Haru Free PDF Library
Font processing

Functions

HPDF_Font HPDF_GetFont (HPDF_Doc pdf, const char *font_name, const char *encoding_name)
 Get requested font object handle. More...
 
const char * HPDF_LoadType1FontFromFile (HPDF_Doc pdf, const char *afm_filename, const char *data_filename)
 Load Type1 font from external file and register it in the document object. More...
 
const char * HPDF_LoadTTFontFromFile (HPDF_Doc pdf, const char *filename, HPDF_BOOL embedding)
 Load TrueType font from external .ttf file and register it in the document object. More...
 
const char * HPDF_LoadTTFontFromFile2 (HPDF_Doc pdf, const char *filename, HPDF_UINT index, HPDF_BOOL embedding)
 Load TrueType font from TrueType collection file *.ttc and register it in the document object. More...
 
HPDF_STATUS HPDF_UseJPFonts (HPDF_Doc pdf)
 Enable Japanese fonts. Application can use following Japanese fonts after HPDF_UseJPFonts() call: More...
 
HPDF_STATUS HPDF_UseKRFonts (HPDF_Doc pdf)
 Enable Korean fonts. Application can use following Korean fonts after HPDF_UseKRFonts() call: More...
 
HPDF_STATUS HPDF_UseCNSFonts (HPDF_Doc pdf)
 Enable simplified Chinese fonts. Application can use following simplified Chinese fonts after HPDF_UseCNSFonts() call: More...
 
HPDF_STATUS HPDF_UseCNTFonts (HPDF_Doc pdf)
 Enable traditional Chinese fonts. Application can use following traditional Chinese fonts after HPDF_UseCNTFonts() call: More...
 
const char * HPDF_Font_GetFontName (HPDF_Font font)
 Get name of the font. More...
 
const char * HPDF_Font_GetEncodingName (HPDF_Font font)
 Get encoding name of the font. More...
 
HPDF_INT HPDF_Font_GetUnicodeWidth (HPDF_Font font, HPDF_UNICODE code)
 Get width of a Unicode character in a specific font. More...
 
HPDF_Box HPDF_Font_GetBBox (HPDF_Font font)
 Get bounding box of the font. More...
 
HPDF_INT HPDF_Font_GetAscent (HPDF_Font font)
 Get vertical ascent of the font. More...
 
HPDF_INT HPDF_Font_GetDescent (HPDF_Font font)
 Get vertical descent of the font. More...
 
HPDF_UINT HPDF_Font_GetXHeight (HPDF_Font font)
 Get the distance from the baseline and the mean line of lowercase letters in a font. More...
 
HPDF_UINT HPDF_Font_GetCapHeight (HPDF_Font font)
 Get the distance from the baseline and the mean line of uppercase letters in a font. More...
 
HPDF_TextWidth HPDF_Font_TextWidth (HPDF_Font font, const HPDF_BYTE *text, HPDF_UINT len)
 Get total width of the text, number of characters, and number of words. More...
 
HPDF_UINT HPDF_Font_MeasureText (HPDF_Font font, const HPDF_BYTE *text, HPDF_UINT len, HPDF_REAL width, HPDF_REAL font_size, HPDF_REAL char_space, HPDF_REAL word_space, HPDF_BOOL wordwrap, HPDF_REAL *real_width)
 Calculate byte length which can be included within the specified width. More...
 

Detailed Description

Routines for font loading and measuring

Function Documentation

◆ HPDF_Font_GetAscent()

HPDF_INT HPDF_Font_GetAscent ( HPDF_Font  font)

Get vertical ascent of the font.

Parameters
fontFont object handle.
Returns
Font vertical ascent on success, otherwise returns 0.

◆ HPDF_Font_GetBBox()

HPDF_Box HPDF_Font_GetBBox ( HPDF_Font  font)

Get bounding box of the font.

Parameters
fontFont object handle.
Returns
HPDF_Box structure specifying font bounding box, otherwise returns HPDF_Box{0, 0, 0, 0}.

◆ HPDF_Font_GetCapHeight()

HPDF_UINT HPDF_Font_GetCapHeight ( HPDF_Font  font)

Get the distance from the baseline and the mean line of uppercase letters in a font.

Parameters
fontFont object handle.
Returns
Font cap height value on success, otherwise returns 0.

◆ HPDF_Font_GetDescent()

