Skip to content

Commit

Permalink
Use regular font for whitespace before monospace text.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Dec 21, 2024
1 parent a24fdee commit a1237db
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions examples/md2pdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ typedef struct docdata_s // Document formatting data
pdfio_rect_t crop_box; // Crop box (for margins)
pdfio_rect_t art_box; // Art box (for markdown content)
pdfio_obj_t *fonts[DOCFONT_MAX]; // Embedded fonts
double font_space; // Unit width of a space
size_t num_images; // Number of embedded images
docimage_t images[DOCIMAGE_MAX]; // Embedded images
const char *title; // Document title
Expand Down Expand Up @@ -349,6 +350,8 @@ main(int argc, // I - Number of command-line arguments
#endif // USE_TRUETYPE
}

dd.font_space = pdfioContentTextMeasure(dd.fonts[DOCFONT_REGULAR], " ", 1.0);

// Add images...
add_images(&dd, doc);

Expand Down Expand Up @@ -624,7 +627,7 @@ format_block(docdata_t *dd, // I - Document data
imagenum = 0;
url = mmdGetURL(current);
ws = mmdGetWhitespace(current);
wswidth = 0.0;
wswidth = ws ? dd->font_space * fsize : 0.0;
next = mmd_walk_next(block, current);

// Process the node...
Expand Down Expand Up @@ -714,9 +717,6 @@ format_block(docdata_t *dd, // I - Document data

width = pdfioContentTextMeasure(dd->fonts[font], text, fsize);
height = fsize * LINE_HEIGHT;

if (ws)
wswidth = pdfioContentTextMeasure(dd->fonts[font], " ", fsize);
}

// See if this node will fit on the current line...
Expand Down Expand Up @@ -1469,7 +1469,6 @@ render_line(docdata_t *dd, // I - Document data
size_t i; // Looping var
linefrag_t *frag; // Current line fragment
bool in_text = false; // Are we in a text block?
// bool ws_after; // Do we have whitespace after this fragment?


if (!dd->st)
Expand Down Expand Up @@ -1517,9 +1516,6 @@ render_line(docdata_t *dd, // I - Document data
else if (frag->text)
{
// Draw text
set_color(dd, frag->color);
set_font(dd, frag->font, frag->height);

if (!in_text)
{
pdfioContentTextBegin(dd->st);
Expand All @@ -1528,20 +1524,19 @@ render_line(docdata_t *dd, // I - Document data
in_text = true;
}

#if 0
if (frag->font != DOCFONT_MONOSPACE && (i + 1) < num_frags && frag[1].ws && frag[1].font == DOCFONT_MONOSPACE)
{
// Don't use a monospace space to separate it from non-monospace
ws_after = true;
frag[1].ws = false;
}
else
if (frag->ws && frag->font == DOCFONT_MONOSPACE)
{
ws_after = false;
set_font(dd, DOCFONT_REGULAR, frag->height);
pdfioContentTextShow(dd->st, UNICODE_VALUE, " ");
}
#endif // 0

pdfioContentTextShowf(dd->st, UNICODE_VALUE, "%s%s%s", frag->ws ? " " : "", frag->text, /*ws_after ? " " :*/ "");
set_color(dd, frag->color);
set_font(dd, frag->font, frag->height);

if (frag->font == DOCFONT_MONOSPACE)
pdfioContentTextShow(dd->st, UNICODE_VALUE, frag->text);
else
pdfioContentTextShowf(dd->st, UNICODE_VALUE, "%s%s", frag->ws ? " " : "", frag->text);

if (frag->url && dd->num_links < DOCLINK_MAX)
{
Expand Down

0 comments on commit a1237db

Please sign in to comment.