For text, I use the BookmarkTextAttribute to show a double underline in green. However, If I just bookmark an image (linked), or an image is part of the bookmarked text, it does not show this double underline under the image (as expected I guess). Can you think of anything I can do to indicate that an image is bookmarked other than showing the bookmark indicator in the gutter? Maybe even an overly that is only visible in the editor but not in print preview or the PDF?
Bookmark attribute for images?
-
-
- Offizieller Beitrag
You can use the OnTextObjectPaint event to paint the image and apply attributes you need to show.
-
Works perfectly, thanks! I still have to add some code to optionally paint the link overlay, but this is what I did in case it helps anyone:
Code
Alles anzeigenprocedure TfrmMain.WPRichText1TextObjectPaint(Sender: TObject; pobj: TWPTextObj; toCanvas: TCanvas; XRes, YRes, X, Y, W, H, BASE: Integer; PageRef: TWPVirtPage; Modes: TWPTextObjectPaintModes; const CanvasExtraAttr: TWPPaintExtraParams; var ContinueMode: TWPTextObjectPaintResult); procedure PaintLink(pMult: Integer = 1); var vRect: TRect; begin vRect := Rect(X, Y, X + (imgLinked.Picture.Width * pMult), Y + (imgLinked.Picture.Height * pMult)); // Want an opaque background (linked image specified happens to be a transparent png file) toCanvas.Brush.Color := clMoneyGreen; toCanvas.FillRect(vRect); toCanvas.StretchDraw(vRect, imgLinked.Picture.Graphic); end; begin if Assigned(pobj) and Assigned(pobj.ObjRef) and pobj.IsImage then begin pobj.ObjRef.Paint(toCanvas, Rect(X, Y, X + W, Y + H), pobj, []); PaintLink(3); // Since we had to paint the image ourselves, do not have WPTools paint contents, selection or frame ContinueMode := ContinueMode - [wpObjPaintContents, wpobjPaintSelection, wpObjPaintFrame]; end; end;
-
For completeness, I now paint the "link" image only if the image is within bookmarked text. Code follows:
Code
Alles anzeigenprocedure TfrmMain.WPRichText1TextObjectPaint(Sender: TObject; pobj: TWPTextObj; toCanvas: TCanvas; XRes, YRes, X, Y, W, H, BASE: Integer; PageRef: TWPVirtPage; Modes: TWPTextObjectPaintModes; const CanvasExtraAttr: TWPPaintExtraParams; var ContinueMode: TWPTextObjectPaintResult); procedure PaintLink(pMult: Integer = 1); var vRect: TRect; begin vRect := Rect(X, Y, X + (imgLinked.Picture.Width * pMult), Y + (imgLinked.Picture.Height * pMult)); // Want an opaque background (linked image specified happens to be a transparent png file) toCanvas.Brush.Color := clMoneyGreen; toCanvas.FillRect(vRect); toCanvas.StretchDraw(vRect, imgLinked.Picture.Graphic); end; begin if Assigned(pobj) and Assigned(pobj.ObjRef) and pobj.IsImage and (WPRichText1.CodeInsideOf(pObj.ParentPar, pobj.ParentPosInPar, wpobjBookmark) <> nil) then begin pobj.ObjRef.Paint(toCanvas, Rect(X, Y, X + W, Y + H), pobj, []); PaintLink(2); // Since we had to paint the image ourselves, do not have WPTools paint contents or frame ContinueMode := ContinueMode - [wpObjPaintContents, wpObjPaintFrame]; end; end;