@@ -5,9 +5,7 @@ package font
55
66import (
77 "fmt"
8- "strconv"
98
10- "github.com/rowland/leadtype/colors"
119 "github.com/rowland/leadtype/options"
1210 "github.com/rowland/leadtype/shaping"
1311)
@@ -33,58 +31,14 @@ type Font struct {
3331 // (e.g. Arabic). It is set automatically by New when the winning FontSource
3432 // implements ShaperSource.
3533 Shaper shaping.Shaper
36-
37- strikeoutPosition int16
38- strikeoutThickness int16
39- strikeoutColor colors.Color
40- strikeoutCapStyle string
41- underlinePosition int16
42- underlineThickness int16
43- underlineColor colors.Color
44- underlineCapStyle string
45-
46- strikeoutPositionSet bool
47- strikeoutThicknessSet bool
48- strikeoutColorSet bool
49- strikeoutCapStyleSet bool
50- underlinePositionSet bool
51- underlineThicknessSet bool
52- underlineColorSet bool
53- underlineCapStyleSet bool
5434}
5535
5636func New (family string , options options.Options , fontSources FontSources ) (* Font , error ) {
57- strikeoutPosition , strikeoutPositionSet := decorationInt16Option (options , "strikeout_position" )
58- strikeoutThickness , strikeoutThicknessSet := decorationInt16Option (options , "strikeout_thickness" )
59- strikeoutColor , strikeoutColorSet := decorationColorOption (options , "strikeout_color" )
60- strikeoutCapStyle , strikeoutCapStyleSet := decorationLineCapStyleOption (options , "strikeout_cap" )
61-
62- underlinePosition , underlinePositionSet := decorationInt16Option (options , "underline_position" )
63- underlineThickness , underlineThicknessSet := decorationInt16Option (options , "underline_thickness" )
64- underlineColor , underlineColorSet := decorationColorOption (options , "underline_color" )
65- underlineCapStyle , underlineCapStyleSet := decorationLineCapStyleOption (options , "underline_cap" )
66-
6737 font := & Font {
68- family : family ,
69- Weight : options .StringDefault ("weight" , "" ),
70- style : options .StringDefault ("style" , "" ),
71- RelativeSize : options .FloatDefault ("relative_size" , 100 ) / 100.0 ,
72- strikeoutPosition : strikeoutPosition ,
73- strikeoutThickness : strikeoutThickness ,
74- strikeoutColor : strikeoutColor ,
75- strikeoutCapStyle : strikeoutCapStyle ,
76- underlinePosition : underlinePosition ,
77- underlineThickness : underlineThickness ,
78- underlineColor : underlineColor ,
79- underlineCapStyle : underlineCapStyle ,
80- strikeoutPositionSet : strikeoutPositionSet ,
81- strikeoutThicknessSet : strikeoutThicknessSet ,
82- strikeoutColorSet : strikeoutColorSet ,
83- strikeoutCapStyleSet : strikeoutCapStyleSet ,
84- underlinePositionSet : underlinePositionSet ,
85- underlineThicknessSet : underlineThicknessSet ,
86- underlineColorSet : underlineColorSet ,
87- underlineCapStyleSet : underlineCapStyleSet ,
38+ family : family ,
39+ Weight : options .StringDefault ("weight" , "" ),
40+ style : options .StringDefault ("style" , "" ),
41+ RelativeSize : options .FloatDefault ("relative_size" , 100 ) / 100.0 ,
8842 }
8943 if Ranges , ok := options ["ranges" ]; ok {
9044 switch Ranges := Ranges .(type ) {
@@ -194,22 +148,6 @@ func (font *Font) Matches(other *Font) bool {
194148 font .subType == other .subType &&
195149 font .RuneSet == other .RuneSet &&
196150 font .RelativeSize == other .RelativeSize &&
197- font .strikeoutPosition == other .strikeoutPosition &&
198- font .strikeoutThickness == other .strikeoutThickness &&
199- font .strikeoutColor == other .strikeoutColor &&
200- font .strikeoutCapStyle == other .strikeoutCapStyle &&
201- font .underlinePosition == other .underlinePosition &&
202- font .underlineThickness == other .underlineThickness &&
203- font .underlineColor == other .underlineColor &&
204- font .underlineCapStyle == other .underlineCapStyle &&
205- font .strikeoutPositionSet == other .strikeoutPositionSet &&
206- font .strikeoutThicknessSet == other .strikeoutThicknessSet &&
207- font .strikeoutColorSet == other .strikeoutColorSet &&
208- font .strikeoutCapStyleSet == other .strikeoutCapStyleSet &&
209- font .underlinePositionSet == other .underlinePositionSet &&
210- font .underlineThicknessSet == other .underlineThicknessSet &&
211- font .underlineColorSet == other .underlineColorSet &&
212- font .underlineCapStyleSet == other .underlineCapStyleSet &&
213151 stringSlicesEqual (font .Ranges , other .Ranges )
214152}
215153
@@ -233,33 +171,13 @@ func (font *Font) SupportsArabic() bool {
233171}
234172
235173func (font * Font ) StrikeoutPosition () int {
236- if font .strikeoutPositionSet {
237- return int (font .strikeoutPosition )
238- }
239174 return font .metrics .StrikeoutPosition ()
240175}
241176
242177func (font * Font ) StrikeoutThickness () int {
243- if font .strikeoutThicknessSet {
244- return int (font .strikeoutThickness )
245- }
246178 return font .metrics .StrikeoutThickness ()
247179}
248180
249- func (font * Font ) StrikeoutColor () (colors.Color , bool ) {
250- if font .strikeoutColorSet {
251- return font .strikeoutColor , true
252- }
253- return 0 , false
254- }
255-
256- func (font * Font ) StrikeoutCapStyle () string {
257- if font .strikeoutCapStyleSet {
258- return font .strikeoutCapStyle
259- }
260- return ""
261- }
262-
263181func (font * Font ) Style () string {
264182 return font .style
265183}
@@ -269,33 +187,13 @@ func (font *Font) SubType() string {
269187}
270188
271189func (font * Font ) UnderlinePosition () int {
272- if font .underlinePositionSet {
273- return int (font .underlinePosition )
274- }
275190 return font .metrics .UnderlinePosition ()
276191}
277192
278193func (font * Font ) UnderlineThickness () int {
279- if font .underlineThicknessSet {
280- return int (font .underlineThickness )
281- }
282194 return font .metrics .UnderlineThickness ()
283195}
284196
285- func (font * Font ) UnderlineColor () (colors.Color , bool ) {
286- if font .underlineColorSet {
287- return font .underlineColor , true
288- }
289- return 0 , false
290- }
291-
292- func (font * Font ) UnderlineCapStyle () string {
293- if font .underlineCapStyleSet {
294- return font .underlineCapStyle
295- }
296- return ""
297- }
298-
299197func (font * Font ) UnitsPerEm () int {
300198 return font .metrics .UnitsPerEm ()
301199}
@@ -362,83 +260,3 @@ func stringSlicesEqual(sl1, sl2 []string) bool {
362260 }
363261 return true
364262}
365-
366- func normalizeDecorationLineCapStyle (style string ) string {
367- switch style {
368- case "butt_cap" , "round_cap" , "projecting_square_cap" :
369- return style
370- default :
371- return ""
372- }
373- }
374-
375- func decorationColorOption (opts options.Options , key string ) (colors.Color , bool ) {
376- value , ok := opts [key ]
377- if ! ok {
378- return 0 , false
379- }
380- switch value := value .(type ) {
381- case colors.Color :
382- return value , true
383- case string :
384- color , err := colors .NamedColor (value )
385- if err != nil {
386- return 0 , false
387- }
388- return color , true
389- case int :
390- return colors .Color (value ), true
391- case int32 :
392- return colors .Color (value ), true
393- default :
394- return 0 , false
395- }
396- }
397-
398- func decorationLineCapStyleOption (opts options.Options , key string ) (string , bool ) {
399- value , ok := opts [key ]
400- if ! ok {
401- return "" , false
402- }
403- style , ok := value .(string )
404- if ! ok {
405- return "" , false
406- }
407- style = normalizeDecorationLineCapStyle (style )
408- if style == "" {
409- return "" , false
410- }
411- return style , true
412- }
413-
414- func decorationInt16Option (opts options.Options , key string ) (int16 , bool ) {
415- value , ok := opts [key ]
416- if ! ok {
417- return 0 , false
418- }
419- switch value := value .(type ) {
420- case int :
421- return int16InRange (value )
422- case int16 :
423- return value , true
424- case int32 :
425- return int16InRange (int (value ))
426- case float64 :
427- return int16InRange (int (value ))
428- case string :
429- i , err := strconv .Atoi (value )
430- if err != nil {
431- return 0 , false
432- }
433- return int16InRange (i )
434- default :
435- return 0 , false
436- }
437- }
438-
439- func int16InRange (value int ) (int16 , bool ) {
440- if value < - 32768 || value > 32767 {
441- return 0 , false
442- }
443- return int16 (value ), true
444- }
0 commit comments