# Documentation/API/Font

### From libHaru.org wiki

< Documentation | API

## HPDF_Font_GetFontName()

    const char * HPDF_Font_GetFontName (HPDF_Font font);

Description

HPDF_Font_GetFontName() gets the name of the font.

Parameters

font - The handle of a font object.

Return Value

Returns font name on success. Otherwise, returns NULL.

## HPDF_Font_GetEncodingName()

    const char * HPDF_Font_GetEncodingName (HPDF_Font font);

Description

HPDF_Font_GetEncodingName() gets the encoding name of the font.

Parameters

font - The handle of a font object.

Return Value

Returns font name on success. Otherwise, returns NULL.

## HPDF_Font_GetUnicodeWidth()

    HPDF_INT HPDF_Font_GetUnicodeWidth (HPDF_Font font, HPDF_UNICODE code);

Description

HPDF_Font_GetUnicodeWidth() gets the width of a Unicode character in a specific font. Actual width of the character on the page can be calculated as follows:

    char_width = HPDF_Font_GetUnicodeWidth (font, UNICODE);
    float actual_width = char_width * FONT_SIZE / 1000;

Parameters

font - The handle of an font object.
code - A Unicode character.

Return Value

Returns character width on success. Otherwise, returns NULL.

## HPDF_Font_GetBBox()

    typedef  struct _HPDF_Rect {
        HPDF_REAL  left;
        HPDF_REAL  bottom;
        HPDF_REAL  right;
        HPDF_REAL  top;
    } HPDF_Rect;

    typedef struct _HPDF_Rect HPDF_Box;

    HPDF_Box HPDF_Font_GetBBox (HPDF_Font font);

Description

HPDF_Font_GetBBox() gets the bounding box of the font.

Parameters

font - The handle of a font object.

Return Value

On success, seturns HPDF_Box struct specifying the font bounding box.
Otherwise, returns a HPDF_Box struct of {0, 0, 0, 0}.

## HPDF_Font_GetAscent()

    HPDF_INT HPDF_Font_GetAscent (HPDF_Font font);

Description

HPDF_Font_GetAscent() gets the vertical ascent of the font.

Parameters

font - The handle of a font object.

Return Value

Returns font vertical ascent on success. Otherwise, returns 0.

## HPDF_Font_GetDescent()

    HPDF_INT HPDF_Font_GetDescent (HPDF_Font font);

Description

HPDF_Font_GetDescent() gets the vertical descent of the font.

Parameters

font - The handle of a font object.

Return Value

Returns font vertical descent on success. Otherwise, returns 0.

## HPDF_Font_GetXHeight()

    HPDF_UINT HPDF_Font_GetXHeight (HPDF_Font font);

Description

HPDF_Font_GetXHeight() gets the distance from the baseline of lowercase letters.

Parameters

font - The handle of a font object.

Return Value

Returns font x-height value on success. Otherwise, returns 0.

## HPDF_Font_GetCapHeight()

    HPDF_UINT HPDF_Font_GetCapHeight (HPDF_Font font);

Description

HPDF_Font_GetCapHeight() gets the distance from the baseline of uppercase letters.

Parameters

font - The handle of a font object.

Return Value

Returns font cap height on success. Otherwise, returns 0.

## HPDF_Font_TextWidth()

    typedef struct _HPDF_TextWidth {
        HPDF_UINT numchars;
        HPDF_UINT numwords;
        HPDF_UINT width;
        HPDF_UINT numspace;
    } HPDF_TextWidth;

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

Description

HPDF_Font_TextWidth() gets total width of the text, number of characters, and number of words.

Parameters

font - The handle of a font object.
text - The text to get width.
len - The byte length of the text.

Return Value

On success, returns HPDF_TextWidth struct including calculation result.
Otherwise, returns HPDF_TextWidth struct whose attributes are all 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);

Description

HPDF_Font_MeasureText() calculates the byte length which can be included within the specified width.

Parameters

font - Specify the handle of a font object.
text - The text to use for calculation.
len - The length of the text.
width - The width of the area to put the text.
font_size - The size of the font.
char_space - The character spacing.
word_space - The word spacing.
wordwrap - Suppose there are three words: "ABCDE", "FGH", and "IJKL". Also, suppose the substring until "J" can be included within the width (12 bytes). If word_wrap is HPDF_FALSE the function returns 12. If word_wrap parameter is HPDF_TRUE, it returns 10 (the end of the previous word).

real_width - If not NULL, parameter is set to the real width of the text. If NULL, parameter is ignored.

Return Value

On success, returns byte length which can be included within specified width. Otherwise, returns 0.

Retrieved from "http://daylessday../../../../articles/d/o/c/Documentation_API_Font_dec7.html"

##### Views

- Page
- Discussion
- View source
- History

##### Personal tools

- Log in

##### Search

##### Toolbox

- What links here
- Related changes
- Special pages
- Printable version
- Permanent link