HPDF_INT HPDF_Font_GetDescent ( HPDF_Font  font)

Get vertical descent of the font.

Parameters
fontFont object handle.
Returns
Font vertical descent on success, otherwise returns 0.

◆ HPDF_Font_GetEncodingName()

const char* HPDF_Font_GetEncodingName ( HPDF_Font  font)

Get encoding name of the font.

Parameters
fontFont object handle.
Returns
Font encoding name on success, otherwise returns NULL
Examples
ttfont_demo_jp.c.

◆ HPDF_Font_GetFontName()

const char* HPDF_Font_GetFontName ( HPDF_Font  font)

Get name of the font.

Parameters
fontFont object handle.
Returns
Font name on success, otherwise returns NULL
Examples
jpfont_demo.c.

◆ HPDF_Font_GetUnicodeWidth()

HPDF_INT HPDF_Font_GetUnicodeWidth ( HPDF_Font  font,
HPDF_UNICODE  code 
)

Get width of a Unicode character in a specific font.

Actual character width on the page can be calculated as follows:

HPDF_INT char_width = HPDF_Font_GetUnicodeWidth (font, UNICODE);
float actual_width = char_width * FONT_SIZE / 1000;
HPDF_INT HPDF_Font_GetUnicodeWidth(HPDF_Font font, HPDF_UNICODE code)
Get width of a Unicode character in a specific font.
signed int HPDF_INT
Definition: hpdf_types.h:44
Parameters
fontFont object handle.
codeUnicode character
Todo:
Clarify what is FONT_SIZE
Returns
Character width on success, otherwise returns 0

◆ HPDF_Font_GetXHeight()

HPDF_UINT HPDF_Font_GetXHeight ( HPDF_Font  font)

Get the distance from the baseline and the mean line of lowercase letters in a font.

Parameters
fontFont object handle.
Returns
Font x-height value on success, otherwise returns 0.

◆ HPDF_Font_MeasureText()

HPDF_UINT HPDF_Font_MeasureText ( HPDF_Font  font,
const HPDF_BYTE text,
HPDF_UINT  len,
HPDF_REAL  width,
HPDF_REAL  font_size,
HPDF_REAL  char_space,
HPDF_REAL  word_space,
HPDF_BOOL  wordwrap,
HPDF_REAL real_width 
)

Calculate byte length which can be included within the specified width.

Parameters
fontFont object handle.
textText to get width
lenLength of the text.
widthWidth of the area to put text.
font_sizeThe size of the font.
char_spaceThe character spacing value.
word_spaceThe word spacing value.
wordwrapWord wrap flag. When there are three words of "ABCDE", "FGH", and "IJKL", and the substring until "J" can be included within the width, if word_wrap parameter is HPDF_FALSE it returns 12, and if word_wrap parameter is HPDF_TRUE, it returns 10 (the end of the previous word).
real_widthIf this parameter is not NULL, the real widths of the text is set. An application can set it to NULL, if it is unnecessary.
Returns
Byte length which can be included within the specified width in current font size, character spacing and word spacing. Otherwise it returns 0 and calls error handler.
Todo:
Check if function return byte length or character lenght, it differs in multiple cases.
Todo:
len is byte length or character length?

◆ HPDF_Font_TextWidth()

HPDF_TextWidth HPDF_Font_TextWidth ( HPDF_Font  font,
const HPDF_BYTE text,
HPDF_UINT  len 
)

Get total width of the text, number of characters, and number of words.

Parameters
fontFont object handle.
textThe text to get width.
len- The byte length of the text.
Returns
HPDF_TextWidth struct with calculation results, otherwise, returns HPDF_TextWidth{0, 0, 0, 0}.
Todo:

What is the meaning of fourth param?

Byte length or character length?

◆ HPDF_GetFont()

HPDF_Font HPDF_GetFont ( HPDF_Doc  pdf,
const char *  font_name,
const char *  encoding_name 
)

◆ HPDF_LoadTTFontFromFile()

const char* HPDF_LoadTTFontFromFile ( HPDF_Doc  pdf,
const char *  filename,
HPDF_BOOL  embedding 
)

Load TrueType font from external .ttf file and register it in the document object.

Parameters
pdfDocument object handle.
filenamePath of TrueType font file (.ttf)
embeddingIf this parameter is set to HPDF_TRUE, the glyph data of the font is included to PDF file, otherwise only the matrix data is included to PDF file.
Returns
Name of the font on success, otherwise, it returns NULL and calls error handler.
Error codes
See also
Fonts
Examples
ttfont_demo.c, ttfont_demo_jp.c, and utf8.c.

