The user-font feature allows the cairo user to provide drawings for glyphs in a font. This is most useful in implementing fonts in non-standard formats, like SVG fonts and Flash fonts, but can also be used by games and other application to draw "funky" fonts.
- Since:
- 1.8
-
Constructor Summary
ConstructorDescriptionUserFontFace
(MemorySegment address) Constructor used internally to instantiate a java UserFontFace object for a nativecairo_font_face
instance -
Method Summary
Modifier and TypeMethodDescriptionstatic UserFontFace
create()
Creates a new user font-face.Gets the scaled-font initialization function of a user-font.Gets the color glyph rendering function of a user-font.Gets the glyph rendering function of a user-font.Gets the text-to-glyphs conversion function of a user-font.Gets the unicode-to-glyph conversion function of a user-font.void
setInitFunc
(UserScaledFontInitFunc initFunc) Sets the scaled-font initialization function of a user-font.void
setRenderColorGlyphFunc
(UserScaledFontRenderGlyphFunc renderGlyphFunc) Sets the color glyph rendering function of a user-font.void
setRenderGlyphFunc
(UserScaledFontRenderGlyphFunc renderGlyphFunc) Sets the glyph rendering function of a user-font.void
setTextToGlyphsFunc
(UserScaledFontTextToGlyphsFunc textToGlyphsFunc) Sets th text-to-glyphs conversion function of a user-font.void
setUnicodeToGlyphFunc
(UserScaledFontUnicodeToGlyphFunc unicodeToGlyphFunc) Sets the unicode-to-glyph conversion function of a user-font.Methods inherited from class org.freedesktop.cairo.FontFace
destroy, getFontType, getType, getUserData, setUserData, status
-
Constructor Details
-
UserFontFace
Constructor used internally to instantiate a java UserFontFace object for a nativecairo_font_face
instance- Parameters:
address
- the memory address of the nativecairo_font_face
instance
-
-
Method Details
-
create
Creates a new user font-face.Use the setter functions to associate callbacks with the returned user font. The only mandatory callback is render_glyph.
After the font-face is created, the user can attach arbitrary data (the actual font data) to it using
FontFace.setUserData(org.freedesktop.cairo.UserDataKey, java.lang.foreign.MemorySegment)
and access it from the user-font callbacks by usingScaledFont.getFontFace()
followed byFontFace.getUserData(org.freedesktop.cairo.UserDataKey)
.- Returns:
- a newly created UserFontFace
- Since:
- 1.8
-
setInitFunc
Sets the scaled-font initialization function of a user-font. SeeUserScaledFontInitFunc
for details of how the callback works.The font-face should not be immutable or an
IllegalStateException
will be thrown. A user font-face is immutable as soon as a scaled-font is created from it.- Parameters:
initFunc
- The init callback, ornull
- Throws:
IllegalStateException
- Since:
- 1.8
-
getInitFunc
Gets the scaled-font initialization function of a user-font.- Returns:
- The init callback of this font-face or
null
if none set or an error has occurred. - Since:
- 1.8
-
setRenderGlyphFunc
public void setRenderGlyphFunc(UserScaledFontRenderGlyphFunc renderGlyphFunc) throws IllegalStateException Sets the glyph rendering function of a user-font. SeeUserScaledFontRenderGlyphFunc
for details of how the callback works.The font-face should not be immutable or an
IllegalStateException
will be thrown. A user font-face is immutable as soon as a scaled-font is created from it.The render_glyph callback is the only mandatory callback of a user-font. At least one of
setRenderColorGlyphFunc(org.freedesktop.cairo.UserScaledFontRenderGlyphFunc)
orsetRenderGlyphFunc
must be called to set a render callback. If both callbacks are set, the color glyph render callback is invoked first. If the color glyph render callback throwsUnsupportedOperationException
, the non-color version of the callback is invoked.If the callback is
null
and a glyph is tried to be rendered using this font-face, anIllegalStateException
will be thrown.- Parameters:
renderGlyphFunc
- The render_glyph callback, ornull
- Throws:
IllegalStateException
- when the font-face is immutable, or the callback is null and a glyph is tried to be rendered using this font-face- Since:
- 1.8
-
getRenderGlyphFunc
Gets the glyph rendering function of a user-font.- Returns:
- The render_glyph callback of this font-face or
null
if none set or an error has occurred. - Since:
- 1.8
-
setRenderColorGlyphFunc
public void setRenderColorGlyphFunc(UserScaledFontRenderGlyphFunc renderGlyphFunc) throws IllegalStateException Sets the color glyph rendering function of a user-font. SeeUserScaledFontRenderGlyphFunc
for details of how the callback works.The font-face should not be immutable or an
IllegalStateException
will be thrown. A user font-face is immutable as soon as a scaled-font is created from it.The render_glyph callback is the only mandatory callback of a user-font. At least one of
setRenderColorGlyphFunc
orsetRenderGlyphFunc(org.freedesktop.cairo.UserScaledFontRenderGlyphFunc)
must be called to set a render callback. If both callbacks are set, the color glyph render callback is invoked first. If the color glyph render callback throwsUnsupportedOperationException
, the non-color version of the callback is invoked.If the callback is
null
and a glyph is tried to be rendered using this font-face, anIllegalStateException
will be thrown.- Parameters:
renderGlyphFunc
- The render_glyph callback, ornull
- Throws:
IllegalStateException
- when the font-face is immutable, or the callback is null and a glyph is tried to be rendered using this font-face- Since:
- 1.8
-
getRenderColorGlyphFunc
Gets the color glyph rendering function of a user-font.- Returns:
- The render_glyph callback of this font-face or
null
if none set or an error has occurred. - Since:
- 1.8
-
setUnicodeToGlyphFunc
public void setUnicodeToGlyphFunc(UserScaledFontUnicodeToGlyphFunc unicodeToGlyphFunc) throws IllegalStateException Sets the unicode-to-glyph conversion function of a user-font. SeeUserScaledFontUnicodeToGlyphFunc
for details of how the callback works.The font-face should not be immutable or an
IllegalStateException
will be thrown. A user font-face is immutable as soon as a scaled-font is created from it.- Parameters:
unicodeToGlyphFunc
- The unicode_to_glyph callback, ornull
- Throws:
IllegalStateException
- when the font-face is immutable- Since:
- 1.8
-
getUnicodeToGlyphFunc
Gets the unicode-to-glyph conversion function of a user-font.- Returns:
- The unicode_to_glyph callback of this font-face or
null
if none set or an error occurred. - Since:
- 1.8
-
setTextToGlyphsFunc
public void setTextToGlyphsFunc(UserScaledFontTextToGlyphsFunc textToGlyphsFunc) throws IllegalStateException Sets th text-to-glyphs conversion function of a user-font. See cairo_user_scaled_font_text_to_glyphs_func_t for details of how the callback works.The font-face should not be immutable or an
IllegalStateException
will be thrown. A user font-face is immutable as soon as a scaled-font is created from it.- Parameters:
textToGlyphsFunc
- The text_to_glyphs callback, ornull
- Throws:
IllegalStateException
- when the font-face is immutable- Since:
- 1.8
-
getTextToGlyphsFunc
Gets the text-to-glyphs conversion function of a user-font.- Returns:
- The text_to_glyphs callback of this font-face or
null
if none set or an error occurred. - Since:
- 1.8
-