Page 1 of 1

[Example] Does document contain an image

Posted: Wed Oct 07, 2015 12:08 pm
by Sergey Tkachenko
The function HasImage (below) returns True if the given TRichView has an image.
It checks:
- document's background bitmap
- images
- images from image lists
- list markers displaying images
- table background images
- table cells background images
Images are checked in the main document, table cells, notes.

Code: Select all

function RVDataHasImage(RVData: TCustomRVData): Boolean;
var
  i,r,c: Integer;
  ListNo, LevelNo, StartFrom: Integer;
  UseStartFrom: Boolean;
  Table: TRVTableItemInfo;
  ListLevels: TRVListLevelCollection;
begin
  Result := True;
  for i := 0 to RVData.ItemCount-1 do
    case RVData.GetItemStyle(i) of
      rvsPicture, rvsHotPicture, rvsBullet, rvsHotspot:
        exit;
      rvsListMarker:
        begin
          RVData.GetListMarkerInfo(i, ListNo, LevelNo, StartFrom, UseStartFrom);
          if (ListNo<0) then
            continue;
          ListLevels := RVData.GetRVStyle.ListStyles[ListNo].Levels;
          if LevelNo>=ListLevels.Count then
            LevelNo := ListLevels.Count-1;
          if (LevelNo<0) then
            continue;
          if ListLevels[LevelNo].ListType in [rvlstPicture, rvlstImageList, rvlstImageListCounter] then
            exit;
        end;
      rvsTable:
        begin
          Table := TRVTableItemInfo(RVData.GetItem(i));
          if (Table.BackgroundStyle<>rvbsColor) and (Table.BackgroundImage<>nil) then
            exit;
          for r := 0 to Table.RowCount - 1 do
            for c := 0 to Table.ColCount - 1 do
              if Table.Cells[r,c]<>nil then
              begin
                if (Table.Cells[r,c].BackgroundStyle<>rvbsColor) and
                  (Table.Cells[r,c].BackgroundImage<>nil) then
                  exit;
                if RVDataHasImage(Table.Cells[r,c].GetRVData) then
                  exit;
              end;
        end;
      rvsFootnote, rvsEndnote, rvsSidenote, rvsTextBox:
        if RVDataHasImage(TCustomRVNoteItemInfo(RVData.GetItem(i)).Document) then
          exit;
  end;
  Result := False;
end;

function HasImage(rv: TCustomRichView): Boolean;
begin
  Result := ((rv.BackgroundStyle<>bsNoBitmap) and not rv.BackgroundBitmap.Empty) or
    RVDataHasImage(rv.RVData);
end;

Re: [Example] Does a document contain an image

Posted: Thu Jul 26, 2018 7:43 pm
by Sergey Tkachenko