Documentation
¶
Overview ¶
Go wrapper for FreeType which is a freely available software library to render fonts.
Index ¶
- Constants
- Variables
- func GetError(errno C.FT_Error) error
- type BBox
- type Bitmap
- func (b *Bitmap) AlphaImage() (*image.Alpha, error)
- func (b *Bitmap) Buffer() []byte
- func (b *Bitmap) Done(lib *Library) error
- func (b *Bitmap) GrayImage() (*image.Gray, error)
- func (b *Bitmap) Image() (image.Image, error)
- func (b *Bitmap) NRGBA() (*image.NRGBA, error)
- func (b *Bitmap) NumGrays() int
- func (b *Bitmap) Pitch() int
- func (b *Bitmap) PixelMode() int
- func (b *Bitmap) Rows() int
- func (b *Bitmap) Width() int
- type BitmapSize
- type CharMap
- type Face
- func (f *Face) Ascender() int16
- func (f *Face) AvailableSizes() []BitmapSize
- func (f *Face) BBox() BBox
- func (f *Face) CharMap() CharMap
- func (f *Face) CharMaps() []CharMap
- func (f *Face) Descender() int16
- func (f *Face) Done() error
- func (f *Face) FaceFlags() int64
- func (f *Face) FaceIndex() int64
- func (f *Face) FamilyName() string
- func (f *Face) GetCharIndex(char uint64) uint
- func (f *Face) Glyph() *GlyphSlot
- func (f *Face) Height() int16
- func (f *Face) LoadChar(char uint64, flags int) error
- func (f *Face) LoadGlyph(index uint, flags int) error
- func (f *Face) MaxAdvanceHeight() int16
- func (f *Face) MaxAdvanceWidth() int16
- func (f *Face) NumCharmaps() int
- func (f *Face) NumFaces() int64
- func (f *Face) NumFixedSizes() int
- func (f *Face) SelectCharmap(encoding int) error
- func (f *Face) SetCharSize(charWidth, charHeight int64, horzResolution, vertResolution uint) error
- func (f *Face) SetPixelSizes(width, height uint) error
- func (f *Face) SetTransform(matrix *Matrix, delta *Vector)
- func (f *Face) Size() Size
- func (f *Face) StyleFlags() int64
- func (f *Face) StyleName() string
- func (f *Face) UnderlinePosition() int16
- func (f *Face) UnderlineThickness() int16
- type Glyph
- func (g *Glyph) Advance() *Vector
- func (g *Glyph) Copy() (*Glyph, error)
- func (g *Glyph) Done()
- func (g *Glyph) Format() int
- func (g *Glyph) GetCBox(bboxMode uint) *BBox
- func (g *Glyph) Library() *Library
- func (g *Glyph) ReinterpretAsOutlineGlyph() *OutlineGlyph
- func (g *Glyph) Stroke(stroker *Stroker, destroy bool) error
- func (g *Glyph) StrokeBorder(stroker *Stroker, inside, destroy bool) error
- func (g *Glyph) ToBitmap(renderMode int, origin *Vector, destroy bool) error
- func (g *Glyph) Transform(matrix *Matrix, delta *Vector) error
- type GlyphMetrics
- func (m *GlyphMetrics) Height() int64
- func (m *GlyphMetrics) HoriAdvance() int64
- func (m *GlyphMetrics) HoriBearingX() int64
- func (m *GlyphMetrics) HoriBearingY() int64
- func (m *GlyphMetrics) VertAdvance() int64
- func (m *GlyphMetrics) VertBearingX() int64
- func (m *GlyphMetrics) VertBearingY() int64
- func (m *GlyphMetrics) Width() int64
- type GlyphSlot
- func (g *GlyphSlot) Advance() *Vector
- func (g *GlyphSlot) Bitmap() *Bitmap
- func (g *GlyphSlot) BitmapLeft() int
- func (g *GlyphSlot) BitmapTop() int
- func (g *GlyphSlot) ControlData() []byte
- func (g *GlyphSlot) ControlLen() int
- func (g *GlyphSlot) Face() *Face
- func (g *GlyphSlot) Format() int
- func (g *GlyphSlot) GetGlyph() (*Glyph, error)
- func (g *GlyphSlot) Library() *Library
- func (g *GlyphSlot) LinearHoriAdvance() int64
- func (g *GlyphSlot) LinearVertAdvance() int64
- func (g *GlyphSlot) LsbDelta() int64
- func (g *GlyphSlot) Metrices() *GlyphMetrics
- func (g *GlyphSlot) Next() *GlyphSlot
- func (g *GlyphSlot) NumSubGlyphs() uint
- func (g *GlyphSlot) Outline() *Outline
- func (g *GlyphSlot) Render(mode int) error
- func (g *GlyphSlot) RsbDelta() int64
- type Library
- type Matrix
- type Outline
- type OutlineGlyph
- type RasterParams
- func (params *RasterParams) ClipBox() *BBox
- func (params *RasterParams) Flags() int
- func (params *RasterParams) GraySpans() SpanFunc
- func (params *RasterParams) SetClipBox(bbox *BBox)
- func (params *RasterParams) SetFlags(flags int)
- func (params *RasterParams) SetGraySpans(f SpanFunc)
- func (params *RasterParams) SetSource(source *interface{})
- func (params *RasterParams) SetTarget(target *Bitmap)
- func (params *RasterParams) Source() unsafe.Pointer
- func (params *RasterParams) Target() *Bitmap
- type Size
- type SizeMetrics
- func (size *SizeMetrics) Ascender() int64
- func (size *SizeMetrics) Descender() int64
- func (size *SizeMetrics) Height() int64
- func (size *SizeMetrics) MaxAdvance() int64
- func (size *SizeMetrics) XPpem() int64
- func (size *SizeMetrics) XScale() int64
- func (size *SizeMetrics) YPpem() int64
- func (size *SizeMetrics) YScale() int64
- type Span
- type SpanFunc
- type Stroker
- func (s *Stroker) BeginSubPath(to Vector, open bool) error
- func (s *Stroker) ConicTo(control, to *Vector) error
- func (s *Stroker) CubicTo(control1, control2, to *Vector) error
- func (s *Stroker) Done()
- func (s *Stroker) EndSubPath() error
- func (s *Stroker) Export(outline *Outline)
- func (s *Stroker) ExportBorder(border int, outline *Outline)
- func (s *Stroker) GetBorderCounts(border int) (uint, uint, error)
- func (s *Stroker) GetCounts() (uint, uint, error)
- func (s *Stroker) LineTo(to *Vector) error
- func (s *Stroker) ParseOutline(outline *Outline, opened bool) error
- func (s *Stroker) Rewind()
- func (s *Stroker) Set(radius int64, lineCap, lineJoin int, miterLimit int64)
- type Vector
Constants ¶
const ( EncodingNone int = C.FT_ENCODING_NONE EncodingMSSymbol int = C.FT_ENCODING_MS_SYMBOL EncodingUnicode int = C.FT_ENCODING_UNICODE EncodingSjis int = C.FT_ENCODING_SJIS EncodingGb2312 int = C.FT_ENCODING_GB2312 EncodingBig5 int = C.FT_ENCODING_BIG5 EncodingWansung int = C.FT_ENCODING_WANSUNG EncodingJohab int = C.FT_ENCODING_JOHAB /* for backwards compatibility */ EncodingMSSjis = EncodingSjis EncodingMSGb2312 = EncodingGb2312 EncodingMSBig5 = EncodingBig5 EncodingMSWansung = EncodingWansung EncodingMSJohab = EncodingJohab EncodingAdobeStandard int = C.FT_ENCODING_ADOBE_STANDARD EncodingAdobeExpert int = C.FT_ENCODING_ADOBE_EXPERT EncodingAdobeCustom int = C.FT_ENCODING_ADOBE_CUSTOM EncodingAdobeLatin1 int = C.FT_ENCODING_ADOBE_LATIN_1 EncodingOldLatin2 int = C.FT_ENCODING_OLD_LATIN_2 EncodingAppleRoman int = C.FT_ENCODING_APPLE_ROMAN )
const ( GlyphBBoxUnscaled int = C.FT_GLYPH_BBOX_UNSCALED GlyphBBoxSubpixels int = C.FT_GLYPH_BBOX_SUBPIXELS GlyphBBoxGridfit int = C.FT_GLYPH_BBOX_GRIDFIT GlyphBBoxTruncate int = C.FT_GLYPH_BBOX_TRUNCATE GlyphBBoxPixels int = C.FT_GLYPH_BBOX_PIXELS )
const ( GlyphFormatNone int = C.FT_GLYPH_FORMAT_NONE GlyphFormatComposite int = C.FT_GLYPH_FORMAT_COMPOSITE GlyphFormatOutline int = C.FT_GLYPH_FORMAT_OUTLINE GlyphFormatPlotter int = C.FT_GLYPH_FORMAT_PLOTTER )
const ( LoadDefault int = C.FT_LOAD_DEFAULT LoadNoScale int = C.FT_LOAD_NO_SCALE LoadNoHinting int = C.FT_LOAD_NO_HINTING LoadRender int = C.FT_LOAD_RENDER LoadNoBitmap int = C.FT_LOAD_NO_BITMAP LoadVerticalLayout int = C.FT_LOAD_VERTICAL_LAYOUT LoadForceAutohint int = C.FT_LOAD_FORCE_AUTOHINT LoadCropBitmap int = C.FT_LOAD_CROP_BITMAP LoadPedantic int = C.FT_LOAD_PEDANTIC LoadIgnoreGlobalAdvanceWidth int = C.FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH LoadNoRecurse int = C.FT_LOAD_NO_RECURSE LoadIgnoreTransform int = C.FT_LOAD_IGNORE_TRANSFORM LoadMonochrome int = C.FT_LOAD_MONOCHROME LoadLinearDesign int = C.FT_LOAD_LINEAR_DESIGN LoadNoAutohint int = C.FT_LOAD_NO_AUTOHINT LoadColor int = C.FT_LOAD_COLOR )
const ( PixelModeNone int = C.FT_PIXEL_MODE_NONE PixelModeMono int = C.FT_PIXEL_MODE_MONO PixelModeGray int = C.FT_PIXEL_MODE_GRAY PixelModeGray2 int = C.FT_PIXEL_MODE_GRAY2 PixelModeGray4 int = C.FT_PIXEL_MODE_GRAY4 PixelModeLCD int = C.FT_PIXEL_MODE_LCD PixelModeLCDV int = C.FT_PIXEL_MODE_LCD_V PixelModeBGRA int = C.FT_PIXEL_MODE_BGRA PixelModeMax int = C.FT_PIXEL_MODE_MAX )
const ( RasterFlagDefault int = C.FT_RASTER_FLAG_DEFAULT RasterFlagAA int = C.FT_RASTER_FLAG_AA RasterFlagDirect int = C.FT_RASTER_FLAG_DIRECT RasterFlagClip int = C.FT_RASTER_FLAG_CLIP )
const ( RenderModeNormal int = C.FT_RENDER_MODE_NORMAL RenderModeLight int = C.FT_RENDER_MODE_LIGHT RenderModeMono int = C.FT_RENDER_MODE_MONO RenderModeLCD int = C.FT_RENDER_MODE_LCD RenderModeLCDV int = C.FT_RENDER_MODE_LCD_V )
const ( StrokerLinejoinRound int = C.FT_STROKER_LINEJOIN_ROUND StrokerLinejoinBevel int = C.FT_STROKER_LINEJOIN_BEVEL StrokerLinejoinMiterVariable int = C.FT_STROKER_LINEJOIN_MITER_VARIABLE StrokerLinejoinMiter int = C.FT_STROKER_LINEJOIN_MITER StrokerLinejoinMiterFixed int = C.FT_STROKER_LINEJOIN_MITER_FIXED StrokerLinecapButt int = C.FT_STROKER_LINECAP_BUTT StrokerLinecapRound int = C.FT_STROKER_LINECAP_ROUND StrokerLinecapSquare int = C.FT_STROKER_LINECAP_SQUARE StrokerBorderLeft int = C.FT_STROKER_BORDER_LEFT StrokerBorderRight int = C.FT_STROKER_BORDER_RIGHT )
Variables ¶
var ( // wrapper errors ErrUnsupportedPixelMode = errors.New("freetype: unsupported pixel mode") // glyph/character errors ErrCanNotOpenResource = errors.New("freetype: cannot open resource") ErrUnknownFileFormat = errors.New("freetype: unknown file format") ErrInvalidFileFormat = errors.New("freetype: broken file") ErrInvalidVersion = errors.New("freetype: invalid FreeType version") ErrLowerModuleVersion = errors.New("freetype: module version is too low") ErrInvalidArgument = errors.New("freetype: invalid argument") ErrUnimplementedFeature = errors.New("freetype: unimplemented feature") ErrInvalidTable = errors.New("freetype: broken table") ErrInvalidOffset = errors.New("freetype: broken offset within table") ErrArrayTooLarge = errors.New("freetype: array allocation size too large") ErrMissingModule = errors.New("freetype: missing module") ErrMissingProperty = errors.New("freetype: missing property") // glyph/character errors ErrInvalidGlyphIndex = errors.New("freetype: invalid glyph index") ErrInvalidCharacterCode = errors.New("freetype: invalid character code") ErrInvalidGlyphFormat = errors.New("freetype: unsupported glyph image format") ErrCannotRenderGlyph = errors.New("freetype: cannot render this glyph format") ErrInvalidOutline = errors.New("freetype: invalid outline") ErrInvalidComposite = errors.New("freetype: invalid composite glyph") ErrTooManyHints = errors.New("freetype: too many hints") ErrInvalidPixelSize = errors.New("freetype: invalid pixel size") // handle errors ErrInvalidHandle = errors.New("freetype: invalid object handle") ErrInvalidLibraryHandle = errors.New("freetype: invalid library handle") ErrInvalidDriverHandle = errors.New("freetype: invalid module handle") ErrInvalidFaceHandle = errors.New("freetype: invalid face handle") ErrInvalidSizeHandle = errors.New("freetype: invalid size handle") ErrInvalidSlotHandle = errors.New("freetype: invalid glyph slot handle") ErrInvalidCharMapHandle = errors.New("freetype: invalid charmap handle") ErrCacheHandle = errors.New("freetype: invalid cache manager handle") ErrInvalidStreamHandle = errors.New("freetype: invalid stream handle") )
Functions ¶
Types ¶
type BBox ¶
type BBox struct {
// contains filtered or unexported fields
}
A structure used to hold an outline's bounding box, i.e., the coordinates of its extrema in the horizontal and vertical directions.
type Bitmap ¶
type Bitmap struct {
// contains filtered or unexported fields
}
func (*Bitmap) AlphaImage ¶
AlphaImage converts an freetype bitmap of PixelModeGray into an Go image.Alpha. NOTE: Memory is not copied.
func (*Bitmap) NumGrays ¶
This field is only used with PixelModeGray; it gives the number of gray levels used in the bitmap.
func (*Bitmap) Pitch ¶
The pitch's absolute value is the number of bytes taken by one bitmap row, including padding. However, the pitch is positive when the bitmap has a ‘down’ flow, and negative when it has an ‘up’ flow. In all cases, the pitch is an offset to add to a bitmap pointer in order to go down one row.
type BitmapSize ¶
type BitmapSize struct {
// contains filtered or unexported fields
}
This structure models the metrics of a bitmap strike (i.e., a set of glyphs for a given point size and resolution) in a bitmap font. It is used for the ‘available_sizes’ field of Face.
func (*BitmapSize) Height ¶
func (size *BitmapSize) Height() int16
The vertical distance, in pixels, between two consecutive baselines. It is always positive.
func (*BitmapSize) Size ¶
func (size *BitmapSize) Size() int64
The nominal size of the strike in 26.6 fractional points. This field is not very useful.
func (*BitmapSize) Width ¶
func (size *BitmapSize) Width() int16
The average width, in pixels, of all glyphs in the strike.
func (*BitmapSize) XPpem ¶
func (size *BitmapSize) XPpem() int64
The horizontal ppem (nominal width) in 26.6 fractional pixels.
func (*BitmapSize) YPpem ¶
func (size *BitmapSize) YPpem() int64
The vertical ppem (nominal height) in 26.6 fractional pixels.
type CharMap ¶
type CharMap struct {
// contains filtered or unexported fields
}
A handle to a given character map. A charmap is used to translate character codes in a given encoding into glyph indexes for its parent's face. Some font formats may provide several charmaps per font.
func (*CharMap) Encoding ¶
An Encoding tag identifying the charmap. Use this with Face.SelectCharmap.
func (*CharMap) EncodingID ¶
A platform specific encoding number. This also comes from the TrueType specification and should be emulated similarly.
func (*CharMap) PlatformID ¶
An ID number describing the platform for the following encoding ID. This comes directly from the TrueType specification and should be emulated for other formats.
type Face ¶
type Face struct {
// contains filtered or unexported fields
}
func NewMemoryFace ¶
func (*Face) AvailableSizes ¶
func (f *Face) AvailableSizes() []BitmapSize
func (*Face) FamilyName ¶
func (*Face) GetCharIndex ¶
GetCharIndex returns the glyph index of a given character code. This function uses a charmap object to do the mapping.
func (*Face) MaxAdvanceHeight ¶
func (*Face) MaxAdvanceWidth ¶
func (*Face) NumCharmaps ¶
func (*Face) NumFixedSizes ¶
func (*Face) SelectCharmap ¶
func (*Face) SetCharSize ¶
func (*Face) SetPixelSizes ¶
func (*Face) SetTransform ¶
func (*Face) StyleFlags ¶
func (*Face) UnderlinePosition ¶
func (*Face) UnderlineThickness ¶
type Glyph ¶
type Glyph struct {
// contains filtered or unexported fields
}
func (*Glyph) ReinterpretAsOutlineGlyph ¶
func (g *Glyph) ReinterpretAsOutlineGlyph() *OutlineGlyph
func (*Glyph) StrokeBorder ¶
Stroke a given outline glyph object with a given stroker, but only return either its inside or outside border.
type GlyphMetrics ¶
type GlyphMetrics struct {
// contains filtered or unexported fields
}
func (*GlyphMetrics) HoriAdvance ¶
func (m *GlyphMetrics) HoriAdvance() int64
Advance width for horizontal layout.
func (*GlyphMetrics) HoriBearingX ¶
func (m *GlyphMetrics) HoriBearingX() int64
Left side bearing for horizontal layout.
func (*GlyphMetrics) HoriBearingY ¶
func (m *GlyphMetrics) HoriBearingY() int64
Top side bearing for horizontal layout.
func (*GlyphMetrics) VertAdvance ¶
func (m *GlyphMetrics) VertAdvance() int64
Advance height for vertical layout. Positive values mean the glyph has a positive advance downward.
func (*GlyphMetrics) VertBearingX ¶
func (m *GlyphMetrics) VertBearingX() int64
Left side bearing for vertical layout.
func (*GlyphMetrics) VertBearingY ¶
func (m *GlyphMetrics) VertBearingY() int64
Top side bearing for vertical layout. Larger positive values mean further below the vertical glyph origin.
type GlyphSlot ¶
type GlyphSlot struct {
// contains filtered or unexported fields
}
func (*GlyphSlot) BitmapLeft ¶
func (*GlyphSlot) ControlData ¶
func (*GlyphSlot) ControlLen ¶
func (*GlyphSlot) LinearHoriAdvance ¶
func (*GlyphSlot) LinearVertAdvance ¶
func (*GlyphSlot) Metrices ¶
func (g *GlyphSlot) Metrices() *GlyphMetrics
func (*GlyphSlot) NumSubGlyphs ¶
type Library ¶
type Library struct {
// contains filtered or unexported fields
}
A handle to a FreeType library instance. Each ‘library’ is completely independent from the others; it is the ‘root’ of a set of objects like fonts, faces, sizes, etc. In multi-threaded applications, make sure that the same library object or any of its children doesn't get accessed in parallel.
func InitFreeType ¶
type OutlineGlyph ¶
type OutlineGlyph struct {
// contains filtered or unexported fields
}
A handle to an object used to model an outline glyph image. This is a sub-class of Glyph, and a pointer to OutlineGlyphRec.
func CastGlyphToOutlineGlyph ¶
func CastGlyphToOutlineGlyph(glyph *Glyph) *OutlineGlyph
func (*OutlineGlyph) Outline ¶
func (g *OutlineGlyph) Outline() *Outline
func (*OutlineGlyph) Root ¶
func (g *OutlineGlyph) Root() *Glyph
type RasterParams ¶
type RasterParams struct {
// contains filtered or unexported fields
}
func NewRasterParams ¶
func NewRasterParams() *RasterParams
func (*RasterParams) ClipBox ¶
func (params *RasterParams) ClipBox() *BBox
An optional clipping box. It is only used in direct rendering mode. Note that coordinates here should be expressed in integer pixels (and not in 26.6 fixed-point units)
func (*RasterParams) GraySpans ¶
func (params *RasterParams) GraySpans() SpanFunc
func (*RasterParams) SetClipBox ¶
func (params *RasterParams) SetClipBox(bbox *BBox)
func (*RasterParams) SetFlags ¶
func (params *RasterParams) SetFlags(flags int)
func (*RasterParams) SetGraySpans ¶
func (params *RasterParams) SetGraySpans(f SpanFunc)
func (*RasterParams) SetSource ¶
func (params *RasterParams) SetSource(source *interface{})
func (*RasterParams) SetTarget ¶
func (params *RasterParams) SetTarget(target *Bitmap)
func (*RasterParams) Source ¶
func (params *RasterParams) Source() unsafe.Pointer
type SizeMetrics ¶
type SizeMetrics struct {
// contains filtered or unexported fields
}
func (*SizeMetrics) Ascender ¶
func (size *SizeMetrics) Ascender() int64
ascender in 26.6 frac. pixels
func (*SizeMetrics) Descender ¶
func (size *SizeMetrics) Descender() int64
descender in 26.6 frac. pixels
func (*SizeMetrics) Height ¶
func (size *SizeMetrics) Height() int64
text height in 26.6 frac. pixels
func (*SizeMetrics) MaxAdvance ¶
func (size *SizeMetrics) MaxAdvance() int64
max horizontal advance, in 26.6 pixels
func (*SizeMetrics) XScale ¶
func (size *SizeMetrics) XScale() int64
scaling values used to convert font
func (*SizeMetrics) YScale ¶
func (size *SizeMetrics) YScale() int64
units to 26.6 fractional pixels
type Stroker ¶
type Stroker struct {
// contains filtered or unexported fields
}
func NewStroker ¶
func (*Stroker) BeginSubPath ¶
Start a new sub-path in the stroker.
func (*Stroker) ConicTo ¶
‘Draw’ a single quadratic Bézier in the stroker's current sub-path, from the last position.
func (*Stroker) CubicTo ¶
‘Draw’ a single cubic Bézier in the stroker's current sub-path, from the last position.
func (*Stroker) EndSubPath ¶
Close the current sub-path in the stroker.
func (*Stroker) Export ¶
Call this function after Stroker.GetBorderCounts to export all borders to your own Outline structure.
Note that this function appends the border points and contours to your outline,
but does not try to resize its arrays.
func (*Stroker) ExportBorder ¶
Call this function after Stroker.GetBorderCounts to export the corresponding border to your own Outline structure.
Note that this function appends the border points and contours to your outline, but does not try to resize its arrays.
func (*Stroker) GetBorderCounts ¶
Call this function once you have finished parsing your paths with the stroker. It returns the number of points and contours necessary to export one of the ‘border’ or ‘stroke’ outlines generated by the stroker.
func (*Stroker) GetCounts ¶
Call this function once you have finished parsing your paths with the stroker. It returns the number of points and contours necessary to export all points/borders from the stroked outline/path.
func (*Stroker) LineTo ¶
‘Draw’ a single line segment in the stroker's current sub-path, from the last position.
func (*Stroker) ParseOutline ¶
A convenience function used to parse a whole outline with the stroker. The resulting outline(s) can be retrieved later by functions
like Stroker.GetCounts and Stroker.Export.