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

sile-typesetter / sile / 6713098919

31 Oct 2023 10:21PM UTC coverage: 52.831% (-21.8%) from 74.636%
6713098919

push

github

web-flow
Merge d0a2a1ee9 into b185d4972

45 of 45 new or added lines in 3 files covered. (100.0%)

8173 of 15470 relevant lines covered (52.83%)

6562.28 hits per line

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

0.0
/packages/hanmenkyoshi/init.lua
1
local base = require("packages.base")
×
2

3
local package = pl.class(base)
×
4
package._name = "hanmenkyoshi"
×
5

6
local showHanmenYoko = function (frame)
7
  local g = frame:top()
×
8
  while g < frame:bottom() do
×
9
    SILE.outputter:drawRule(frame:left(), g - 0.25, frame:width(), 0.5)
×
10
    local l = frame:left()
×
11
    while l <= frame:right() do
×
12
      SILE.outputter:drawRule(l-0.25, g + frame.hanmen.gridsize - 0.25, 0.5, -frame.hanmen.gridsize)
×
13
      l = l + frame.hanmen.gridsize
×
14
    end
15
    g = g + frame.hanmen.gridsize
×
16
    SILE.outputter:drawRule(frame:left(), g - 0.25, frame:width(), 0.5)
×
17
    g = g + frame.hanmen.linegap
×
18
  end
19
end
20

21
local showHanmenTate = function (frame)
22
  local g = frame:right()
×
23
  while g > frame:left() do
×
24
    SILE.outputter:drawRule( g - 0.25, frame:top(), 0.5, -frame:height())
×
25
    local l = frame:top()
×
26
    while l < frame:bottom() do
×
27
      SILE.outputter:drawRule(g - frame.hanmen.gridsize - 0.25, l-0.25, frame.hanmen.gridsize, 0.5)
×
28
      l = l + frame.hanmen.gridsize
×
29
    end
30
    g = g - frame.hanmen.gridsize
×
31
    SILE.outputter:drawRule( g - 0.25, frame:top(), 0.5, -frame:height())
×
32
    g = g - frame.hanmen.linegap
×
33
  end
34
end
35

36
-- Warning: this function has side affects and if a real frame is
37
-- passed as a spec it will be modified in addition to a frame
38
-- being instantiated in the class page template.
39
local declareHanmenFrame = function (class, id, spec)
40
  if spec then
×
41
    spec.id = id
×
42
  else
43
    spec = id
×
44
  end
45
  spec.hanmen = {
×
46
    gridsize = SU.required(spec, "gridsize", "declaring the kihonhanmen", "measurement"),
47
    linegap = SU.required(spec, "linegap", "declaring the kihonhanmen", "measurement"),
48
    linelength = SU.required(spec, "linelength", "declaring the kihonhanmen", "measurement"),
49
    linecount = SU.required(spec, "linecount", "declaring the kihonhanmen")
×
50
  }
51
  if spec.tate then
×
52
    spec.height = spec.hanmen.gridsize * spec.hanmen.linelength
×
53
    spec.width = spec.hanmen.gridsize * spec.hanmen.linecount +
×
54
                  spec.hanmen.linegap * ( spec.hanmen.linecount -1 )
×
55
  else
56
    spec.width = spec.hanmen.gridsize * spec.hanmen.linelength
×
57
    spec.height = spec.hanmen.gridsize * spec.hanmen.linecount +
×
58
                  spec.hanmen.linegap * ( spec.hanmen.linecount -1 )
×
59
  end
60
  local skip = spec.hanmen.linegap + spec.hanmen.gridsize
×
61
  SILE.settings:set("document.baselineskip", SILE.nodefactory.vglue(skip))
×
62
  SILE.settings:set("document.parskip", SILE.nodefactory.vglue())
×
63
  local frame = SILE.newFrame(spec, spec.tate and SILE.tateFramePrototype or SILE.framePrototype)
×
64
  if spec.id then
×
65
    class.pageTemplate.frames[spec.id] = frame
×
66
  end
67
end
68

69
function package:_init ()
×
70
  base._init(self)
×
71
  self:loadPackage("tate")
×
72
  self:export("declareHanmenFrame", declareHanmenFrame)
×
73
end
74

75
function package:registerCommands ()
×
76

77
  self:registerCommand("show-hanmen", function (_, _)
×
78
    local frame = SILE.typesetter.frame
×
79
    if not frame.hanmen then
×
80
      SU.error("show-hanmen called on a frame with no hanmen")
×
81
    end
82
    SILE.outputter:pushColor({r = 1, g= 0.9, b = 0.9 })
×
83
    if frame:writingDirection() == "TTB" then
×
84
      showHanmenTate(frame)
×
85
    else
86
      showHanmenYoko(frame)
×
87
    end
88
    SILE.outputter:popColor()
×
89
  end)
90

91
end
92

93
package.documentation = [[
94
\begin{document}
95
Japanese documents are traditionally typeset on a grid layout called a \em{hanmen}, with each character essentially monospaced inside the grid (like writing on graph paper).
96
The \autodoc:package{hanmenkyoshi} package provides tools to Japanese class designers for creating \em{hanmen} frames with correctly spaced grids.
97
It also provides the \autodoc:command{\show-hanmen} command for debugging the grid.
98

99
The name \em{hanmenkyoshi} is a terrible pun.
100
\end{document}
101
]]
×
102

103
return package
×
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

© 2025 Coveralls, Inc