Compare commits

..

4 Commits

Author SHA1 Message Date
Michael R Sweet
d4e3bbcf16
Doco updates. 2024-12-15 11:28:09 -05:00
Michael R Sweet
2c8a996875
Add green bar next to block quote text (for notes). 2024-12-15 11:27:32 -05:00
Michael R Sweet
3d6d9e3e3e
Fix name of ZapfDingbats. 2024-12-15 11:27:18 -05:00
Michael R Sweet
62fdf48ff9
Fix links for code text, background of code blocks. 2024-12-15 11:00:30 -05:00
4 changed files with 92 additions and 32 deletions

View File

@ -465,7 +465,9 @@ You create a new PDF file using the [`pdfioFileCreate`](@@) function:
pdfio_rect_t media_box = { 0.0, 0.0, 612.0, 792.0 }; // US Letter
pdfio_rect_t crop_box = { 36.0, 36.0, 576.0, 756.0 }; // w/0.5" margins
pdfio_file_t *pdf = pdfioFileCreate("myoutputfile.pdf", "2.0", &media_box, &crop_box, error_cb, error_data);
pdfio_file_t *pdf = pdfioFileCreate("myoutputfile.pdf", "2.0",
&media_box, &crop_box,
error_cb, error_data);
```
where the six arguments to the function are the filename ("myoutputfile.pdf"),
@ -481,7 +483,9 @@ function:
pdfio_rect_t media_box = { 0.0, 0.0, 612.0, 792.0 }; // US Letter
pdfio_rect_t crop_box = { 36.0, 36.0, 576.0, 756.0 }; // w/0.5" margins
pdfio_file_t *pdf = pdfioFileCreateOutput(output_cb, output_ctx, "2.0", &media_box, &crop_box, error_cb, error_data);
pdfio_file_t *pdf = pdfioFileCreateOutput(output_cb, output_ctx, "2.0",
&media_box, &crop_box,
error_cb, error_data);
```
Once the file is created, use the [`pdfioFileCreateObj`](@@),
@ -638,13 +642,16 @@ spaces:
pdfio_file_t *pdf = pdfioFileCreate(...);
// Create an AdobeRGB color array
pdfio_array_t *adobe_rgb = pdfioArrayCreateColorFromStandard(pdf, 3, PDFIO_CS_ADOBE);
pdfio_array_t *adobe_rgb =
pdfioArrayCreateColorFromStandard(pdf, 3, PDFIO_CS_ADOBE);
// Create an Display P3 color array
pdfio_array_t *display_p3 = pdfioArrayCreateColorFromStandard(pdf, 3, PDFIO_CS_P3_D65);
pdfio_array_t *display_p3 =
pdfioArrayCreateColorFromStandard(pdf, 3, PDFIO_CS_P3_D65);
// Create an sRGB color array
pdfio_array_t *srgb = pdfioArrayCreateColorFromStandard(pdf, 3, PDFIO_CS_SRGB);
pdfio_array_t *srgb =
pdfioArrayCreateColorFromStandard(pdf, 3, PDFIO_CS_SRGB);
```
@ -670,6 +677,7 @@ font object for one of the base PDF fonts:
- "Times-Roman"
- "ZapfDingbats"
Except for Symbol and ZapfDingbats (which use a custom 8-bit character set),
PDFio always uses the Windows CP1252 subset of Unicode for these fonts.
The second function is [`pdfioFileCreateFontObjFromFile`](@@) which creates a
@ -677,7 +685,8 @@ font object from a TrueType/OpenType font file, for example:
```c
pdfio_file_t *pdf = pdfioFileCreate(...);
pdfio_obj_t *arial = pdfioFileCreateFontObjFromFile(pdf, "OpenSans-Regular.ttf", false);
pdfio_obj_t *arial =
pdfioFileCreateFontObjFromFile(pdf, "OpenSans-Regular.ttf", false);
```
will embed an OpenSans Regular TrueType font using the Windows CP1252 subset of
@ -686,12 +695,16 @@ instead, for example:
```c
pdfio_file_t *pdf = pdfioFileCreate(...);
pdfio_obj_t *arial = pdfioFileCreateFontObjFromFile(pdf, "NotoSansJP-Regular.otf", true);
pdfio_obj_t *arial =
pdfioFileCreateFontObjFromFile(pdf, "NotoSansJP-Regular.otf", true);
```
will embed the NotoSansJP Regular OpenType font with full support for Unicode.
> Note: Not all fonts support Unicode.
> Note: Not all fonts support Unicode, and most do not contain a full
> complement of Unicode characters. `pdfioFileCreateFontObjFromFile` does not
> perform any character subsetting, so the entire font file is embedded in the
> PDF file.
### Image Object Functions
@ -705,7 +718,11 @@ in memory, for example:
```c
pdfio_file_t *pdf = pdfioFileCreate(...);
unsigned char data[1024 * 1024 * 4]; // 1024x1024 RGBA image data
pdfio_obj_t *img = pdfioFileCreateImageObjFromData(pdf, data, /*width*/1024, /*height*/1024, /*num_colors*/3, /*color_data*/NULL, /*alpha*/true, /*interpolate*/false);
pdfio_obj_t *img =
pdfioFileCreateImageObjFromData(pdf, data, /*width*/1024,
/*height*/1024, /*num_colors*/3,
/*color_data*/NULL, /*alpha*/true,
/*interpolate*/false);
```
will create an object for a 1024x1024 RGBA image in memory, using the default
@ -717,11 +734,19 @@ example:
pdfio_file_t *pdf = pdfioFileCreate(...);
// Create an AdobeRGB color array
pdfio_array_t *adobe_rgb = pdfioArrayCreateColorFromMatrix(pdf, 3, pdfioAdobeRGBGamma, pdfioAdobeRGBMatrix, pdfioAdobeRGBWhitePoint);
pdfio_array_t *adobe_rgb =
pdfioArrayCreateColorFromMatrix(pdf, 3, pdfioAdobeRGBGamma,
pdfioAdobeRGBMatrix,
pdfioAdobeRGBWhitePoint);
// Create a 1024x1024 RGBA image using AdobeRGB
unsigned char data[1024 * 1024 * 4]; // 1024x1024 RGBA image data
pdfio_obj_t *img = pdfioFileCreateImageObjFromData(pdf, data, /*width*/1024, /*height*/1024, /*num_colors*/3, /*color_data*/adobe_rgb, /*alpha*/true, /*interpolate*/false);
pdfio_obj_t *img =
pdfioFileCreateImageObjFromData(pdf, data, /*width*/1024,
/*height*/1024, /*num_colors*/3,
/*color_data*/adobe_rgb,
/*alpha*/true,
/*interpolate*/false);
```
The "interpolate" argument specifies whether the colors in the image should be
@ -733,7 +758,9 @@ function to copy the image into a PDF image object, for example:
```c
pdfio_file_t *pdf = pdfioFileCreate(...);
pdfio_obj_t *img = pdfioFileCreateImageObjFromFile(pdf, "myphoto.jpg", /*interpolate*/true);
pdfio_obj_t *img =
pdfioFileCreateImageObjFromFile(pdf, "myphoto.jpg",
/*interpolate*/true);
```
@ -856,7 +883,9 @@ show_pdf_info(const char *filename)
// Open the PDF file with the default callbacks...
pdf = pdfioFileOpen(filename, /*password_cb*/NULL, /*password_cbdata*/NULL, /*error_cb*/NULL, /*error_cbdata*/NULL);
pdf = pdfioFileOpen(filename, /*password_cb*/NULL,
/*password_cbdata*/NULL, /*error_cb*/NULL,
/*error_cbdata*/NULL);
if (pdf == NULL)
return;
@ -892,7 +921,8 @@ the page with the text centered below:
void
create_pdf_image_file(const char *pdfname, const char *imagename, const char *caption)
create_pdf_image_file(const char *pdfname, const char *imagename,
const char *caption)
{
pdfio_file_t *pdf;
pdfio_obj_t *font;
@ -905,7 +935,9 @@ create_pdf_image_file(const char *pdfname, const char *imagename, const char *ca
// Create the PDF file...
pdf = pdfioFileCreate(pdfname, /*version*/NULL, /*media_box*/NULL, /*crop_box*/NULL, /*error_cb*/NULL, /*error_cbdata*/NULL);
pdf = pdfioFileCreate(pdfname, /*version*/NULL, /*media_box*/NULL,
/*crop_box*/NULL, /*error_cb*/NULL,
/*error_cbdata*/NULL);
// Create a Courier base font for the caption
font = pdfioFileCreateFontObjFromBase(pdf, "Courier");
@ -925,9 +957,9 @@ create_pdf_image_file(const char *pdfname, const char *imagename, const char *ca
width = pdfioImageGetWidth(image);
height = pdfioImageGetHeight(image);
// Default media_box is "universal" 595.28x792 points (8.27x11in or 210x279mm)
// Use margins of 36 points (0.5in or 12.7mm) with another 36 points for the
// caption underneath...
// Default media_box is "universal" 595.28x792 points (8.27x11in or
// 210x279mm). Use margins of 36 points (0.5in or 12.7mm) with another
// 36 points for the caption underneath...
swidth = 595.28 - 72.0;
sheight = swidth * height / width;
if (sheight > (792.0 - 36.0 - 72.0))
@ -944,8 +976,8 @@ create_pdf_image_file(const char *pdfname, const char *imagename, const char *ca
// Draw the caption in black...
pdfioContentSetFillColorDeviceGray(page, 0.0);
// Compute the starting point for the text - Courier is monospaced with a
// nominal width of 0.6 times the text height...
// Compute the starting point for the text - Courier is monospaced
// with a nominal width of 0.6 times the text height...
tx = 0.5 * (595.28 - 18.0 * 0.6 * strlen(caption));
// Position and draw the caption underneath...

View File

@ -231,7 +231,7 @@ static void add_links(docdata_t *dd);
static pdfio_obj_t *find_image(docdata_t *dd, const char *url, size_t *imagenum);
static void format_block(docdata_t *dd, mmd_t *block, docfont_t deffont, double fsize, double left, double right, const char *leader);
static void format_code(docdata_t *dd, mmd_t *block, double left, double right);
static void format_doc(docdata_t *dd, mmd_t *doc, double left, double right);
static void format_doc(docdata_t *dd, mmd_t *doc, docfont_t deffont, double left, double right);
static void format_table(docdata_t *dd, mmd_t *table, double left, double right);
static void make_target_name(char *dst, const char *src, size_t dstsize);
static double measure_cell(docdata_t *dd, mmd_t *cell, tablecol_t *col);
@ -327,7 +327,7 @@ main(int argc, // I - Number of command-line arguments
add_images(&dd, doc);
// Parse the markdown document...
format_doc(&dd, doc, dd.art_box.x1, dd.art_box.x2);
format_doc(&dd, doc, DOCFONT_REGULAR, dd.art_box.x1, dd.art_box.x2);
// Close the PDF and return...
if (dd.st)
@ -622,6 +622,15 @@ format_block(docdata_t *dd, // I - Document data
render_line(dd, margin_left, margin_top, lineheight, num_frags, frags);
if (deffont == DOCFONT_ITALIC)
{
// Add a gray bar to the left of block quotes...
set_color(dd, DOCCOLOR_GREEN);
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);
}
num_frags = 0;
frag = frags;
x = left;
@ -678,6 +687,15 @@ format_block(docdata_t *dd, // I - Document data
render_line(dd, margin_left, margin_top, lineheight, num_frags, frags);
if (deffont == DOCFONT_ITALIC)
{
// Add a gray bar to the left of block quotes...
set_color(dd, DOCCOLOR_GREEN);
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);
}
num_frags = 0;
frag = frags;
x = left;
@ -720,6 +738,15 @@ format_block(docdata_t *dd, // I - Document data
margin_left = 0.0;
render_line(dd, margin_left, margin_top, lineheight, num_frags, frags);
if (deffont == DOCFONT_ITALIC)
{
// Add a gray bar to the left of block quotes...
set_color(dd, DOCCOLOR_GREEN);
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);
}
}
}
@ -759,7 +786,7 @@ format_code(docdata_t *dd, // I - Document data
for (code = mmdGetFirstChild(block); code; code = mmdGetNextSibling(code))
{
set_color(dd, DOCCOLOR_LTGRAY);
pdfioContentPathRect(dd->st, left - 3.0, dd->y - (LINE_HEIGHT - 1.0) * SIZE_CODEBLOCK, right - left + 3.0, lineheight);
pdfioContentPathRect(dd->st, left - 3.0, dd->y - (LINE_HEIGHT - 1.0) * SIZE_CODEBLOCK, right - left + 6.0, lineheight);
pdfioContentFillAndStroke(dd->st, false);
set_color(dd, DOCCOLOR_RED);
@ -794,6 +821,7 @@ format_code(docdata_t *dd, // I - Document data
static void
format_doc(docdata_t *dd, // I - Document data
mmd_t *doc, // I - Document node to format
docfont_t deffont, // I - Default font
double left, // I - Left margin
double right) // I - Right margin
{
@ -823,7 +851,7 @@ format_doc(docdata_t *dd, // I - Document data
break;
case MMD_TYPE_BLOCK_QUOTE :
format_doc(dd, current, left + 36.0, right - 36.0);
format_doc(dd, current, DOCFONT_ITALIC, left + 36.0, right - 36.0);
break;
case MMD_TYPE_ORDERED_LIST :
@ -831,18 +859,18 @@ format_doc(docdata_t *dd, // I - Document data
if (dd->st)
dd->y -= SIZE_BODY * LINE_HEIGHT;
format_doc(dd, current, left + 36.0, right);
format_doc(dd, current, deffont, left + 36.0, right);
break;
case MMD_TYPE_LIST_ITEM :
if (doctype == MMD_TYPE_ORDERED_LIST)
{
snprintf(leader, sizeof(leader), "%d. ", i);
format_block(dd, current, DOCFONT_REGULAR, SIZE_BODY, left, right, leader);
format_block(dd, current, deffont, SIZE_BODY, left, right, leader);
}
else
{
format_block(dd, current, DOCFONT_REGULAR, SIZE_BODY, left, right, /*leader*/"");
format_block(dd, current, deffont, SIZE_BODY, left, right, /*leader*/"");
}
break;
@ -873,7 +901,7 @@ format_doc(docdata_t *dd, // I - Document data
break;
case MMD_TYPE_PARAGRAPH :
format_block(dd, current, DOCFONT_REGULAR, SIZE_BODY, left, right, /*leader*/NULL);
format_block(dd, current, deffont, SIZE_BODY, left, right, /*leader*/NULL);
break;
case MMD_TYPE_TABLE :
@ -1414,7 +1442,7 @@ render_line(docdata_t *dd, // I - Document data
else
pdfioContentTextShow(dd->st, UNICODE_VALUE, frag->text);
if (frag->type == MMD_TYPE_LINKED_TEXT && frag->url && dd->num_links < DOCLINK_MAX)
if (frag->url && dd->num_links < DOCLINK_MAX)
{
doclink_t *l = dd->links + dd->num_links;
// Pointer to this link record

View File

@ -284,7 +284,7 @@ static short times_roman_widths[256] =
};
static short zapf_dingbats_widths[256] =
static short zapfdingbats_widths[256] =
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

View File

@ -1171,8 +1171,8 @@ pdfioContentTextMeasure(
widths = times_italic_widths;
else if (!strcmp(basefont, "Times-Roman"))
widths = times_roman_widths;
else if (!strcmp(basefont, "Zapf-Dingbats"))
widths = zapf_dingbats_widths;
else if (!strcmp(basefont, "ZapfDingbats"))
widths = zapfdingbats_widths;
else
return (0.0);