metadata.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2023 The Ebitengine Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package text
  15. import (
  16. "github.com/go-text/typesetting/font"
  17. "github.com/go-text/typesetting/font/opentype"
  18. )
  19. // Metadata represents a font face's metadata.
  20. type Metadata struct {
  21. Family string
  22. Style Style
  23. Weight Weight
  24. Stretch Stretch
  25. }
  26. func metadataFromLoader(l *opentype.Loader) Metadata {
  27. d, _ := font.Describe(l, nil)
  28. return Metadata{
  29. Family: d.Family,
  30. Style: Style(d.Aspect.Style),
  31. Weight: Weight(d.Aspect.Weight),
  32. Stretch: Stretch(d.Aspect.Stretch),
  33. }
  34. }
  35. type Style uint8
  36. const (
  37. StyleNormal Style = Style(font.StyleNormal)
  38. StyleItalic Style = Style(font.StyleItalic)
  39. )
  40. type Weight float32
  41. const (
  42. WeightThin Weight = Weight(font.WeightThin)
  43. WeightExtraLight Weight = Weight(font.WeightExtraLight)
  44. WeightLight Weight = Weight(font.WeightLight)
  45. WeightNormal Weight = Weight(font.WeightNormal)
  46. WeightMedium Weight = Weight(font.WeightMedium)
  47. WeightSemibold Weight = Weight(font.WeightSemibold)
  48. WeightBold Weight = Weight(font.WeightBold)
  49. WeightExtraBold Weight = Weight(font.WeightExtraBold)
  50. WeightBlack Weight = Weight(font.WeightBlack)
  51. )
  52. type Stretch float32
  53. const (
  54. StretchUltraCondensed Stretch = Stretch(font.StretchUltraCondensed)
  55. StretchExtraCondensed Stretch = Stretch(font.StretchExtraCondensed)
  56. StretchCondensed Stretch = Stretch(font.StretchCondensed)
  57. StretchSemiCondensed Stretch = Stretch(font.StretchSemiCondensed)
  58. StretchNormal Stretch = Stretch(font.StretchNormal)
  59. StretchSemiExpanded Stretch = Stretch(font.StretchSemiExpanded)
  60. StretchExpanded Stretch = Stretch(font.StretchExpanded)
  61. StretchExtraExpanded Stretch = Stretch(font.StretchExtraExpanded)
  62. StretchUltraExpanded Stretch = Stretch(font.StretchUltraExpanded)
  63. )