Hyper Text Rendering (hApi + HTextRendering)
- Plain Text (Windows API)
- Hyper Text Rendering (HTextRendering)
- Web Content Types
- HTML ↔ Hyper Text Conversion
HTextDimensions
Measures text dimensions with current canvas font settings.Function HTextDimensions(CONST Canvas: TCanvas; CONST Text: String; Inc_Pixel: Boolean = True): TSize;
Parameters
- Canvas: TCanvas; measurement canvas.
- Text: String; text to measure.
- Inc_Pixel: Boolean; adds extra pixel when True.
Return Value
Returns calculated text size, with one pixel added to both dimensions whenInc_Pixel is True.HDrawText
Draws text with WindowsDrawTextW, combining the supplied flags with DT_NOPREFIX.Procedure HDrawText(CONST Canvas: TCanvas; CONST Text: String; Rect: TRect; CONST Flags: Cardinal);
Parameters
- Canvas: TCanvas; drawing surface.
- Text: String; text to render.
- Rect: TRect; draw rectangle.
- Flags: Cardinal; draw flags (DT_*).
HDrawText_SL
Draws a single line of text. Alignment codes are 0 = left/top, 1 = center, and 2 = right/bottom.Procedure HDrawText_SL(CONST Canvas: TCanvas; CONST Text: String; Rect: TRect; CONST Halign, Valign: Byte);
Parameters
- Canvas: TCanvas; drawing surface.
- Text: String; text to render.
- Rect: TRect; draw rectangle.
- Halign: Byte; horizontal alignment.
- Valign: Byte; vertical alignment.
HSmart_DrawText
Draws Hyper Text (Hapi-tagged text) on a canvas with horizontal and vertical alignment control.Returns the size of the rendered text area.
This API is a direct bridge to
Render_Text_On_Canvas
in the engine with identical parameters.Function HSmart_DrawText(CONST Canvas: TCanvas; CONST Text: String; CONST Rect: TRect; CONST HAlign, VAlign: Byte): TSize;
Parameters
- Canvas: TCanvas; the canvas on which to draw text.
- Text: String; Hyper Text / tagged text to render.
- Rect: TRect; bounding rectangle for rendering.
- HAlign: Byte; horizontal alignment code.
- VAlign: Byte; vertical alignment code.
Return Value
Returns the size occupied by the rendered text.HSmart_Text_Dimensions
Measures Hyper Text (Hapi-tagged text) dimensions using a fixed width constraint.Function HSmart_Text_Dimensions(CONST Canvas: TCanvas; CONST Text: String; CONST FixedWidth: Integer): TSize;
Parameters
- Canvas: TCanvas; the canvas used for measuring text.
- Text: String; Hyper Text / tagged text content to measure.
- FixedWidth: Integer; width used for line wrapping.
Return Value
Returns the measured width and height, each increased by one pixel.Convert_Html_Body_To_Hapi_Tagged_Text
Converts HTML body text into Hapi tagged text format.Function Convert_Html_Body_To_Hapi_Tagged_Text(Html: String): String;
Parameters
- Html: String; source HTML content.
Return Value
Returns converted Hapi-tagged text.Convert_Hapi_Tagged_Text_To_Html
Converts Hapi tagged text back into HTML markup.Function Convert_Hapi_Tagged_Text_To_Html(Text: String): String;
Parameters
- Text: String; Hapi tagged source text.
Return Value
Returns generated HTML text.Convert_Chars_From_Unicode_To_Html
Replaces selected characters with HTML entities and can turn carriage returns into<br> tags.Function Convert_Chars_From_Unicode_To_Html(Original_Unicode16: String; Convert_CR_To_BR: Boolean = True): String;
Parameters
- Original_Unicode16: String; source Unicode text.
- Convert_CR_To_BR: Boolean; converts CR/LF to <br> when True.
Return Value
Returns transformed text. This function does not escape&, <, or >; do not use it alone to make untrusted text safe for HTML.Does_Html_Need_To_Be_RtL
Checks whether more than one character is Hebrew or Arabic and those characters make up over 40% of the input.Function Does_Html_Need_To_Be_RtL(Text: String): Boolean;
Parameters
- Text: String; text to analyze.
Return Value
Returns True for RTL-oriented text.Returns False otherwise.
Web Content Types
Get_Web_Content_Type
Maps a lowercase file extension (without its dot) to an HTTP content type.Function Get_Web_Content_Type(FileExt: String; Return_As_Http_Parameter: Boolean): String;
The current implementation ignores Return_As_Http_Parameter and returns
application/octet-stream for an unknown extension.Example
Get_Web_Content_Type('PNG', False) // returns 'image/png'
Get_File_Ext_By_Web_Content_Type
Maps a known HTTP content type to a file extension without its dot.Function Get_File_Ext_By_Web_Content_Type(_Content_Type: String): String;
Unknown content types return file. For example, image/jpeg returns jpg.