Fix more of the text output code (paren handling).

Update unit tests to write lines from README.md.
This commit is contained in:
Michael R Sweet 2021-05-31 21:34:53 -04:00
parent 05df5919cd
commit cc250e7201
No known key found for this signature in database
GPG Key ID: 999559A027815955
2 changed files with 19 additions and 12 deletions

View File

@ -1462,7 +1462,6 @@ write_string(pdfio_stream_t *st, // I - Stream
{
// ASCII string...
const char *start = s; // Start of fragment
int level = 0; // Paren level
if (!pdfioStreamPuts(st, "("))
return (false);
@ -1500,16 +1499,16 @@ write_string(pdfio_stream_t *st, // I - Stream
ptr ++;
start = ptr + 1;
}
else if (*ptr == '\\' || (*ptr == ')' && level == 0) || *ptr < ' ')
else if (*ptr == '\\' || *ptr == '(' || *ptr == ')' || *ptr < ' ')
{
if (ptr > start)
{
if (!pdfioStreamWrite(st, start, (size_t)(ptr - start)))
return (false);
start = ptr + 1;
}
start = ptr + 1;
if (*ptr < ' ')
{
if (!pdfioStreamPrintf(st, "\\%03o", *ptr))
@ -1518,10 +1517,6 @@ write_string(pdfio_stream_t *st, // I - Stream
else if (!pdfioStreamPrintf(st, "\\%c", *ptr))
return (false);
}
else if (*ptr == '(')
level ++;
else if (*ptr == ')')
level --;
}
if (ptr > start)

View File

@ -987,8 +987,20 @@ write_text(pdfio_file_t *pdf, // I - PDF file
else
return (1);
fputs("pdfioContentTextMoveTo(550.0, 36.0): ", stdout);
if (pdfioContentTextMoveTo(st, 550.0, 36.0))
fputs("pdfioContentTextMoveTo(36.0, 36.0): ", stdout);
if (pdfioContentTextMoveTo(st, 36, 36.0))
puts("PASS");
else
return (1);
printf("pdfioContentTextShowf(\"\\\"%s\\\"\"): ", filename);
if (pdfioContentTextShowf(st, "\"%s\"", filename))
puts("PASS");
else
return (1);
fputs("pdfioContentTextMoveTo(514.0, 0.0): ", stdout);
if (pdfioContentTextMoveTo(st, 514.0, 0.0))
puts("PASS");
else
return (1);
@ -1026,8 +1038,8 @@ write_text(pdfio_file_t *pdf, // I - PDF file
else
return (1);
fputs("pdfioContentTextMoveTo(36.0, 746.0): ", stdout);
if (pdfioContentTextMoveTo(st, 36.0, 746.0))
fputs("pdfioContentTextMoveTo(36.0, 756.0): ", stdout);
if (pdfioContentTextMoveTo(st, 36.0, 756.0))
puts("PASS");
else
return (1);