forked from gonum/plot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vg/vgsvg: drop fontMap, use informations from font.Font
This CL drops the use of the internal fontMap that was associating some pre-defined set of fonts with a set of SVG naming schemes (derived from PostScript). Instead, use the informations contained in plot/font.Font to derive the expected SVG font-family (and friends) font style string. Updates gonum#702.
- Loading branch information
Showing
4 changed files
with
276 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
// Copyright ©2021 The Gonum Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package vgsvg | ||
|
||
import ( | ||
"testing" | ||
|
||
stdfnt "golang.org/x/image/font" | ||
"gonum.org/v1/plot/font" | ||
) | ||
|
||
func TestSVGFontDescr(t *testing.T) { | ||
for i, tc := range []struct { | ||
fnt font.Font | ||
want string | ||
}{ | ||
// typefaces | ||
{ | ||
fnt: font.Font{Typeface: "Liberation"}, | ||
want: "font-family:Liberation;font-variant:normal;font-weight:normal;font-style:normal", | ||
}, | ||
{ | ||
fnt: font.Font{ | ||
Typeface: "Liberation", | ||
Variant: "", | ||
Style: stdfnt.StyleNormal, | ||
Weight: stdfnt.WeightNormal, | ||
}, | ||
want: "font-family:Liberation;font-variant:normal;font-weight:normal;font-style:normal", | ||
}, | ||
{ | ||
fnt: font.Font{ | ||
Typeface: "My-Font-Name", | ||
Variant: "", | ||
Style: stdfnt.StyleNormal, | ||
Weight: stdfnt.WeightNormal, | ||
}, | ||
want: "font-family:My-Font-Name;font-variant:normal;font-weight:normal;font-style:normal", | ||
}, | ||
// variants | ||
{ | ||
fnt: font.Font{ | ||
Typeface: "Liberation", | ||
Variant: "Mono", | ||
Style: stdfnt.StyleNormal, | ||
Weight: stdfnt.WeightNormal, | ||
}, | ||
want: "font-family:Liberation, monospace;font-variant:monospace;font-weight:normal;font-style:normal", | ||
}, | ||
{ | ||
fnt: font.Font{ | ||
Typeface: "Liberation", | ||
Variant: "Serif", | ||
Style: stdfnt.StyleNormal, | ||
Weight: stdfnt.WeightNormal, | ||
}, | ||
want: "font-family:Liberation, serif;font-variant:serif;font-weight:normal;font-style:normal", | ||
}, | ||
{ | ||
fnt: font.Font{ | ||
Typeface: "Liberation", | ||
Variant: "Sans", | ||
Style: stdfnt.StyleNormal, | ||
Weight: stdfnt.WeightNormal, | ||
}, | ||
want: "font-family:Liberation, sans-serif;font-variant:sans-serif;font-weight:normal;font-style:normal", | ||
}, | ||
{ | ||
fnt: font.Font{ | ||
Typeface: "Liberation", | ||
Variant: "SansSerif", | ||
Style: stdfnt.StyleNormal, | ||
Weight: stdfnt.WeightNormal, | ||
}, | ||
want: "font-family:Liberation, sans-serif;font-variant:sans-serif;font-weight:normal;font-style:normal", | ||
}, | ||
{ | ||
fnt: font.Font{ | ||
Typeface: "Liberation", | ||
Variant: "Sans-Serif", | ||
Style: stdfnt.StyleNormal, | ||
Weight: stdfnt.WeightNormal, | ||
}, | ||
want: "font-family:Liberation, sans-serif;font-variant:sans-serif;font-weight:normal;font-style:normal", | ||
}, | ||
{ | ||
fnt: font.Font{ | ||
Typeface: "Liberation", | ||
Variant: "Smallcaps", | ||
Style: stdfnt.StyleNormal, | ||
Weight: stdfnt.WeightNormal, | ||
}, | ||
want: "font-family:Liberation, small-caps;font-variant:small-caps;font-weight:normal;font-style:normal", | ||
}, | ||
// styles | ||
{ | ||
fnt: font.Font{ | ||
Typeface: "Liberation", | ||
Variant: "", | ||
Style: stdfnt.StyleItalic, | ||
Weight: stdfnt.WeightNormal, | ||
}, | ||
want: "font-family:Liberation;font-variant:normal;font-weight:normal;font-style:italic", | ||
}, | ||
{ | ||
fnt: font.Font{ | ||
Typeface: "Liberation", | ||
Variant: "", | ||
Style: stdfnt.StyleOblique, | ||
Weight: stdfnt.WeightNormal, | ||
}, | ||
want: "font-family:Liberation;font-variant:normal;font-weight:normal;font-style:oblique", | ||
}, | ||
// weights | ||
{ | ||
fnt: font.Font{ | ||
Typeface: "Liberation", | ||
Variant: "", | ||
Style: stdfnt.StyleNormal, | ||
Weight: stdfnt.WeightThin, | ||
}, | ||
want: "font-family:Liberation;font-variant:normal;font-weight:100;font-style:normal", | ||
}, | ||
{ | ||
fnt: font.Font{ | ||
Typeface: "Liberation", | ||
Variant: "", | ||
Style: stdfnt.StyleNormal, | ||
Weight: stdfnt.WeightBold, | ||
}, | ||
want: "font-family:Liberation;font-variant:normal;font-weight:bold;font-style:normal", | ||
}, | ||
{ | ||
fnt: font.Font{ | ||
Typeface: "Liberation", | ||
Variant: "", | ||
Style: stdfnt.StyleNormal, | ||
}, | ||
want: "font-family:Liberation;font-variant:normal;font-weight:normal;font-style:normal", | ||
}, | ||
{ | ||
fnt: font.Font{ | ||
Typeface: "Liberation", | ||
Variant: "", | ||
Style: stdfnt.StyleNormal, | ||
Weight: stdfnt.WeightExtraBold, | ||
}, | ||
want: "font-family:Liberation;font-variant:normal;font-weight:800;font-style:normal", | ||
}, | ||
// weights+styles | ||
{ | ||
fnt: font.Font{ | ||
Typeface: "Times", | ||
Variant: "", | ||
Style: stdfnt.StyleItalic, | ||
Weight: stdfnt.WeightBold, | ||
}, | ||
want: "font-family:Times;font-variant:normal;font-weight:bold;font-style:italic", | ||
}, | ||
} { | ||
got := svgFontDescr(tc.fnt) | ||
if got != tc.want { | ||
t.Errorf( | ||
"invalid SVG font[%d] description:\ngot= %s\nwant=%s", | ||
i, got, tc.want, | ||
) | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.