// OpenFont loads file for use as a font, at the specified size. This is actually OpenFontIndex(file, size, 0). This can load TTF and FON files.
// (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_14.html)
322513
func OpenFont(file string, size int) (*Font, error) {
	_file := C.CString(file)
	defer C.free(unsafe.Pointer(_file))
	_size := (C.int)(size)
	f := (*C.TTF_Font)(C.TTF_OpenFont(_file, _size))

	if f == nil {
		return nil, GetError()
	}
	return &Font{f}, nil
}
359440
func (cr *Context) SetFontSize(size float64) {
	C.cairo_set_font_size(cr.Ptr, C.double(size))
	if err := cr.status(); err != nil {
		panic(err)
	}
}
777920
func (i FontSlant) String() string {
	switch i {
	case FontSlantNormal:
		return "FontSlantNormal"
	case FontSlantItalic:
		return "FontSlantItalic"
	case FontSlantOblique:
		return "FontSlantOblique"
	default:
		return fmt.Sprintf("FontSlant(%d)", i)
	}
}
524881
func IsFont(buf []byte) bool {
	kind, _ := Font(buf)
	return kind != types.Unknown
}
943589
func (f *Fpdf) SetFontStyle(styleStr string) {
	f.SetFont(f.fontFamily, styleStr, f.fontSizePt)
}
542114
func (fs DummyFS) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
	return nil, fs.err
}
1341385
func (f *Fpdf) AddFontFromReader(familyStr, styleStr string, r io.Reader) {
	if f.err != nil {
		return
	}
	// dbg("Adding family [%s], style [%s]", familyStr, styleStr)
	var ok bool
	fontkey := getFontKey(familyStr, styleStr)
	_, ok = f.fonts[fontkey]
	if ok {
		return
	}
	var info fontDefType
	info = f.loadfont(r)
	if f.err != nil {
		return
	}
	if len(info.Diff) > 0 {
		// Search existing encodings
		n := -1
		for j, str := range f.diffs {
			if str == info.Diff {
				n = j + 1
				break
			}
		}
		if n < 0 {
			f.diffs = append(f.diffs, info.Diff)
			n = len(f.diffs)
		}
		info.DiffN = n
	}
	// dbg("font [%s], type [%s]", info.File, info.Tp)
	if len(info.File) > 0 {
		// Embedded font
		if info.Tp == "TrueType" {
			f.fontFiles[info.File] = fontFileType{length1: int64(info.OriginalSize)}
		} else {
			f.fontFiles[info.File] = fontFileType{length1: int64(info.Size1), length2: int64(info.Size2)}
		}
	}
	f.fonts[fontkey] = info
	return
}
596839
func parseFont(fontFile string) (*truetype.Font, error) {
	fontBytes, err := ioutil.ReadFile(fontFile)
	if err != nil {
		return nil, err
	}

	font, err := truetype.Parse(fontBytes)
	if err != nil {
		return nil, err
	}

	return font, nil
}
873218
func Font(buf []byte) (types.Type, error) {
	return doMatchMap(buf, matchers.Font)
}
952769
func (s Style) GetFont(defaults ...*truetype.Font) *truetype.Font {
	if s.Font == nil {
		if len(defaults) > 0 {
			return defaults[0]
		}
		return nil
	}
	return s.Font
}
1208491
func (vr *vectorRenderer) SetFont(f *truetype.Font) {
	vr.s.Font = f
}
7794
func (s *DvbSubDestinationSettings) SetFontScript(v string) *DvbSubDestinationSettings {
	s.FontScript = &v
	return s
}
388606
func (t *TM1638Driver) AddFonts(fonts map[string]byte) {
	for k, v := range fonts {
		t.fonts[k] = v
	}
}
524132
func (s *BurnInDestinationSettings) SetFontSize(v string) *BurnInDestinationSettings {
	s.FontSize = &v
	return s
}
1171857
func (cr *Context) SelectFontFace(family string, slant FontSlant, weight FontWeight) {
	c_family := C.CString(family)
	defer C.free(unsafe.Pointer(c_family))
	C.cairo_select_font_face(cr.Ptr, c_family, C.cairo_font_slant_t(slant), C.cairo_font_weight_t(weight))
	if err := cr.status(); err != nil {
		panic(err)
	}
}
1178735
func (s Style) GetFontSize(defaults ...float64) float64 {
	if s.FontSize == 0 {
		if len(defaults) > 0 {
			return defaults[0]
		}
		return DefaultFontSize
	}
	return s.FontSize
}
1034940
func (f *Font) SetStyle(style int) {
	C.TTF_SetFontStyle(f.f, C.int(style))
}