summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b91f764)
raw | patch | inline | side by side (parent: b91f764)
author | ulferikson <ulferikson@users.sourceforge.net> | |
Mon, 7 Aug 2006 20:21:08 +0000 (20:21 +0000) | ||
committer | ulferikson <ulferikson@users.sourceforge.net> | |
Mon, 7 Aug 2006 20:21:08 +0000 (20:21 +0000) |
src/extension/internal/pdf-mini.h | patch | blob | history | |
src/extension/internal/pdf.cpp | patch | blob | history | |
src/extension/internal/pdf.h | patch | blob | history |
index 32f8e284ceb6dbeef4ef27ce0059cc61cd65edb9..3b68ac66bc344e2b1ae1c38f8d28357c56b83d36 100644 (file)
\r
class PdfXref {\r
public:\r
- PdfXref() { size = 10; table = (long*) malloc(size*sizeof(long)); entries = 0; }\r
- ~PdfXref() { free(table); }\r
+ PdfXref() { table.push_back(0); }\r
+ ~PdfXref() { table.clear(); }\r
\r
- long get_size() { return entries; }\r
- long get_entry(long id) { return table[id]; }\r
- \r
- long alloc_id() {\r
- entries++;\r
- if (entries >= size) {\r
- size = size*2;\r
- table = (long *) realloc(table, size*sizeof(long));\r
- }\r
- return entries;\r
- }\r
+ long get_size() { return (long) table.size() - 1; }\r
+ long get_entry(long id) { return table.at(id); }\r
\r
void update_entry(long id, long offset) {\r
- table[id] = offset;\r
+ table.at(id) = offset;\r
}\r
\r
long add_entry(long offset = 0) {\r
- long id = alloc_id();\r
- update_entry(id, offset);\r
- return id;\r
+ table.push_back(offset);\r
+ return get_size();\r
}\r
\r
protected:\r
- long *table;\r
- long entries;\r
- long size;\r
+ std::vector<long> table;\r
};\r
\r
\r
class PdfObject : public Inkscape::SVGOStringStream {\r
public:\r
- PdfObject(long i) : next(NULL) { id = i; setf(std::ios::fixed); }\r
- ~PdfObject() {}\r
+ PdfObject(long i) : next(NULL), name(NULL) { id = i; setf(std::ios::fixed); }\r
+ ~PdfObject() { if (name) g_free(name); }\r
\r
long get_id() { return id; }\r
- const char *get_name() { return name.str().c_str(); }\r
+ const char *get_name() { return name; }\r
long get_length() { return str().length(); }\r
- void set_type(enum pdf_resource_type type) { name << "/" << pdf_res_short[type] << id; }\r
+ void set_type(enum pdf_resource_type type) {\r
+ if (name) g_free(name);\r
+ name = g_strdup_printf("/%s%ld", pdf_res_short[type], id);\r
+ }\r
PdfObject *next;\r
\r
protected:\r
long id;\r
- Inkscape::SVGOStringStream name;\r
+ gchar *name;\r
};\r
\r
PdfFile::PdfFile(FILE *_stream) {\r
index 80a5a1304aca2dba9c873dd2a832b604e7542d69..d4a15316b619e64c4de9de3aba86661a5f7c004a 100644 (file)
_dpi(72),\r
_bitmap(false)\r
{\r
- _num_alphas = 10;\r
- _pushed_alphas = (float*) malloc(_num_alphas*sizeof(float));\r
}\r
\r
PrintPDF::~PrintPDF(void)\r
{\r
- free(_pushed_alphas);\r
-\r
/* fixme: should really use pclose for popen'd streams */\r
if (_stream) fclose(_stream);\r
\r
FILE *osf = NULL;\r
FILE *osp = NULL;\r
\r
- _curr_alpha = 0;\r
- _pushed_alphas[_curr_alpha] = 1.0;\r
+ _pushed_alphas.clear();\r
+ _pushed_alphas.push_back(1.0);\r
\r
gsize bytesRead = 0;\r
gsize bytesWritten = 0;\r
@@ -485,14 +481,8 @@ PrintPDF::bind(Inkscape::Extension::Print *mod, NRMatrix const *transform, float
<< transform->c[4] << " "\r
<< transform->c[5] << " cm\n";\r
\r
- float alpha = opacity * _pushed_alphas[_curr_alpha];\r
- \r
- _curr_alpha++;\r
- if (_curr_alpha >= _num_alphas) {\r
- _num_alphas = _num_alphas*2;\r
- _pushed_alphas = (float *) realloc(_pushed_alphas, _num_alphas*sizeof(float));\r
- }\r
- _pushed_alphas[_curr_alpha] = alpha;\r
+ float alpha = opacity * _pushed_alphas.back();\r
+ _pushed_alphas.push_back(alpha);\r
\r
pdf_file->puts(os);\r
return 1;\r
if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.\r
if (_bitmap) return 0;\r
\r
- if (_curr_alpha > 0)\r
- _curr_alpha--;\r
+ _pushed_alphas.pop_back();\r
+ g_assert( _pushed_alphas.size() > 0 );\r
\r
pdf_file->puts("Q\n");\r
\r
@@ -531,7 +521,7 @@ PrintPDF::print_fill_alpha(SVGOStringStream &os, SPStyle const *const style, NRR
if (style->fill.type == SP_PAINT_TYPE_COLOR) {\r
float alpha = 1.0;\r
alpha *= SP_SCALE24_TO_FLOAT(style->fill_opacity.value);\r
- alpha *= _pushed_alphas[_curr_alpha];\r
+ alpha *= _pushed_alphas.back();\r
\r
if (alpha != 1.0) {\r
PdfObject *pdf_alpha = pdf_file->begin_resource(pdf_extgstate);\r
@@ -552,7 +542,6 @@ PrintPDF::print_fill_alpha(SVGOStringStream &os, SPStyle const *const style, NRR
if (SP_IS_LINEARGRADIENT (SP_STYLE_FILL_SERVER (style))) {\r
\r
SPLinearGradient *lg=SP_LINEARGRADIENT(SP_STYLE_FILL_SERVER (style));\r
-\r
sp_gradient_ensure_vector(SP_GRADIENT(lg)); // when exporting from commandline, vector is not built\r
\r
NR::Point p1 (lg->x1.computed, lg->y1.computed);\r
@@ -569,12 +558,12 @@ PrintPDF::print_fill_alpha(SVGOStringStream &os, SPStyle const *const style, NRR
alpha *= lg->vector.stops[i].opacity;\r
}\r
\r
- if (alpha != 1.0 || _pushed_alphas[_curr_alpha] != 1.0) {\r
+ if (alpha != 1.0 || _pushed_alphas.back() != 1.0) {\r
PdfObject *pdf_gstate = pdf_file->begin_resource(pdf_extgstate);\r
*pdf_gstate << "<< /Type /ExtGState\n";\r
\r
- if (_pushed_alphas[_curr_alpha] != 1.0) {\r
- *pdf_gstate << " /ca " << _pushed_alphas[_curr_alpha] << "\n";\r
+ if (_pushed_alphas.back() != 1.0) {\r
+ *pdf_gstate << " /ca " << _pushed_alphas.back() << "\n";\r
*pdf_gstate << " /AIS false\n";\r
}\r
\r
@@ -634,34 +623,34 @@ PrintPDF::print_fill_alpha(SVGOStringStream &os, SPStyle const *const style, NRR
*pdf_xobj << " /CS /DeviceGray \n";\r
*pdf_xobj << " >>\n";\r
\r
- Inkscape::SVGOStringStream os;\r
- os.setf(std::ios::fixed);\r
+ Inkscape::SVGOStringStream os_tmp;\r
+ os_tmp.setf(std::ios::fixed);\r
\r
- os << "q\n"\r
- << pbox->x0 << " " << pbox->y0 << " m\n"\r
- << pbox->x1 << " " << pbox->y0 << " l\n"\r
- << pbox->x1 << " " << pbox->y1 << " l\n"\r
- << pbox->x0 << " " << pbox->y1 << " l\n"\r
- << pbox->x0 << " " << pbox->y0 << " l\n"\r
- << "h\n"\r
- << "W* n\n";\r
+ os_tmp << "q\n"\r
+ << pbox->x0 << " " << pbox->y0 << " m\n"\r
+ << pbox->x1 << " " << pbox->y0 << " l\n"\r
+ << pbox->x1 << " " << pbox->y1 << " l\n"\r
+ << pbox->x0 << " " << pbox->y1 << " l\n"\r
+ << pbox->x0 << " " << pbox->y0 << " l\n"\r
+ << "h\n"\r
+ << "W* n\n";\r
\r
SPGradient const *g = SP_GRADIENT(SP_STYLE_FILL_SERVER(style));\r
if (g->gradientTransform_set) {\r
- os << g->gradientTransform[0] << " "\r
- << g->gradientTransform[1] << " "\r
- << g->gradientTransform[2] << " "\r
- << g->gradientTransform[3] << " "\r
- << g->gradientTransform[4] << " "\r
- << g->gradientTransform[5] << " cm\n"; \r
+ os_tmp << g->gradientTransform[0] << " "\r
+ << g->gradientTransform[1] << " "\r
+ << g->gradientTransform[2] << " "\r
+ << g->gradientTransform[3] << " "\r
+ << g->gradientTransform[4] << " "\r
+ << g->gradientTransform[5] << " cm\n"; \r
}\r
\r
- os << pdf_alpha->get_name() << " sh\n";\r
- os << "Q\n";\r
- *pdf_xobj << " /Length " << strlen(os.str().c_str()) << "\n";\r
+ os_tmp << pdf_alpha->get_name() << " sh\n";\r
+ os_tmp << "Q\n";\r
+ *pdf_xobj << " /Length " << os_tmp.str().length() << "\n";\r
*pdf_xobj << ">>\n";\r
*pdf_xobj << "stream\n";\r
- *pdf_xobj << os.str().c_str();\r
+ *pdf_xobj << os_tmp.str().c_str();\r
*pdf_xobj << "endstream\n";\r
\r
\r
@@ -679,7 +668,6 @@ PrintPDF::print_fill_alpha(SVGOStringStream &os, SPStyle const *const style, NRR
} else if (SP_IS_RADIALGRADIENT (SP_STYLE_FILL_SERVER (style))) {\r
\r
SPRadialGradient *rg=SP_RADIALGRADIENT(SP_STYLE_FILL_SERVER (style));\r
-\r
sp_gradient_ensure_vector(SP_GRADIENT(rg)); // when exporting from commandline, vector is not built\r
\r
NR::Point c (rg->cx.computed, rg->cy.computed);\r
@@ -705,12 +693,12 @@ PrintPDF::print_fill_alpha(SVGOStringStream &os, SPStyle const *const style, NRR
alpha *= rg->vector.stops[i].opacity;\r
}\r
\r
- if (alpha != 1.0 || _pushed_alphas[_curr_alpha] != 1.0) {\r
+ if (alpha != 1.0 || _pushed_alphas.back() != 1.0) {\r
PdfObject *pdf_gstate = pdf_file->begin_resource(pdf_extgstate);\r
*pdf_gstate << "<< /Type /ExtGState\n";\r
\r
- if (_pushed_alphas[_curr_alpha] != 1.0) {\r
- *pdf_gstate << " /ca " << _pushed_alphas[_curr_alpha] << "\n";\r
+ if (_pushed_alphas.back() != 1.0) {\r
+ *pdf_gstate << " /ca " << _pushed_alphas.back() << "\n";\r
*pdf_gstate << " /AIS false\n";\r
}\r
\r
@@ -771,34 +759,34 @@ PrintPDF::print_fill_alpha(SVGOStringStream &os, SPStyle const *const style, NRR
*pdf_xobj << " /CS /DeviceGray \n";\r
*pdf_xobj << " >>\n";\r
\r
- Inkscape::SVGOStringStream os;\r
- os.setf(std::ios::fixed);\r
+ Inkscape::SVGOStringStream os_tmp;\r
+ os_tmp.setf(std::ios::fixed);\r
\r
- os << "q\n"\r
- << pbox->x0 << " " << pbox->y0 << " m\n"\r
- << pbox->x1 << " " << pbox->y0 << " l\n"\r
- << pbox->x1 << " " << pbox->y1 << " l\n"\r
- << pbox->x0 << " " << pbox->y1 << " l\n"\r
- << pbox->x0 << " " << pbox->y0 << " l\n"\r
- << "h\n"\r
- << "W* n\n";\r
+ os_tmp << "q\n"\r
+ << pbox->x0 << " " << pbox->y0 << " m\n"\r
+ << pbox->x1 << " " << pbox->y0 << " l\n"\r
+ << pbox->x1 << " " << pbox->y1 << " l\n"\r
+ << pbox->x0 << " " << pbox->y1 << " l\n"\r
+ << pbox->x0 << " " << pbox->y0 << " l\n"\r
+ << "h\n"\r
+ << "W* n\n";\r
\r
SPGradient const *g = SP_GRADIENT(SP_STYLE_FILL_SERVER(style));\r
if (g->gradientTransform_set) {\r
- os << g->gradientTransform[0] << " "\r
- << g->gradientTransform[1] << " "\r
- << g->gradientTransform[2] << " "\r
- << g->gradientTransform[3] << " "\r
- << g->gradientTransform[4] << " "\r
- << g->gradientTransform[5] << " cm\n"; \r
+ os_tmp << g->gradientTransform[0] << " "\r
+ << g->gradientTransform[1] << " "\r
+ << g->gradientTransform[2] << " "\r
+ << g->gradientTransform[3] << " "\r
+ << g->gradientTransform[4] << " "\r
+ << g->gradientTransform[5] << " cm\n"; \r
}\r
\r
- os << pdf_alpha->get_name() << " sh\n";\r
- os << "Q\n";\r
- *pdf_xobj << " /Length " << strlen(os.str().c_str()) << "\n";\r
+ os_tmp << pdf_alpha->get_name() << " sh\n";\r
+ os_tmp << "Q\n";\r
+ *pdf_xobj << " /Length " << os_tmp.str().length() << "\n";\r
*pdf_xobj << ">>\n";\r
*pdf_xobj << "stream\n";\r
- *pdf_xobj << os.str().c_str();\r
+ *pdf_xobj << os_tmp.str().c_str();\r
*pdf_xobj << "endstream\n";\r
\r
\r
@@ -836,6 +824,8 @@ PrintPDF::print_fill_style(SVGOStringStream &os, SPStyle const *const style, NRR
if (SP_IS_LINEARGRADIENT (SP_STYLE_FILL_SERVER (style))) {\r
\r
SPLinearGradient *lg=SP_LINEARGRADIENT(SP_STYLE_FILL_SERVER (style));\r
+ sp_gradient_ensure_vector(SP_GRADIENT(lg)); // when exporting from commandline, vector is not built\r
+\r
NR::Point p1 (lg->x1.computed, lg->y1.computed);\r
NR::Point p2 (lg->x2.computed, lg->y2.computed);\r
if (pbox && SP_GRADIENT(lg)->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {\r
@@ -853,7 +843,6 @@ PrintPDF::print_fill_style(SVGOStringStream &os, SPStyle const *const style, NRR
*pdf_shade << "/Domain [0 1]\n";\r
*pdf_shade << "/Function <<\n/FunctionType 3\n/Functions\n[\n";\r
\r
- sp_gradient_ensure_vector(SP_GRADIENT(lg)); // when exporting from commandline, vector is not built\r
for (gint i = 0; unsigned(i) < lg->vector.stops.size() - 1; i++) {\r
float rgb[3];\r
sp_color_get_rgb_floatv(&lg->vector.stops[i].color, rgb);\r
@@ -881,6 +870,8 @@ PrintPDF::print_fill_style(SVGOStringStream &os, SPStyle const *const style, NRR
} else if (SP_IS_RADIALGRADIENT (SP_STYLE_FILL_SERVER (style))) {\r
\r
SPRadialGradient *rg=SP_RADIALGRADIENT(SP_STYLE_FILL_SERVER (style));\r
+ sp_gradient_ensure_vector(SP_GRADIENT(rg)); // when exporting from commandline, vector is not built\r
+\r
NR::Point c (rg->cx.computed, rg->cy.computed);\r
NR::Point f (rg->fx.computed, rg->fy.computed);\r
double r = rg->r.computed;\r
@@ -907,7 +898,6 @@ PrintPDF::print_fill_style(SVGOStringStream &os, SPStyle const *const style, NRR
*pdf_shade << "/Domain [0 1]\n";\r
*pdf_shade << "/Function <<\n/FunctionType 3\n/Functions\n[\n";\r
\r
- sp_gradient_ensure_vector(SP_GRADIENT(rg)); // when exporting from commandline, vector is not built\r
for (gint i = 0; unsigned(i) < rg->vector.stops.size() - 1; i++) {\r
float rgb[3];\r
sp_color_get_rgb_floatv(&rg->vector.stops[i].color, rgb);\r
\r
float alpha = 1.0;\r
alpha *= SP_SCALE24_TO_FLOAT(style->stroke_opacity.value);\r
- alpha *= _pushed_alphas[_curr_alpha];\r
+ alpha *= _pushed_alphas.back();\r
\r
if (alpha != 1.0) {\r
PdfObject *pdf_alpha = pdf_file->begin_resource(pdf_extgstate);\r
void\r
PrintPDF::init(void)\r
{\r
- /* SVG in */\r
+ /* PDF print */\r
(void) Inkscape::Extension::build_from_mem(\r
"<inkscape-extension>\n"\r
"<name>" N_("PDF Print") "</name>\n"\r
index 0ceda7cafa1969f5c13b2bc4540e55df986d49fb..50bfebe222cdb716835d415e5dca010c47cfb278 100644 (file)
PdfFile *pdf_file;\r
PdfObject *doc_info;\r
PdfObject *page_stream;\r
- float *_pushed_alphas;\r
- int _num_alphas;\r
- int _curr_alpha;\r
+ std::vector<float> _pushed_alphas;\r
unsigned short _dpi;\r
bool _bitmap;\r
std::set<std::string> _latin1_encoded_fonts;\r