-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
font/{liberation,lm},cmd/mtex-render: expose ttf.Fonts collections
- Loading branch information
Showing
3 changed files
with
122 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
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,58 @@ | ||
// Copyright ©2021 The go-latex 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 liberation provides a ttf.Fonts value populated with Liberation fonts. | ||
package liberation // import "github.com/go-latex/latex/font/liberation" | ||
|
||
import ( | ||
"log" | ||
"sync" | ||
|
||
"github.com/go-fonts/liberation/liberationserifbold" | ||
"github.com/go-fonts/liberation/liberationserifbolditalic" | ||
"github.com/go-fonts/liberation/liberationserifitalic" | ||
"github.com/go-fonts/liberation/liberationserifregular" | ||
"golang.org/x/image/font/sfnt" | ||
|
||
"github.com/go-latex/latex/font/ttf" | ||
) | ||
|
||
var ( | ||
once sync.Once | ||
fnts *ttf.Fonts | ||
) | ||
|
||
// Fonts returns a ttf.Fonts value populated with Liberation fonts. | ||
func Fonts() *ttf.Fonts { | ||
once.Do(func() { | ||
rm, err := sfnt.Parse(liberationserifregular.TTF) | ||
if err != nil { | ||
log.Panicf("could not parse fonts: %+v", err) | ||
} | ||
|
||
it, err := sfnt.Parse(liberationserifitalic.TTF) | ||
if err != nil { | ||
log.Panicf("could not parse fonts: %+v", err) | ||
} | ||
|
||
bf, err := sfnt.Parse(liberationserifbold.TTF) | ||
if err != nil { | ||
log.Panicf("could not parse fonts: %+v", err) | ||
} | ||
|
||
bfit, err := sfnt.Parse(liberationserifbolditalic.TTF) | ||
if err != nil { | ||
log.Panicf("could not parse fonts: %+v", err) | ||
} | ||
|
||
fnts = &ttf.Fonts{ | ||
Default: rm, | ||
Rm: rm, | ||
It: it, | ||
Bf: bf, | ||
BfIt: bfit, | ||
} | ||
}) | ||
return fnts | ||
} |
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,60 @@ | ||
// Copyright ©2021 The go-latex 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 lm provides a ttf.Fonts value populated with latin-modern, | ||
// a LaTeX-looking font. | ||
package lm // import "github.com/go-latex/latex/font/lm" | ||
|
||
import ( | ||
"log" | ||
"sync" | ||
|
||
lmromanbold "github.com/go-fonts/latin-modern/lmroman10bold" | ||
lmromanbolditalic "github.com/go-fonts/latin-modern/lmroman10bolditalic" | ||
lmromanitalic "github.com/go-fonts/latin-modern/lmroman10italic" | ||
lmromanregular "github.com/go-fonts/latin-modern/lmroman10regular" | ||
"golang.org/x/image/font/sfnt" | ||
|
||
"github.com/go-latex/latex/font/ttf" | ||
) | ||
|
||
var ( | ||
once sync.Once | ||
fnts *ttf.Fonts | ||
) | ||
|
||
// Fonts returns a ttf.Fonts value populated with latin-modern fonts. | ||
func Fonts() *ttf.Fonts { | ||
once.Do(func() { | ||
rm, err := sfnt.Parse(lmromanregular.TTF) | ||
if err != nil { | ||
log.Panicf("could not parse fonts: %+v", err) | ||
} | ||
|
||
it, err := sfnt.Parse(lmromanitalic.TTF) | ||
if err != nil { | ||
log.Panicf("could not parse fonts: %+v", err) | ||
} | ||
|
||
bf, err := sfnt.Parse(lmromanbold.TTF) | ||
if err != nil { | ||
log.Panicf("could not parse fonts: %+v", err) | ||
} | ||
|
||
bfit, err := sfnt.Parse(lmromanbolditalic.TTF) | ||
if err != nil { | ||
log.Panicf("could not parse fonts: %+v", err) | ||
} | ||
|
||
fnts = &ttf.Fonts{ | ||
Default: rm, | ||
Rm: rm, | ||
It: it, | ||
Bf: bf, | ||
BfIt: bfit, | ||
} | ||
}) | ||
|
||
return fnts | ||
} |