Skip to content

Commit f70582e

Browse files
committed
Reducing bullet indentation and also avoid hardcoded value for
it
1 parent 1ccd3e9 commit f70582e

35 files changed

Lines changed: 190 additions & 187 deletions

mdtopdf.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ type PdfRenderer struct {
130130
Extensions parser.Extensions
131131
ColumnWidths map[ast.Node][]float64
132132

133+
BulletIndentation float64
134+
133135
tocLinks map[string]*int
134136
}
135137

@@ -372,6 +374,7 @@ func NewPdfRenderer(params PdfRendererParams) *PdfRenderer {
372374
r.Theme = params.Theme
373375

374376
r.Pdf = fpdf.New(r.orientation, r.units, r.papersize, r.fontdir)
377+
r.BulletIndentation = 0.1
375378

376379
r.Pdf.SetHeaderFunc(func() {
377380
r.SetPageBackground("", r.BackgroundColor)
@@ -392,7 +395,7 @@ func NewPdfRenderer(params PdfRendererParams) *PdfRenderer {
392395
r.setStyler(r.Normal)
393396
r.mleft, r.mtop, r.mright, r.mbottom = r.Pdf.GetMargins()
394397
r.em = r.Pdf.GetStringWidth("m")
395-
r.IndentValue = 3 * r.em
398+
r.IndentValue = 2.5 * r.em
396399

397400
r.cs = states{stack: make([]*containerState, 0)}
398401
initcurrent := &containerState{

nodeProcessing.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,19 +259,19 @@ func (r *PdfRenderer) processItem(node ast.ListItem, entering bool) {
259259
bulletChar = tr("▪")
260260
r.Pdf.SetFont("", "", 25)
261261
}
262-
r.Pdf.CellFormat(4*r.em, r.Normal.Size+r.Normal.Spacing,
262+
r.Pdf.CellFormat(r.BulletIndentation * r.em, r.Normal.Size+r.Normal.Spacing,
263263
bulletChar,
264264
"", 0, "RB", false, 0, "")
265265
r.Pdf.SetFont("", "", currFontSize)
266266
} else if r.cs.peek().listkind == ordered {
267-
r.Pdf.CellFormat(4*r.em, r.Normal.Size+r.Normal.Spacing,
267+
r.Pdf.CellFormat(r.BulletIndentation * r.em, r.Normal.Size+r.Normal.Spacing,
268268
fmt.Sprintf("%v.", r.cs.peek().itemNumber),
269269
"", 0, "RB", false, 0, "")
270270
}
271271
// with the bullet done, now set the left margin for the text
272-
r.Pdf.SetLeftMargin(r.cs.peek().leftMargin + (4 * r.em))
272+
r.Pdf.SetLeftMargin(r.cs.peek().leftMargin + (r.BulletIndentation * r.em))
273273
// set the cursor to this point
274-
r.Pdf.SetX(r.cs.peek().leftMargin + (4 * r.em))
274+
r.Pdf.SetX(r.cs.peek().leftMargin + (r.BulletIndentation * r.em))
275275
} else {
276276
r.tracer(fmt.Sprintf("%v Item (leaving)",
277277
r.cs.peek().listkind),
0 Bytes
Binary file not shown.

testdata/Auto links.log

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@
3535
Paragraph
3636
Text 'It should.'
3737

38-
[... List Left Margin] set to 58.338
38+
[... List Left Margin] set to 53.34
3939
-[Unordered Item (entering) #1] Container
4040
Paragraph
4141
Text 'In a list?'
4242

4343
-[cr()] LH=14
4444
--[Paragraph (entering)]
45-
--[... Margins (left, top, right, bottom:] 98.322 28.35 28.35 56.7
45+
--[... Margins (left, top, right, bottom:] 54.339600000000004 28.35 28.35 56.7
4646
--[First Para within a list] breaking
4747
--[Text] In a list?
4848
--[Paragraph (leaving)]
49-
--[... Margins (left, top, right, bottom:] 98.322 28.35 28.35 56.7
49+
--[... Margins (left, top, right, bottom:] 54.339600000000004 28.35 28.35 56.7
5050
--[Unordered Item (leaving)] Container
5151
Paragraph
5252
Text 'In a list?'
@@ -60,15 +60,15 @@
6060

6161
-[cr()] LH=14
6262
--[Paragraph (entering)]
63-
--[... Margins (left, top, right, bottom:] 98.322 28.35 28.35 56.7
63+
--[... Margins (left, top, right, bottom:] 54.339600000000004 28.35 28.35 56.7
6464
--[First Para within a list] breaking
6565
--[Text]
6666
---[Link (entering)] Destination[http://example.com/] Title[]
6767
---[Text] http://example.com/
6868
---[Link (leaving)]
6969
--[Text]
7070
--[Paragraph (leaving)]
71-
--[... Margins (left, top, right, bottom:] 98.322 28.35 28.35 56.7
71+
--[... Margins (left, top, right, bottom:] 54.339600000000004 28.35 28.35 56.7
7272
--[Unordered Item (leaving)] Container
7373
Paragraph
7474
Text
@@ -82,11 +82,11 @@
8282

8383
-[cr()] LH=14
8484
--[Paragraph (entering)]
85-
--[... Margins (left, top, right, bottom:] 98.322 28.35 28.35 56.7
85+
--[... Margins (left, top, right, bottom:] 54.339600000000004 28.35 28.35 56.7
8686
--[First Para within a list] breaking
8787
--[Text] It should.
8888
--[Paragraph (leaving)]
89-
--[... Margins (left, top, right, bottom:] 98.322 28.35 28.35 56.7
89+
--[... Margins (left, top, right, bottom:] 54.339600000000004 28.35 28.35 56.7
9090
--[Unordered Item (leaving)] Container
9191
Paragraph
9292
Text 'It should.'
@@ -109,14 +109,14 @@
109109
[cr()] LH=14
110110
[BlockQuote (entering)]
111111
-[Paragraph (entering)]
112-
-[... Margins (left, top, right, bottom:] 58.338 28.35 28.35 56.7
112+
-[... Margins (left, top, right, bottom:] 53.34 28.35 28.35 56.7
113113
-[cr()] LH=14
114114
-[Text] Blockquoted:
115115
--[Link (entering)] Destination[http://example.com/] Title[]
116116
--[Text] http://example.com/
117117
--[Link (leaving)]
118118
-[Paragraph (leaving)]
119-
-[... Margins (left, top, right, bottom:] 58.338 28.35 28.35 56.7
119+
-[... Margins (left, top, right, bottom:] 53.34 28.35 28.35 56.7
120120
-[cr()] LH=14
121121
-[BlockQuote (leaving)]
122122
[cr()] LH=14

testdata/Auto links.pdf

-3 Bytes
Binary file not shown.

testdata/Backslash escapes.pdf

0 Bytes
Binary file not shown.

testdata/Blockquotes with code blocks.log

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
[Document] Not Handled
33
[BlockQuote (entering)]
44
-[Paragraph (entering)]
5-
-[... Margins (left, top, right, bottom:] 58.338 28.35 28.35 56.7
5+
-[... Margins (left, top, right, bottom:] 53.34 28.35 28.35 56.7
66
-[cr()] LH=14
77
-[Text] Example:
88
-[Paragraph (leaving)]
9-
-[... Margins (left, top, right, bottom:] 58.338 28.35 28.35 56.7
9+
-[... Margins (left, top, right, bottom:] 53.34 28.35 28.35 56.7
1010
-[cr()] LH=14
1111
-[Codeblock] Leaf 'sub status {\n print "working";\n}\n'
1212

1313
-[cr()] LH=14
1414
-[Paragraph (entering)]
15-
-[... Margins (left, top, right, bottom:] 58.338 28.35 28.35 56.7
15+
-[... Margins (left, top, right, bottom:] 53.34 28.35 28.35 56.7
1616
-[cr()] LH=14
1717
-[Text] Or:
1818
-[Paragraph (leaving)]
19-
-[... Margins (left, top, right, bottom:] 58.338 28.35 28.35 56.7
19+
-[... Margins (left, top, right, bottom:] 53.34 28.35 28.35 56.7
2020
-[cr()] LH=14
2121
-[Codeblock] Leaf 'sub status {\n return "working";\n…'
2222

0 Bytes
Binary file not shown.

testdata/Code Blocks.pdf

0 Bytes
Binary file not shown.

testdata/Code Spans.pdf

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)