// See cairo_scaled_font_text_extents().
//
// C API documentation: http://cairographics.org/manual/cairo-cairo-scaled-font-t.html#cairo-scaled-font-text-extents
359730
func (scaledFont *ScaledFont) TextExtents(utf8 string, extents *TextExtents) {
	c_utf8 := C.CString(utf8)
	defer C.free(unsafe.Pointer(c_utf8))
	C.cairo_scaled_font_text_extents(scaledFont.Ptr, c_utf8, (*C.cairo_text_extents_t)(unsafe.Pointer(extents)))
	if err := scaledFont.status(); err != nil {
		panic(err)
	}
}
1247338
func (original *FontOptions) Copy() *FontOptions {
	ret := wrapFontOptions(C.cairo_font_options_copy(original.Ptr))
	if err := original.status(); err != nil {
		panic(err)
	}
	return ret
}
1308809
func (hrt HTMLRichText) Italic(text string) string {
	if text == "" {
		return ""
	}

	text = fmt.Sprintf("<i>%s</i>", hrt.EncodeEntities(text))
	return text
}
1038041
func (c RGBA) Scaled(scale float64) RGBA {
	return RGBA{
		R: c.R * scale,
		G: c.G * scale,
		B: c.B * scale,
		A: c.A * scale,
	}
}
646367
func (t Text) Width() float32 {
	atlas, ok := atlasCache[*t.Font]
	if !ok {
		// Generate texture first
		atlas = t.Font.generateFontAtlas(200)
		atlasCache[*t.Font] = atlas
	}

	var currentX float32
	var greatestX float32

	for _, char := range t.Text {
		// TODO: this might not work for all characters
		switch {
		case char == '\n':
			if currentX > greatestX {
				greatestX = currentX
			}
			currentX = 0
			continue
		case char < 32: // all system stuff should be ignored
			continue
		}

		currentX += atlas.Width[char] + float32(t.Font.Size)*t.LetterSpacing
	}
	if currentX > greatestX {
		return currentX
	}
	return greatestX
}
763199
func (d draw) Text(r Renderer, text string, x, y int, style Style) {
	style.GetTextOptions().WriteToRenderer(r)
	defer r.ResetStyle()

	r.Text(text, x, y)
}
688386
func (cr *Context) TextExtents(utf8 string, extents *TextExtents) {
	c_utf8 := C.CString(utf8)
	defer C.free(unsafe.Pointer(c_utf8))
	C.cairo_text_extents(cr.Ptr, c_utf8, (*C.cairo_text_extents_t)(unsafe.Pointer(extents)))
	if err := cr.status(); err != nil {
		panic(err)
	}
}
683185
func (s *UpdateByQueryService) LowercaseExpandedTerms(lowercaseExpandedTerms bool) *UpdateByQueryService {
	s.lowercaseExpandedTerms = &lowercaseExpandedTerms
	return s
}
430125
func (this *AsciiRender) LoadFont(fontPath string) error {
	return this.fontMgr.loadFont(fontPath)
}
811066
func (cr *Context) ShowText(utf8 string) {
	c_utf8 := C.CString(utf8)
	defer C.free(unsafe.Pointer(c_utf8))
	C.cairo_show_text(cr.Ptr, c_utf8)
	if err := cr.status(); err != nil {
		panic(err)
	}
}
729025
func (scaledFont *ScaledFont) GetFontMatrix(fontMatrix *Matrix) {
	C.cairo_scaled_font_get_font_matrix(scaledFont.Ptr, (*C.cairo_matrix_t)(unsafe.Pointer(fontMatrix)))
	if err := scaledFont.status(); err != nil {
		panic(err)
	}
}
167851
func (f *Fpdf) loadfont(r io.Reader) (def fontDefType) {
	if f.err != nil {
		return
	}
	// dbg("Loading font [%s]", fontStr)
	var buf bytes.Buffer
	_, err := buf.ReadFrom(r)
	if err != nil {
		f.err = err
		return
	}
	err = json.Unmarshal(buf.Bytes(), &def)
	if err != nil {
		f.err = err
		return
	}

	if def.i, err = generateFontID(def); err != nil {
		f.err = err
	}
	// dump(def)
	return
}
5121
func (cr *Context) GetFontOptions(options *FontOptions) {
	C.cairo_get_font_options(cr.Ptr, options.Ptr)
	if err := cr.status(); err != nil {
		panic(err)
	}
}
56432
func UserFontFaceCreate() *FontFace {
	ret := wrapFontFace(C.cairo_user_font_face_create())
	if err := ret.status(); err != nil {
		panic(err)
	}
	return ret
}
388606
func (t *TM1638Driver) AddFonts(fonts map[string]byte) {
	for k, v := range fonts {
		t.fonts[k] = v
	}
}
826053
func (scaledFont *ScaledFont) status() error {
	ret := Status(C.cairo_scaled_font_status(scaledFont.Ptr)).toError()
	return ret
}
768578
func (gp *GoPdf) MeasureTextWidth(text string) (float64, error) {

	err := gp.curr.Font_ISubset.AddChars(text) //AddChars for create CharacterToGlyphIndex
	if err != nil {
		return 0, err
	}

	_, _, textWidthPdfUnit, err := createContent(gp.curr.Font_ISubset, text, gp.curr.Font_Size, nil)
	if err != nil {
		return 0, err
	}
	return PointsToUnits(gp.config.Unit, textWidthPdfUnit), nil
}