mirror of
https://github.com/michaelrsweet/pdfio.git
synced 2024-12-26 13:28:22 +01:00
Compare commits
3 Commits
a1237db52c
...
52b508bdd2
Author | SHA1 | Date | |
---|---|---|---|
|
52b508bdd2 | ||
|
41ebe39f3b | ||
|
62df5f5c78 |
928
doc/pdfio.md
928
doc/pdfio.md
File diff suppressed because it is too large
Load Diff
@ -209,6 +209,11 @@ static const char * const docfont_names[] =
|
|||||||
"FM"
|
"FM"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define BQ_PADDING 18.0 // Padding for block quotes
|
||||||
|
#define BQ_THICKNESS 3.0 // Thickness of block quote bar
|
||||||
|
|
||||||
|
#define CODE_PADDING 4.5 // Padding for code blocks
|
||||||
|
|
||||||
#define IMAGE_PPI 100.0 // Pixels per inch for images
|
#define IMAGE_PPI 100.0 // Pixels per inch for images
|
||||||
|
|
||||||
#define LINE_HEIGHT 1.4 // Multiplier for line height
|
#define LINE_HEIGHT 1.4 // Multiplier for line height
|
||||||
@ -670,12 +675,8 @@ format_block(docdata_t *dd, // I - Document data
|
|||||||
{
|
{
|
||||||
// Add an orange bar to the left of block quotes...
|
// Add an orange bar to the left of block quotes...
|
||||||
set_color(dd, DOCCOLOR_ORANGE);
|
set_color(dd, DOCCOLOR_ORANGE);
|
||||||
pdfioContentSave(dd->st);
|
pdfioContentPathRect(dd->st, left - BQ_PADDING, dd->y - (LINE_HEIGHT - 1.0) * fsize - BQ_THICKNESS, BQ_THICKNESS, lineheight + 2.0 * BQ_THICKNESS);
|
||||||
pdfioContentSetLineWidth(dd->st, 3.0);
|
pdfioContentFill(dd->st, /*even_odd*/false);
|
||||||
pdfioContentPathMoveTo(dd->st, left - 6.0, dd->y - (LINE_HEIGHT - 1.0) * fsize);
|
|
||||||
pdfioContentPathLineTo(dd->st, left - 6.0, dd->y + fsize);
|
|
||||||
pdfioContentStroke(dd->st);
|
|
||||||
pdfioContentRestore(dd->st);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
num_frags = 0;
|
num_frags = 0;
|
||||||
@ -827,18 +828,23 @@ format_code(docdata_t *dd, // I - Document data
|
|||||||
{
|
{
|
||||||
new_page(dd);
|
new_page(dd);
|
||||||
|
|
||||||
margin_top = (1.0 - LINE_HEIGHT) * lineheight;
|
margin_top = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
dd->y -= lineheight + margin_top;
|
dd->y -= lineheight + margin_top + CODE_PADDING;
|
||||||
|
|
||||||
if ((dd->y - lineheight) < dd->art_box.y1)
|
if ((dd->y - lineheight) < dd->art_box.y1)
|
||||||
{
|
{
|
||||||
new_page(dd);
|
new_page(dd);
|
||||||
|
|
||||||
dd->y -= lineheight / LINE_HEIGHT;
|
dd->y -= lineheight + CODE_PADDING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw the top padding...
|
||||||
|
set_color(dd, DOCCOLOR_LTGRAY);
|
||||||
|
pdfioContentPathRect(dd->st, left - CODE_PADDING, dd->y + SIZE_CODEBLOCK, right - left + 2.0 * CODE_PADDING, CODE_PADDING);
|
||||||
|
pdfioContentFillAndStroke(dd->st, false);
|
||||||
|
|
||||||
// Start a code text block...
|
// Start a code text block...
|
||||||
set_font(dd, DOCFONT_MONOSPACE, SIZE_CODEBLOCK);
|
set_font(dd, DOCFONT_MONOSPACE, SIZE_CODEBLOCK);
|
||||||
pdfioContentTextBegin(dd->st);
|
pdfioContentTextBegin(dd->st);
|
||||||
@ -847,7 +853,7 @@ format_code(docdata_t *dd, // I - Document data
|
|||||||
for (code = mmdGetFirstChild(block); code; code = mmdGetNextSibling(code))
|
for (code = mmdGetFirstChild(block); code; code = mmdGetNextSibling(code))
|
||||||
{
|
{
|
||||||
set_color(dd, DOCCOLOR_LTGRAY);
|
set_color(dd, DOCCOLOR_LTGRAY);
|
||||||
pdfioContentPathRect(dd->st, left - 3.0, dd->y - (LINE_HEIGHT - 1.0) * SIZE_CODEBLOCK, right - left + 6.0, lineheight);
|
pdfioContentPathRect(dd->st, left - CODE_PADDING, dd->y - (LINE_HEIGHT - 1.0) * SIZE_CODEBLOCK, right - left + 2.0 * CODE_PADDING, lineheight);
|
||||||
pdfioContentFillAndStroke(dd->st, false);
|
pdfioContentFillAndStroke(dd->st, false);
|
||||||
|
|
||||||
set_color(dd, DOCCOLOR_RED);
|
set_color(dd, DOCCOLOR_RED);
|
||||||
@ -873,6 +879,11 @@ format_code(docdata_t *dd, // I - Document data
|
|||||||
// End the current text block...
|
// End the current text block...
|
||||||
pdfioContentTextEnd(dd->st);
|
pdfioContentTextEnd(dd->st);
|
||||||
dd->y += lineheight;
|
dd->y += lineheight;
|
||||||
|
|
||||||
|
// Draw the bottom padding...
|
||||||
|
set_color(dd, DOCCOLOR_LTGRAY);
|
||||||
|
pdfioContentPathRect(dd->st, left - CODE_PADDING, dd->y - CODE_PADDING - (LINE_HEIGHT - 1.0) * SIZE_CODEBLOCK, right - left + 2.0 * CODE_PADDING, CODE_PADDING);
|
||||||
|
pdfioContentFillAndStroke(dd->st, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -918,7 +929,7 @@ format_doc(docdata_t *dd, // I - Document data
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case MMD_TYPE_BLOCK_QUOTE :
|
case MMD_TYPE_BLOCK_QUOTE :
|
||||||
format_doc(dd, current, DOCFONT_ITALIC, left + 36.0, right - 36.0);
|
format_doc(dd, current, DOCFONT_ITALIC, left + BQ_PADDING, right - BQ_PADDING);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MMD_TYPE_ORDERED_LIST :
|
case MMD_TYPE_ORDERED_LIST :
|
||||||
@ -998,7 +1009,7 @@ format_doc(docdata_t *dd, // I - Document data
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case MMD_TYPE_CODE_BLOCK :
|
case MMD_TYPE_CODE_BLOCK :
|
||||||
format_code(dd, current, left + 36.0, right - 36.0);
|
format_code(dd, current, left + CODE_PADDING, right - CODE_PADDING);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1474,7 +1485,7 @@ render_line(docdata_t *dd, // I - Document data
|
|||||||
if (!dd->st)
|
if (!dd->st)
|
||||||
{
|
{
|
||||||
new_page(dd);
|
new_page(dd);
|
||||||
margin_top = (1.0 - LINE_HEIGHT) * lineheight;
|
margin_top = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
dd->y -= margin_top + lineheight;
|
dd->y -= margin_top + lineheight;
|
||||||
@ -1482,7 +1493,7 @@ render_line(docdata_t *dd, // I - Document data
|
|||||||
{
|
{
|
||||||
new_page(dd);
|
new_page(dd);
|
||||||
|
|
||||||
dd->y -= lineheight / LINE_HEIGHT;
|
dd->y -= lineheight;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0, frag = frags; i < num_frags; i ++, frag ++)
|
for (i = 0, frag = frags; i < num_frags; i ++, frag ++)
|
||||||
|
@ -1,22 +1,10 @@
|
|||||||
---
|
---
|
||||||
title: Markdown to PDF Converter Example
|
title: Markdown to PDF Converter Test File
|
||||||
...
|
...
|
||||||
|
|
||||||
Markdown to PDF Converter Example
|
|
||||||
=================================
|
|
||||||
|
|
||||||
The `md2pdf` example program reads a markdown file and formats the content onto
|
Markdown to PDF Converter Test File
|
||||||
pages in a PDF file. It demonstrates how to:
|
===================================
|
||||||
|
|
||||||
- Embed base and TrueType fonts,
|
|
||||||
- Format text,
|
|
||||||
- Embed JPEG and PNG images,
|
|
||||||
- Add headers and footers, and
|
|
||||||
- Add hyperlinks.
|
|
||||||
|
|
||||||
|
|
||||||
Source Files
|
|
||||||
------------
|
|
||||||
|
|
||||||
The `md2pdf` program is organized into three source files: `md2pdf.c` which
|
The `md2pdf` program is organized into three source files: `md2pdf.c` which
|
||||||
contains the code to format the markdown content and `mmd.h` and `mmd.c` (from
|
contains the code to format the markdown content and `mmd.h` and `mmd.c` (from
|
||||||
@ -24,4 +12,73 @@ the [Miniature Markdown Library][MMD] project) which load the markdown content.
|
|||||||
|
|
||||||
[MMD]: https://www.msweet.org/mmd/
|
[MMD]: https://www.msweet.org/mmd/
|
||||||
|
|
||||||
|
This is a test file for `md2pdf`. Here is a bullet list:
|
||||||
|
|
||||||
|
- Embed base and TrueType fonts,
|
||||||
|
- Format text with embedded JPEG and PNG images and check boxes, with support
|
||||||
|
for wrapping, alignment in table cells, leader text (as used for lists), and
|
||||||
|
variable line height,
|
||||||
|
- Add headers and footers, and
|
||||||
|
- Add hyperlinks and document platform.
|
||||||
|
|
||||||
|
And here is an ordered list:
|
||||||
|
|
||||||
|
1. Embed base and TrueType fonts,
|
||||||
|
2. Format text with embedded JPEG and PNG images and check boxes, with support
|
||||||
|
for wrapping, alignment in table cells, leader text (as used for lists), and
|
||||||
|
variable line height,
|
||||||
|
3. Add headers and footers, and
|
||||||
|
4. Add hyperlinks and document platform.
|
||||||
|
|
||||||
|
|
||||||
|
Code Blocks
|
||||||
|
-----------
|
||||||
|
|
||||||
|
```
|
||||||
|
0 1 2 3 4 5 6 7 8
|
||||||
|
12345678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Images
|
||||||
|
------
|
||||||
|
|
||||||
|
PDFio book cover image:
|
||||||
|
|
||||||
|
![PDFio](../doc/pdfio-epub.png)
|
||||||
|
|
||||||
|
|
||||||
|
Tables
|
||||||
|
------
|
||||||
|
|
||||||
|
Table with leading/trailing pipes:
|
||||||
|
|
||||||
|
| Heading 1 | Heading 2 | Heading 3 |
|
||||||
|
| --------- | --------- | --------- |
|
||||||
|
| Cell 1,1 | Cell 1,2 | Cell 1,3 |
|
||||||
|
| Cell 2,1 | Cell 2,2 | Cell 2,3 |
|
||||||
|
| Cell 3,1 | Cell 3,2 | Cell 3,3 |
|
||||||
|
|
||||||
|
Table without leading/trailing pipes:
|
||||||
|
|
||||||
|
Heading 1 | Heading 2 | Heading 3
|
||||||
|
--------- | --------- | ---------
|
||||||
|
Cell 1,1 | Cell 1,2 | Cell 1,3
|
||||||
|
Cell 2,1 | Cell 2,2 | Cell 2,3
|
||||||
|
Cell 3,1 | Cell 3,2 | Cell 3,3
|
||||||
|
|
||||||
|
Table with alignment:
|
||||||
|
|
||||||
|
Left Alignment | Center Alignment | Right Alignment
|
||||||
|
:-------- | :-------: | --------:
|
||||||
|
Cell 1,1 | Cell 1,2 | 1
|
||||||
|
Cell 2,1 | Cell 2,2 | 12
|
||||||
|
Cell 3,1 | Cell 3,2 | 123
|
||||||
|
|
||||||
|
Table in block quote:
|
||||||
|
|
||||||
|
> Heading 1 | Heading 2 | Heading 3
|
||||||
|
> --------- | --------- | ---------
|
||||||
|
> Cell 1,1 | Cell 1,2 | Cell 1,3
|
||||||
|
> Cell 2,1 | Cell 2,2 | Cell 2,3
|
||||||
|
> Cell 3,1 | Cell 3,2 | Cell 3,3
|
||||||
|
Loading…
Reference in New Issue
Block a user