[Example] Does a document contain an image

Demos, code samples. Only questions related to the existing topics are allowed here.
Post Reply
Sergey Tkachenko
Site Admin
Posts: 13149
Joined: Sat Aug 27, 2005 10:28 am
Contact:

[Example] Does a document contain an image

Post by Sergey Tkachenko » Wed Oct 07, 2015 12:08 pm

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;

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest