2023-11-25 13:53:46 +01:00
|
|
|
// Copyright 2023 The Ebitengine Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package text
|
|
|
|
|
|
|
|
import (
|
2024-09-09 16:07:30 +02:00
|
|
|
"github.com/go-text/typesetting/font"
|
|
|
|
"github.com/go-text/typesetting/font/opentype"
|
2023-11-25 13:53:46 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Metadata represents a font face's metadata.
|
|
|
|
type Metadata struct {
|
2023-11-28 04:22:06 +01:00
|
|
|
Family string
|
|
|
|
Style Style
|
|
|
|
Weight Weight
|
|
|
|
Stretch Stretch
|
2023-11-25 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
2024-09-09 16:07:30 +02:00
|
|
|
func metadataFromLoader(l *opentype.Loader) Metadata {
|
|
|
|
d, _ := font.Describe(l, nil)
|
2023-11-25 13:53:46 +01:00
|
|
|
return Metadata{
|
2024-09-09 16:07:30 +02:00
|
|
|
Family: d.Family,
|
|
|
|
Style: Style(d.Aspect.Style),
|
|
|
|
Weight: Weight(d.Aspect.Weight),
|
|
|
|
Stretch: Stretch(d.Aspect.Stretch),
|
2023-11-25 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type Style uint8
|
|
|
|
|
|
|
|
const (
|
2024-09-09 16:07:30 +02:00
|
|
|
StyleNormal Style = Style(font.StyleNormal)
|
|
|
|
StyleItalic Style = Style(font.StyleItalic)
|
2023-11-25 13:53:46 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type Weight float32
|
|
|
|
|
|
|
|
const (
|
2024-09-09 16:07:30 +02:00
|
|
|
WeightThin Weight = Weight(font.WeightThin)
|
|
|
|
WeightExtraLight Weight = Weight(font.WeightExtraLight)
|
|
|
|
WeightLight Weight = Weight(font.WeightLight)
|
|
|
|
WeightNormal Weight = Weight(font.WeightNormal)
|
|
|
|
WeightMedium Weight = Weight(font.WeightMedium)
|
|
|
|
WeightSemibold Weight = Weight(font.WeightSemibold)
|
|
|
|
WeightBold Weight = Weight(font.WeightBold)
|
|
|
|
WeightExtraBold Weight = Weight(font.WeightExtraBold)
|
|
|
|
WeightBlack Weight = Weight(font.WeightBlack)
|
2023-11-25 13:53:46 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type Stretch float32
|
|
|
|
|
|
|
|
const (
|
2024-09-09 16:07:30 +02:00
|
|
|
StretchUltraCondensed Stretch = Stretch(font.StretchUltraCondensed)
|
|
|
|
StretchExtraCondensed Stretch = Stretch(font.StretchExtraCondensed)
|
|
|
|
StretchCondensed Stretch = Stretch(font.StretchCondensed)
|
|
|
|
StretchSemiCondensed Stretch = Stretch(font.StretchSemiCondensed)
|
|
|
|
StretchNormal Stretch = Stretch(font.StretchNormal)
|
|
|
|
StretchSemiExpanded Stretch = Stretch(font.StretchSemiExpanded)
|
|
|
|
StretchExpanded Stretch = Stretch(font.StretchExpanded)
|
|
|
|
StretchExtraExpanded Stretch = Stretch(font.StretchExtraExpanded)
|
|
|
|
StretchUltraExpanded Stretch = Stretch(font.StretchUltraExpanded)
|
2023-11-25 13:53:46 +01:00
|
|
|
)
|