<< Click to display table of contents >> TRVGraphicHandler |
This class provides an abstraction layer for managing graphic in TRichView components. It is designed to make TRichView components independent of specific graphic classes.
Unit [VCL/FMX]: RVGrHandler / fmxRVGrHandler
Syntax
TRVGraphicHandler = class;
(introduced in version 15)
A single variable of this class is created: RVGraphicHandler. You can call methods of the object returned in this variable.
Additionally, you can create a class inherited from TRVGraphicHandler and assign it to this variable (however, this possibility is not discussed in this help file).
A complete description of all methods of this class is beyond the scope of this help file.
The following methods are useful:
procedure SetDefaultGraphicClass(GraphicType: TRVGraphicType;
GraphicClass: TRVGraphicClass);
procedure RegisterPngGraphic(GraphicClass: TRVGraphicClass);
procedure RegisterJpegGraphic(GraphicClass: TRVGraphicClass);
procedure RegisterHTMLGraphicFormat(GraphicClass: TRVGraphicClass);
function CreateGraphicByType(GraphicType: TRVGraphicType): TRVGraphic;
function LoadFromFile(const FileName: TRVUnicodeString): TRVGraphic;
function LoadFromStream(Stream: TStream): TRVGraphic;
function GetDataGraphicType(const Buffer; Size: Integer): TRVGraphicType;
// VCL and LCL
function CreateGraphic(GraphicClass: TRVGraphicClass): TRVGraphic;
// FireMonkey
function GetFileDialogFilter: String;
[FireMonkey] Normally, to get a filter string for a file dialog to open image files, developers use TBitmapCodecManager.GetFilterString. However, this filter string does not include non-bitmap formats supported by TRichView (such as SVG supported using Skia4Delphi). So, you can use GetFileDialogFilter method to get a filter string that includes both bitmap and non-bitmap formats.
In VCL and Lazarus, different graphic classes represent images. All of them are inherited from TGraphic.
In FireMonkey, graphic classes are inherited fromTRVGraphicFM (also available as TRVGraphic). There are two classes that can be used:
▪TRVRasterGraphicFM (also available as TRVBitmap): wrapper for FireMonkey TBitmap, supports many raster image formats
▪TRVSvgImageSkiaFM: wrapper for TSkSvgBrush from Skia4Delphi, supports SVG images.
RegisterPngGraphic registers a PNG graphic class for using in TRichView. Call this method one time when the application starts (for example, in the initialization section of the main form's unit). If PNG class is registered, TRichView controls can save and load PNG images in RTF and DocX files. Optionally, bitmaps can be saved as PNG in RTF too, see TCustomRichView.RTFOptions property (rvrtfPNGInsteadOfBitmap).
By default, in Delphi 2009+, TRichView registers a standard TPngImage as PNG graphic format, so, unless you want to use another class for PNG images, this method is necessary only for Delphi 2007 or older. For example, you can use Gustavo Huffenbacher Daud's TPngObject: download file (free PNG graphic class). In Lazarus, TPortableNetworkGraphic is registered automatically.
RegisterJpegGraphic registers a JPEG graphic class for using in TRichView. If this method is not called, TRichView uses TJPEGImage. This class is used when loading Jpeg images embedded in RTF.
There is an universal method allowing to define graphic classes for the specified graphic type: SetDefaultGraphicClass.
By default, the classes are:
▪bitmaps: TBitmap;
▪icons: TIcon;
▪metafiles: TMetafile (for Delphi), undefined for Lazarus;
▪jpeg: TJPEGImage;
▪png: TPngImage (for Delphi 2009+), TPortableNetworkGraphic (for Lazarus), undefined otherwise;
▪gif: TGifImage (for Delphi 2007+, if RVGifAnimate2007 is included in the project; for previous versions of Delphi, if RVGifAnimate is included in the project; undefined otherwise;
▪tiff: TWicImage (for Delphi 2010+, undefined otherwise);
▪anymap: TPortableAnyMapGraphic (for Lazarus), undefined otherwise.
▪svg: TSkSvgGraphic (requires Skia4Delphi); include RVSkia unit in your project.
When saving image to HTML or Markdown, TRichView converts all non-HTML image formats as to Jpegs.
Images of graphic classes registered for the following formats are not converted: rvgtJPEG, rvgtPNG, rvgtGIF, rvgtSVG, rvgtWebP.
RegisterHTMLGraphicFormat allows to define additional HTML graphic formats. Call this method when the application starts (for example, in the initialization section of the main form's unit). Images of these formats are saved in HTML as they are, without conversion to Jpegs. TRichView registers the following classes as HTML graphic formats:
▪standard TPngImage (for Delphi 2009+);
▪standard TGifImage (for Delphi 2007+), if you include RVGifAnimate2007 unit in your project;
▪Anders Melander's TGifImage, if you include RVGifAnimate unit in your project;
▪TJvGifImage from JEDI's JVCL, if you include RVJvGifAnimate unit in your project.
CreateGraphic creates a graphic of this specified class. For Delphi/C++Builder 6 or newer, this method is equivalent to calling GraphicClass.Create. For older version of Delphi, this method contains a workaround for TGraphic bug.
CreateGraphicByType creates a graphic of the specified type, see "Choosing default graphic classes" above.
LoadFromFile creates a graphic object, loads the file FileName in it, and returns this graphic. A TRVGraphic TRichView tries to recognize the proper graphic class by content itself. If failed, it tries to use framework methods to recognize an load an image (in VCL/LCL: by file extension; in FireMonkey: by content). If failed, it returns nil.
LoadFromStream creates a graphic object, loads the stream content in it, and returns this graphic. A graphic format is recognized by content. If this procedure cannot recognize a graphic format, or no graphic class is defined for this graphic type, it returns nil.