◆ HPDF_LoadTTFontFromFile2()

const char* HPDF_LoadTTFontFromFile2 ( HPDF_Doc  pdf,
const char *  filename,
HPDF_UINT  index,
HPDF_BOOL  embedding 
)

Load TrueType font from TrueType collection file *.ttc and register it in the document object.

Parameters
pdfDocument object handle.
filenamePath of TrueType font file (.ttc)
indexIndex of font in collection to be loaded.
embeddingIf this parameter is set to HPDF_TRUE, the glyph data of the font is included to PDF file, otherwise only the matrix data is included to PDF file.
Returns
Name of the font on success, otherwise, it returns NULL and calls error handler.
Error codes
See also
Fonts, Encodings
Examples
chfont_demo.c, and ttfont_demo_jp.c.

◆ HPDF_LoadType1FontFromFile()

const char* HPDF_LoadType1FontFromFile ( HPDF_Doc  pdf,
const char *  afm_filename,
const char *  data_filename 
)

Load Type1 font from external file and register it in the document object.

Parameters
pdfDocument object handle.
afm_filenamePath of AFM file
data_filenamePath of PFA/PFB file. If NULL, glyph data of font file is not embedded into the PDF file
Returns
Name of the font on success, otherwise, it returns NULL and calls error handler.
Error codes
See also
Fonts
Examples
encoding_list.c.

◆ HPDF_UseCNSFonts()

HPDF_STATUS HPDF_UseCNSFonts ( HPDF_Doc  pdf)

Enable simplified Chinese fonts. Application can use following simplified Chinese fonts after HPDF_UseCNSFonts() call:

Font name
SimSun
SimSun,Bold
SimSun,Italic
SimSun,BoldItalic
SimHei
SimHei,Bold
SimHei,Italic
SimHei,BoldItalic
Parameters
pdfDocument object handle.
Returns
HPDF_OK on success, otherwise returns error code and calls error handler.
Error codes
Examples
character_map.c.

◆ HPDF_UseCNTFonts()

HPDF_STATUS HPDF_UseCNTFonts ( HPDF_Doc  pdf)

Enable traditional Chinese fonts. Application can use following traditional Chinese fonts after HPDF_UseCNTFonts() call:

Font name
MingLiU
MingLiU,Bold
MingLiU,Italic
MingLiU,BoldItalic
Parameters
pdfDocument object handle.
Returns
HPDF_OK on success, otherwise returns error code and calls error handler.
Error codes
Examples
character_map.c.

◆ HPDF_UseJPFonts()

HPDF_STATUS HPDF_UseJPFonts ( HPDF_Doc  pdf)

Enable Japanese fonts. Application can use following Japanese fonts after HPDF_UseJPFonts() call:

Font name
MS-Mincyo
MS-Mincyo,Bold
MS-Mincyo,Italic
MS-Mincyo,BoldItalic
MS-Gothic
MS-Gothic,Bold
MS-Gothic,Italic
MS-Gothic,BoldItalic
MS-PMincyo
MS-PMincyo,Bold
MS-PMincyo,Italic
MS-PMincyo,BoldItalic
MS-PGothic
MS-PGothic,Bold
MS-PGothic,Italic
MS-PGothic,BoldItalic
Parameters
pdfDocument object handle.
Returns
HPDF_OK on success, otherwise returns error code and calls error handler.
Error codes
Examples
character_map.c, and jpfont_demo.c.

◆ HPDF_UseKRFonts()

HPDF_STATUS HPDF_UseKRFonts ( HPDF_Doc  pdf)

Enable Korean fonts. Application can use following Korean fonts after HPDF_UseKRFonts() call:

Font name
DotumChe
DotumChe,Bold
DotumChe,Italic
DotumChe,BoldItalic
Dotum
Dotum,Bold
Dotum,Italic
Dotum,BoldItalic
BatangChe
BatangChe,Bold
BatangChe,Italic
BatangChe,BoldItalic
Batang
Batang,Bold
Batang,Italic
Batang,BoldItalic
Parameters
pdfDocument object handle.
Returns
HPDF_OK on success, otherwise returns error code and calls error handler.
Error codes
Examples
character_map.c.