TRVGraphicHandler

Top  Previous  Next

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 RVGrHandler;

Syntax

TRVGraphicHandler = class;

(introduced in version 15)

Using

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).

Methods

A complete description of all methods of this class is beyond the scope of this help file.

The following methods are useful:

type
  TRVGraphicType = // defined in RVFuncs unit
    (rvgtBitmap, rvgtIcon, rvgtMetafile, rvgtJPEG, rvgtPNG, rvgtGIF, rvgtTIFF, rvgtOther);
procedure SetDefaultGraphicClass(GraphicType: TRVGraphicType; GraphicClass: TGraphicClass);
procedure RegisterPngGraphic(GraphicClass: TGraphicClass);
procedure RegisterJpegGraphic(GraphicClass: TGraphicClass);
procedure RegisterHTMLGraphicFormat(GraphicClass: TGraphicClass);
function CreateGraphic(GraphicClass: TGraphicClass): TGraphic;

function CreateGraphicByType(GraphicType: TRVGraphicType): TGraphic;
function LoadFromFile(const FileName: String): TGraphic; 
function LoadFromStream(Stream: TStream): TGraphic;

Choosing default graphic classes

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 and save in 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).

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,

jpeg: TJPEGImage,

png: TPngImage (for Delphi 2009+, 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)

HTML export

RegisterHTMLGraphicFormat allows to define HTML graphic formats. Call this method one time 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. It's not necessary to call it for TJpegImage. These formats must have file extension associated, see TPicture.RegisterFileFormat. 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.

Creating graphics

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 TGraphic class of a created object is determined by the file extension of the file. If the file extension is not recognized, or loading failed, the method 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,

See also

how to use third-party graphic classes in TRichView


TRichView © trichview.com