Skip to content

Commit

Permalink
Update pdfioContentSetDashPattern to support setting solid line style…
Browse files Browse the repository at this point in the history
…s (Issue #41)
  • Loading branch information
michaelrsweet committed Oct 6, 2023
1 parent b0e4646 commit 19c4587
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Changes in PDFio
v1.1.2 (TBD)
------------

- Updated `pdfioContentSetDashPattern` to support setting a solid (0 length)
dash pattern (Issue #41)
- Fixed an issue with broken PDF files containing extra CR and/or LF separators
after the object stream token (Issue #40)
- Fixed an issue with PDF files produced by Microsoft Reporting Services
Expand Down
24 changes: 18 additions & 6 deletions doc/pdfio.3
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH pdfio 3 "pdf read/write library" "2022-07-03" "pdf read/write library"
.TH pdfio 3 "pdf read/write library" "2023-10-06" "pdf read/write library"
.SH NAME
pdfio \- pdf read/write library
.SH Introduction
Expand Down Expand Up @@ -34,7 +34,7 @@ PDFio is
.I not
concerned with rendering or viewing a PDF file, although a PDF RIP or viewer could be written using it.
.PP
PDFio is Copyright \[co] 2021\-2022 by Michael R Sweet and is licensed under the Apache License Version 2.0 with an (optional) exception to allow linking against GPL2/LGPL2 software. See the files "LICENSE" and "NOTICE" for more information.
PDFio is Copyright \[co] 2021\-2023 by Michael R Sweet and is licensed under the Apache License Version 2.0 with an (optional) exception to allow linking against GPL2/LGPL2 software. See the files "LICENSE" and "NOTICE" for more information.
.SS Requirements
.PP
PDFio requires the following to build the software:
Expand Down Expand Up @@ -1357,7 +1357,7 @@ bool pdfioContentFillAndStroke (
.fi
.SS pdfioContentMatrixConcat
Concatenate a matrix to the current graphics
state.
state.
.PP
.nf
bool pdfioContentMatrixConcat (
Expand Down Expand Up @@ -1507,6 +1507,9 @@ bool pdfioContentSetDashPattern (
double off
);
.fi
.PP
This function sets the stroke pattern when drawing lines. If "on" and "off"
are 0, a solid line is drawn.
.SS pdfioContentSetFillColorDeviceCMYK
Set device CMYK fill color.
.PP
Expand Down Expand Up @@ -1981,6 +1984,7 @@ function "cb":
}

.fi

The iteration continues as long as the callback returns \fBtrue\fR or all keys
have been iterated.
.SS pdfioDictSetArray
Expand Down Expand Up @@ -2305,10 +2309,11 @@ written:
ssize_t
output_cb(void *output_ctx, const void *buffer, size_t bytes)
{
// Write buffer to output and return the number of bytes written
// Write buffer to output and return the number of bytes written
}

.fi

The "version" argument specifies the PDF version number for the file or
\fBNULL\fR for the default ("2.0").
.PP
Expand Down Expand Up @@ -2616,7 +2621,7 @@ double pdfioImageGetWidth (
.fi
.SS pdfioObjClose
Close an object, writing any data as needed to the PDF
file.
file.
.PP
.nf
bool pdfioObjClose (
Expand Down Expand Up @@ -2802,6 +2807,13 @@ bool pdfioStreamGetToken (
size_t bufsize
);
.fi
.PP
This function reads a single PDF token from a stream. Operator tokens,
boolean values, and numbers are returned as-is in the provided string buffer.
String values start with the opening parenthesis ('(') but have all escaping
resolved and the terminating parenthesis removed. Hexadecimal string values
start with the opening angle bracket ('<') and have all whitespace and the
terminating angle bracket removed.
.SS pdfioStreamPeek
Peek at data in a stream.
.PP
Expand Down Expand Up @@ -3035,4 +3047,4 @@ typedef uint8_t state_t[4][4];
Michael R Sweet
.SH COPYRIGHT
.PP
Copyright (c) 2021-2022 by Michael R Sweet
Copyright (c) 2021-2023 by Michael R Sweet
30 changes: 21 additions & 9 deletions doc/pdfio.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>PDFio Programming Manual v1.1</title>
<title>PDFio Programming Manual v1.1.2</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="generator" content="codedoc v3.7">
<meta name="author" content="Michael R Sweet">
<meta name="language" content="en-US">
<meta name="copyright" content="Copyright © 2021-2022 by Michael R Sweet">
<meta name="version" content="1.1">
<meta name="copyright" content="Copyright © 2021-2023 by Michael R Sweet">
<meta name="version" content="1.1.2">
<style type="text/css"><!--
body {
background: white;
Expand Down Expand Up @@ -245,9 +245,9 @@
<body>
<div class="header">
<p><img class="title" src="pdfio-512.png"></p>
<h1 class="title">PDFio Programming Manual v1.1</h1>
<h1 class="title">PDFio Programming Manual v1.1.2</h1>
<p>Michael R Sweet</p>
<p>Copyright © 2021-2022 by Michael R Sweet</p>
<p>Copyright © 2021-2023 by Michael R Sweet</p>
</div>
<div class="contents">
<h2 class="title">Contents</h2>
Expand Down Expand Up @@ -497,7 +497,7 @@ <h2 class="title" id="introduction">Introduction</h2>
</li>
</ul>
<p>PDFio is <em>not</em> concerned with rendering or viewing a PDF file, although a PDF RIP or viewer could be written using it.</p>
<p>PDFio is Copyright © 2021-2022 by Michael R Sweet and is licensed under the Apache License Version 2.0 with an (optional) exception to allow linking against GPL2/LGPL2 software. See the files &quot;LICENSE&quot; and &quot;NOTICE&quot; for more information.</p>
<p>PDFio is Copyright © 2021-2023 by Michael R Sweet and is licensed under the Apache License Version 2.0 with an (optional) exception to allow linking against GPL2/LGPL2 software. See the files &quot;LICENSE&quot; and &quot;NOTICE&quot; for more information.</p>
<h3 class="title" id="requirements">Requirements</h3>
<p>PDFio requires the following to build the software:</p>
<ul>
Expand Down Expand Up @@ -1388,7 +1388,7 @@ <h4 class="returnvalue">Return Value</h4>
<p class="description"><code>true</code> on success, <code>false</code> on failure</p>
<h3 class="function"><a id="pdfioContentMatrixConcat">pdfioContentMatrixConcat</a></h3>
<p class="description">Concatenate a matrix to the current graphics
state.</p>
state.</p>
<p class="code">
bool pdfioContentMatrixConcat(<a href="#pdfio_stream_t">pdfio_stream_t</a> *st, pdfio_matrix_t m);</p>
<h4 class="parameters">Parameters</h4>
Expand Down Expand Up @@ -1614,6 +1614,9 @@ <h4 class="parameters">Parameters</h4>
</tbody></table>
<h4 class="returnvalue">Return Value</h4>
<p class="description"><code>true</code> on success, <code>false</code> on failure</p>
<h4 class="discussion">Discussion</h4>
<p class="discussion">This function sets the stroke pattern when drawing lines. If &quot;on&quot; and &quot;off&quot;
are 0, a solid line is drawn.</p>
<h3 class="function"><a id="pdfioContentSetFillColorDeviceCMYK">pdfioContentSetFillColorDeviceCMYK</a></h3>
<p class="description">Set device CMYK fill color.</p>
<p class="code">
Expand Down Expand Up @@ -2301,6 +2304,7 @@ <h4 class="discussion">Discussion</h4>
... return true to continue or false to stop ...
}
</pre>

The iteration continues as long as the callback returns <code>true</code> or all keys
have been iterated.</p>
<h3 class="function"><a id="pdfioDictSetArray">pdfioDictSetArray</a></h3>
Expand Down Expand Up @@ -2741,9 +2745,10 @@ <h4 class="discussion">Discussion</h4>
ssize_t
output_cb(void *output_ctx, const void *buffer, size_t bytes)
{
// Write buffer to output and return the number of bytes written
// Write buffer to output and return the number of bytes written
}
</pre>

The &quot;version&quot; argument specifies the PDF version number for the file or
<code>NULL</code> for the default (&quot;2.0&quot;).<br>
<br>
Expand Down Expand Up @@ -3152,7 +3157,7 @@ <h4 class="returnvalue">Return Value</h4>
<p class="description">Width in columns</p>
<h3 class="function"><a id="pdfioObjClose">pdfioObjClose</a></h3>
<p class="description">Close an object, writing any data as needed to the PDF
file.</p>
file.</p>
<p class="code">
bool pdfioObjClose(<a href="#pdfio_obj_t">pdfio_obj_t</a> *obj);</p>
<h4 class="parameters">Parameters</h4>
Expand Down Expand Up @@ -3413,6 +3418,13 @@ <h4 class="parameters">Parameters</h4>
</tbody></table>
<h4 class="returnvalue">Return Value</h4>
<p class="description"><code>true</code> on success, <code>false</code> on EOF</p>
<h4 class="discussion">Discussion</h4>
<p class="discussion">This function reads a single PDF token from a stream. Operator tokens,
boolean values, and numbers are returned as-is in the provided string buffer.
String values start with the opening parenthesis ('(') but have all escaping
resolved and the terminating parenthesis removed. Hexadecimal string values
start with the opening angle bracket ('&lt;') and have all whitespace and the
terminating angle bracket removed.</p>
<h3 class="function"><a id="pdfioStreamPeek">pdfioStreamPeek</a></h3>
<p class="description">Peek at data in a stream.</p>
<p class="code">
Expand Down
2 changes: 1 addition & 1 deletion doc/pdfio.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ goals of pdfio are:
PDFio is *not* concerned with rendering or viewing a PDF file, although a PDF
RIP or viewer could be written using it.

PDFio is Copyright © 2021-2022 by Michael R Sweet and is licensed under the
PDFio is Copyright © 2021-2023 by Michael R Sweet and is licensed under the
Apache License Version 2.0 with an (optional) exception to allow linking against
GPL2/LGPL2 software. See the files "LICENSE" and "NOTICE" for more information.

Expand Down
12 changes: 10 additions & 2 deletions pdfio-content.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Content helper functions for PDFio.
//
// Copyright © 2021 by Michael R Sweet.
// Copyright © 2021-2023 by Michael R Sweet.
//
// Licensed under Apache License v2.0. See the file "LICENSE" for more
// information.
Expand Down Expand Up @@ -670,6 +670,9 @@ pdfioContentSave(pdfio_stream_t *st) // I - Stream
//
// 'pdfioContentSetDashPattern()' - Set the stroke pattern.
//
// This function sets the stroke pattern when drawing lines. If "on" and "off"
// are 0, a solid line is drawn.
//

bool // O - `true` on success, `false` on failure
pdfioContentSetDashPattern(
Expand All @@ -678,7 +681,12 @@ pdfioContentSetDashPattern(
double on, // I - On length
double off) // I - Off length
{
return (pdfioStreamPrintf(st, "[%g %g] %g d\n", on, off, phase));
if (on <= 0.0 && off <= 0.0)
return (pdfioStreamPrintf(st, "[] %g d\n", phase));
else if (fabs(on - off) < 0.001)
return (pdfioStreamPrintf(st, "[%g] %g d\n", on, phase));
else
return (pdfioStreamPrintf(st, "[%g %g] %g d\n", on, off, phase));
}


Expand Down

0 comments on commit 19c4587

Please sign in to comment.