• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sile-typesetter / sile / 9307175333

30 May 2024 06:08PM UTC coverage: 70.644% (-3.5%) from 74.124%
9307175333

push

github

web-flow
Merge b18390e74 into 70ff5c335

1910 of 2592 new or added lines in 108 files covered. (73.69%)

901 existing lines in 52 files now uncovered.

12203 of 17274 relevant lines covered (70.64%)

6112.16 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/shapers/pango.lua
1
-- This shaper package is deprecated and should only be used as an
2
-- example of how to create alternative shaper backends, in comparison
3
-- with the harfbuzz shaper.
4
local lgi = require("lgi")
×
5
require("string")
×
6
local pangolgi = lgi.Pango
×
7
local fm = lgi.PangoCairo.FontMap.get_default()
×
8
local pango_context = lgi.Pango.FontMap.create_context(fm)
×
9

10
local base = require("shapers.base")
×
11

12
local palcache = {}
×
13

14
local function _shape (text, item)
15
   local offset = item.offset
×
16
   local length = item.length
×
17
   local analysis = item.analysis
×
18
   local pgs = pangolgi.GlyphString.new()
×
19
   pangolgi.shape(string.sub(text, 1 + offset), length, analysis, pgs)
×
20
   return pgs
×
21
end
22

23
local shaper = pl.class(base)
×
24
shaper._name = "pango"
×
25

26
-- TODO: refactor so method accepts self
27
function shaper.getFace (options)
×
28
   local pal
29
   if options.pal then
×
30
      return options.pal
×
31
   end
32
   local p = pl.pretty.write(options, "")
×
33
   if palcache[p] then
×
34
      return palcache[p]
×
35
   else
36
      pal = pangolgi.AttrList.new()
×
37
      if options.language then
×
38
         pal:insert(pangolgi.Attribute.language_new(pangolgi.Language.from_string(options.language)))
×
39
      end
40
      if options.font then
×
41
         pal:insert(pangolgi.Attribute.family_new(options.font))
×
42
      end
43
      if options.weight then
×
44
         pal:insert(pangolgi.Attribute.weight_new(tonumber(options.weight)))
×
45
      end
46
      if options.size then
×
47
         pal:insert(pangolgi.Attribute.size_new(options.size * 1024 * 0.75))
×
48
      end -- I don't know why 0.75
49
      if options.style then
×
50
         pal:insert(
×
51
            pangolgi.Attribute.style_new(
×
52
               options.style:lower() == "italic" and pangolgi.Style.ITALIC or pangolgi.Style.NORMAL
×
53
            )
54
         )
55
      end
56
      if options.variant then
×
57
         pal:insert(
×
58
            pangolgi.Attribute.variant_new(
×
59
               options.variant:lower() == "smallcaps" and pangolgi.Variant.SMALL_CAPS or pangolgi.Variant.NORMAL
×
60
            )
61
         )
62
      end
63
   end
64
   if options.language then
×
65
      pango_context:set_language(pangolgi.Language.from_string(options.language))
×
66
   end
67
   palcache[p] = pal
×
68
   return pal
×
69
end
70

71
function shaper:shapeToken (text, options)
×
72
   local pal = SILE.font.cache(options, self.getFace)
×
73
   local rv = {}
×
74
   local items = pangolgi.itemize(pango_context, text, 0, string.len(text), pal, nil)
×
NEW
75
   local twidth = SILE.types.length()
×
76
   for i = 1, #items do
×
77
      local item = items[i]
×
78
      local pgs = _shape(text, item)
×
79
      -- local text = string.sub(text,1+items[i].offset, items[i].length)
80
      -- local depth, height = 0,0
81
      local font = items[i].analysis.font
×
82
      twidth = twidth + pgs:get_width() / 1024
×
83
      for g in pairs(pgs.glyphs) do
×
84
         local rect = font:get_glyph_extents(pgs.glyphs[g].glyph)
×
85
         table.insert(rv, {
×
86
            height = -rect.y / 1024,
87
            depth = (rect.y + rect.height) / 1024,
88
            width = rect.width / 1024,
89
            glyph = pgs.glyphs[g].glyph,
90
            pgs = pgs,
91
            font = font,
92
            -- text = text
93
         })
94
      end
95
   end
96
   return rv, twidth
×
97
end
98

99
function shaper.addShapedGlyphToNnodeValue (_, nnodevalue, shapedglyph)
×
100
   nnodevalue.pgs = shapedglyph.pgs
×
101
   nnodevalue.font = shapedglyph.font
×
102
end
103

104
return shaper
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc