Ejemplo n.º 1
0
Archivo: draw.go Proyecto: duckbrain/ui
// LoadClosestFont loads a Font.
//
// You pass the properties of the ideal font you want to load in the
// FontDescriptor you pass to this function. If the requested font
// is not available on the system, the closest matching font is used.
// This means that, for instance, if you specify a Weight of
// TextWeightUltraHeavy and the heaviest weight available for the
// chosen font family is actually TextWeightBold, that will be used
// instead. The specific details of font matching beyond this
// description are implementation defined. This also means that
// getting a descriptor back out of a Font may return a different
// desriptor.
//
// TODO guarantee that passing *that* back into LoadClosestFont() returns the same font
func LoadClosestFont(desc *FontDescriptor) *Font {
	d := C.newFontDescriptor() // both of these are freed by C.newFont()
	d.Family = C.CString(desc.Family)
	d.Size = C.double(desc.Size)
	d.Weight = C.uiDrawTextWeight(desc.Weight)
	d.Italic = C.uiDrawTextItalic(desc.Italic)
	d.Stretch = C.uiDrawTextStretch(desc.Stretch)
	return &Font{
		f: C.newFont(d),
	}
}
Ejemplo n.º 2
0
Archivo: draw.go Proyecto: luoshulin/ui
// LoadClosestFont loads a Font.
//
// You pass the properties of the ideal font you want to load in the
// FontDescriptor you pass to this function. If the requested font
// is not available on the system, the closest matching font is used.
// This means that, for instance, if you specify a Weight of
// TextWeightUltraHeavy and the heaviest weight available for the
// chosen font family is actually TextWeightBold, that will be used
// instead. The specific details of font matching beyond this
// description are implementation defined. This also means that
// getting a descriptor back out of a Font may return a different
// desriptor.
//
// TODO guarantee that passing *that* back into LoadClosestFont() returns the same font
func LoadClosestFont(desc *FontDescriptor) *Font {
	d := C.newFontDescriptor() // both of these are freed by C.newFont()
	d.Family = C.CString(desc.Family)
	d.Size = C.double(desc.Size)
	d.Weight = C.uiDrawTextWeight(desc.Weight)
	d.Italic = C.uiDrawTextItalic(desc.Italic)
	d.SmallCaps = frombool(desc.SmallCaps)
	d.Stretch = C.uiDrawTextStretch(desc.Stretch)
	//	d.Gravity = C.uiDrawTextGravity(desc.Gravity)
	d.Gravity = C.uiDrawTextGravitySouth
	return &Font{
		f: C.newFont(d),
	}
}