Example #1
0
File: draw.go Project: 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),
	}
}
Example #2
0
File: draw.go Project: 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),
	}
}
Example #3
0
File: draw.go Project: xushiwei/ui
// NewTextLayout creates a new TextLayout.
func NewTextLayout(text string, initialStyle *InitialTextStyle) *TextLayout {
	l := new(TextLayout)
	ctext := C.CString(text) // all three of these are cleaned up by C.newTextLayout()
	is := C.newInitialTextStyle()
	is.Family = C.CString(initialStyle.Family)
	is.Size = C.double(initialStyle.Size)
	is.Weight = C.uiDrawTextWeight(initialStyle.Weight)
	is.Italic = C.uiDrawTextItalic(initialStyle.Italic)
	is.SmallCaps = frombool(initialStyle.SmallCaps)
	is.Stretch = C.uiDrawTextStretch(initialStyle.Stretch)
	//	is.Gravity = C.uiDrawTextGravity(initialStyle.Gravity)
	is.Gravity = C.uiDrawTextGravitySouth
	l.l = C.newTextLayout(ctext, is)
	return l
}