Skip to content

Commit

Permalink
Add pdfioFileCreateNumber/StringObj functions (Issue #14)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Dec 5, 2023
1 parent 7ff051f commit 16c8b83
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 0 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.2.0 (Month DD, YYYY)
-----------------------

- Added `pdfioFileCreateNumberObj` and `pdfioFileCreateStringObj` functions
(Issue #14)
- Added `pdfioContentTextMeasure` function (Issue #17)
- Added `pdfioContentTextNewLineShow` and `pdfioContentTextNewLineShowf`
functions (Issue #24)
Expand Down
24 changes: 24 additions & 0 deletions doc/pdfio.3
Original file line number Diff line number Diff line change
Expand Up @@ -2325,6 +2325,18 @@ Note: Currently PNG support is limited to grayscale, RGB, or indexed files
without interlacing or alpha. Transparency (masking) based on color/index
.IP 5
is supported.
.SS pdfioFileCreateNumberObj
Create a new object in a PDF file containing a number.
.PP
.nf
pdfio_obj_t * pdfioFileCreateNumberObj (
pdfio_file_t *pdf,
double number
);
.fi
.PP
This function creates a new object with a number value in a PDF file.
You must call \fIpdfioObjClose\fR to write the object to the file.
.SS pdfioFileCreateObj
Create a new object in a PDF file.
.PP
Expand Down Expand Up @@ -2389,6 +2401,18 @@ pdfio_stream_t * pdfioFileCreatePage (
pdfio_dict_t *dict
);
.fi
.SS pdfioFileCreateStringObj
Create a new object in a PDF file containing a string.
.PP
.nf
pdfio_obj_t * pdfioFileCreateStringObj (
pdfio_file_t *pdf,
const char *string
);
.fi
.PP
This function creates a new object with a string value in a PDF file.
You must call \fIpdfioObjClose\fR to write the object to the file.
.SS pdfioFileCreateTemporary

.PP
Expand Down
34 changes: 34 additions & 0 deletions doc/pdfio.html
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,11 @@ <h2 class="title">Contents</h2>
<li><a href="#pdfioFileCreateICCObjFromFile">pdfioFileCreateICCObjFromFile</a></li>
<li><a href="#pdfioFileCreateImageObjFromData">pdfioFileCreateImageObjFromData</a></li>
<li><a href="#pdfioFileCreateImageObjFromFile">pdfioFileCreateImageObjFromFile</a></li>
<li><a href="#pdfioFileCreateNumberObj">pdfioFileCreateNumberObj</a></li>
<li><a href="#pdfioFileCreateObj">pdfioFileCreateObj</a></li>
<li><a href="#pdfioFileCreateOutput">pdfioFileCreateOutput</a></li>
<li><a href="#pdfioFileCreatePage">pdfioFileCreatePage</a></li>
<li><a href="#pdfioFileCreateStringObj">pdfioFileCreateStringObj</a></li>
<li><a href="#pdfioFileCreateTemporary">pdfioFileCreateTemporary</a></li>
<li><a href="#pdfioFileFindObj">pdfioFileFindObj</a></li>
<li><a href="#pdfioFileGetAuthor">pdfioFileGetAuthor</a></li>
Expand Down Expand Up @@ -2771,6 +2773,22 @@ <h4 class="discussion">Discussion</h4>
Note: Currently PNG support is limited to grayscale, RGB, or indexed files
without interlacing or alpha. Transparency (masking) based on color/index
is supported.</blockquote>
<h3 class="function"><a id="pdfioFileCreateNumberObj">pdfioFileCreateNumberObj</a></h3>
<p class="description">Create a new object in a PDF file containing a number.</p>
<p class="code">
<a href="#pdfio_obj_t">pdfio_obj_t</a> *pdfioFileCreateNumberObj(<a href="#pdfio_file_t">pdfio_file_t</a> *pdf, double number);</p>
<h4 class="parameters">Parameters</h4>
<table class="list"><tbody>
<tr><th>pdf</th>
<td class="description">PDF file</td></tr>
<tr><th>number</th>
<td class="description">Number value</td></tr>
</tbody></table>
<h4 class="returnvalue">Return Value</h4>
<p class="description">New object</p>
<h4 class="discussion">Discussion</h4>
<p class="discussion">This function creates a new object with a number value in a PDF file.
You must call <a href="#pdfioObjClose"><code>pdfioObjClose</code></a> to write the object to the file.</p>
<h3 class="function"><a id="pdfioFileCreateObj">pdfioFileCreateObj</a></h3>
<p class="description">Create a new object in a PDF file.</p>
<p class="code">
Expand Down Expand Up @@ -2849,6 +2867,22 @@ <h4 class="parameters">Parameters</h4>
</tbody></table>
<h4 class="returnvalue">Return Value</h4>
<p class="description">Contents stream</p>
<h3 class="function"><a id="pdfioFileCreateStringObj">pdfioFileCreateStringObj</a></h3>
<p class="description">Create a new object in a PDF file containing a string.</p>
<p class="code">
<a href="#pdfio_obj_t">pdfio_obj_t</a> *pdfioFileCreateStringObj(<a href="#pdfio_file_t">pdfio_file_t</a> *pdf, const char *string);</p>
<h4 class="parameters">Parameters</h4>
<table class="list"><tbody>
<tr><th>pdf</th>
<td class="description">PDF file</td></tr>
<tr><th>string</th>
<td class="description">String</td></tr>
</tbody></table>
<h4 class="returnvalue">Return Value</h4>
<p class="description">New object</p>
<h4 class="discussion">Discussion</h4>
<p class="discussion">This function creates a new object with a string value in a PDF file.
You must call <a href="#pdfioObjClose"><code>pdfioObjClose</code></a> to write the object to the file.</p>
<h3 class="function"><a id="pdfioFileCreateTemporary">pdfioFileCreateTemporary</a></h3>
<p class="description"></p>
<p class="code">
Expand Down
52 changes: 52 additions & 0 deletions pdfio-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,32 @@ pdfioFileCreateArrayObj(
}


//
// 'pdfioFileCreateNumberObj()' - Create a new object in a PDF file containing a number.
//
// This function creates a new object with a number value in a PDF file.
// You must call @link pdfioObjClose@ to write the object to the file.
//

pdfio_obj_t * // O - New object
pdfioFileCreateNumberObj(
pdfio_file_t *pdf, // I - PDF file
double number) // I - Number value
{
_pdfio_value_t value; // Object value


// Range check input...
if (!pdf)
return (NULL);

value.type = PDFIO_VALTYPE_NUMBER;
value.value.number = number;

return (_pdfioFileCreateObj(pdf, NULL, &value));
}


//
// 'pdfioFileCreateObj()' - Create a new object in a PDF file.
//
Expand Down Expand Up @@ -639,6 +665,32 @@ pdfioFileCreatePage(pdfio_file_t *pdf, // I - PDF file
}


//
// 'pdfioFileCreateStringObj()' - Create a new object in a PDF file containing a string.
//
// This function creates a new object with a string value in a PDF file.
// You must call @link pdfioObjClose@ to write the object to the file.
//

pdfio_obj_t * // O - New object
pdfioFileCreateStringObj(
pdfio_file_t *pdf, // I - PDF file
const char *string) // I - String
{
_pdfio_value_t value; // Object value


// Range check input...
if (!pdf)
return (NULL);

value.type = PDFIO_VALTYPE_STRING;
value.value.string = string;

return (_pdfioFileCreateObj(pdf, NULL, &value));
}


//
// 'pdfioFileCreateTemporary()' - Create a temporary PDF file.
//
Expand Down
2 changes: 2 additions & 0 deletions pdfio.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,12 @@ extern bool pdfioDictSetStringf(pdfio_dict_t *dict, const char *key, const char
extern bool pdfioFileClose(pdfio_file_t *pdf) _PDFIO_PUBLIC;
extern pdfio_file_t *pdfioFileCreate(const char *filename, const char *version, pdfio_rect_t *media_box, pdfio_rect_t *crop_box, pdfio_error_cb_t error_cb, void *error_data) _PDFIO_PUBLIC;
extern pdfio_obj_t *pdfioFileCreateArrayObj(pdfio_file_t *pdf, pdfio_array_t *array) _PDFIO_PUBLIC;
extern pdfio_obj_t *pdfioFileCreateNumberObj(pdfio_file_t *pdf, double number) _PDFIO_PUBLIC;
extern pdfio_obj_t *pdfioFileCreateObj(pdfio_file_t *pdf, pdfio_dict_t *dict) _PDFIO_PUBLIC;
extern pdfio_file_t *pdfioFileCreateOutput(pdfio_output_cb_t output_cb, void *output_ctx, const char *version, pdfio_rect_t *media_box, pdfio_rect_t *crop_box, pdfio_error_cb_t error_cb, void *error_data) _PDFIO_PUBLIC;
// TODO: Add number, array, string, etc. versions of pdfioFileCreateObject?
extern pdfio_stream_t *pdfioFileCreatePage(pdfio_file_t *pdf, pdfio_dict_t *dict) _PDFIO_PUBLIC;
extern pdfio_obj_t *pdfioFileCreateStringObj(pdfio_file_t *pdf, const char *s) _PDFIO_PUBLIC;
extern pdfio_file_t *pdfioFileCreateTemporary(char *buffer, size_t bufsize, const char *version, pdfio_rect_t *media_box, pdfio_rect_t *crop_box, pdfio_error_cb_t error_cb, void *error_data) _PDFIO_PUBLIC;
extern pdfio_obj_t *pdfioFileFindObj(pdfio_file_t *pdf, size_t number) _PDFIO_PUBLIC;
extern const char *pdfioFileGetAuthor(pdfio_file_t *pdf) _PDFIO_PUBLIC;
Expand Down
2 changes: 2 additions & 0 deletions pdfio1.def
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,11 @@ pdfioFileCreateFontObjFromFile
pdfioFileCreateICCObjFromFile
pdfioFileCreateImageObjFromData
pdfioFileCreateImageObjFromFile
pdfioFileCreateNumberObj
pdfioFileCreateObj
pdfioFileCreateOutput
pdfioFileCreatePage
pdfioFileCreateStringObj
pdfioFileCreateTemporary
pdfioFileFindObj
pdfioFileGetAuthor
Expand Down

0 comments on commit 16c8b83

Please sign in to comment.