// Test restricting a "preferred" font's usage to a particular range. // If two fonts each implement both of two ranges, but one font is superior for // one range and the other font is superior for the other range, the first font // can be restricted to only specified ranges. func TestNewRichText_ChineseAndEnglish_ranges(t *testing.T) { st := SuperTest{t} fc, err := ttf_fonts.New("/Library/Fonts/*.ttf") if err != nil { t.Fatal(err) } cjk, err := ttf.NewCodepointRangeSet("CJK Unified Ideographs") if err != nil { t.Fatal(err) } stFangsong, err := font.New("STFangsong", options.Options{"ranges": cjk}, font.FontSources{fc}) if err != nil { t.Fatal(err) } arial, err := font.New("Arial", options.Options{}, font.FontSources{fc}) if err != nil { t.Fatal(err) } fonts := []*font.Font{stFangsong, arial} rt, err := New("所有测abc", fonts, 10, options.Options{}) if err != nil { t.Fatal(err) } st.Must(len(rt.pieces) == 2, "Expecting 2 pieces.") st.Equal("所有测", rt.pieces[0].Text) st.Equal(10.0, rt.pieces[0].FontSize) st.Equal("abc", rt.pieces[1].Text) st.Equal(10.0, rt.pieces[1].FontSize) st.Equal(fonts[0], rt.pieces[0].Font, "Should be tagged with STFangsong font.") st.Equal(fonts[1], rt.pieces[1].Font, "Should be tagged with Arial font.") }
func (pw *PageWriter) AddFont(family string, options options.Options) ([]*font.Font, error) { if font, err := font.New(family, options, pw.dw.fontSources); err != nil { return nil, err } else { return pw.addFont(font), nil } }
func Families(families ...string) (fonts []*font.Font) { fc, err := New("/Library/Fonts/*.ttf") if err != nil { panic(err) } for _, family := range families { if family == "" { fonts = append(fonts, nil) continue } f, err := font.New(family, options.Options{}, font.FontSources{fc}) if err != nil { panic(err) } fonts = append(fonts, f) } return }