"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/Plugins/Pdf/pdf_hummus_renderer.cpp" between
TeXmacs-1.99.4-src.tar.gz and TeXmacs-1.99.5-src.tar.gz

About: GNU TeXmacs is a what-you-see-is-what-you-get scientific text editor, which was both inspired by TeX and GNU Emacs.

pdf_hummus_renderer.cpp  (TeXmacs-1.99.4-src):pdf_hummus_renderer.cpp  (TeXmacs-1.99.5-src)
skipping to change at line 27 skipping to change at line 27
#include "analyze.hpp" #include "analyze.hpp"
#include "iterator.hpp" #include "iterator.hpp"
#include "merge_sort.hpp" #include "merge_sort.hpp"
#include "scheme.hpp" #include "scheme.hpp"
#include "sys_utils.hpp" #include "sys_utils.hpp"
#include "convert.hpp" #include "convert.hpp"
#include "ntuple.hpp" #include "ntuple.hpp"
#include "link.hpp" #include "link.hpp"
#include "frame.hpp" #include "frame.hpp"
#include "Ghostscript/gs_utilities.hpp" // for gs_prefix #include "Ghostscript/gs_utilities.hpp" // for gs_prefix
#include "wencoding.hpp"
#ifdef QTTEXMACS #ifdef QTTEXMACS
#include "Qt/qt_utilities.hpp" #include "Qt/qt_utilities.hpp"
#endif #endif
#include "PDFWriter/PDFWriter.h" #include "PDFWriter/PDFWriter.h"
#include "PDFWriter/PDFPage.h" #include "PDFWriter/PDFPage.h"
#include "PDFWriter/PageContentContext.h" #include "PDFWriter/PageContentContext.h"
#include "PDFWriter/DictionaryContext.h" #include "PDFWriter/DictionaryContext.h"
#include "PDFWriter/PDFImageXObject.h" #include "PDFWriter/PDFImageXObject.h"
#include "PDFWriter/PDFStream.h" #include "PDFWriter/PDFStream.h"
#include "PDFWriter/PDFDocumentCopyingContext.h" #include "PDFWriter/PDFDocumentCopyingContext.h"
#include "PDFWriter/InputByteArrayStream.h" #include "PDFWriter/InputByteArrayStream.h"
#include "PDFWriter/ProcsetResourcesConstants.h" #include "PDFWriter/ProcsetResourcesConstants.h"
#include "PDFWriter/OutputStreamTraits.h" #include "PDFWriter/OutputStreamTraits.h"
#include "PDFWriter/XObjectContentContext.h" #include "PDFWriter/XObjectContentContext.h"
#include "PDFWriter/PDFFormXObject.h" #include "PDFWriter/PDFFormXObject.h"
#include "PDFWriter/InfoDictionary.h" #include "PDFWriter/InfoDictionary.h"
#include "PDFWriter/PDFPageInput.h"
#include "PDFWriter/PDFTiledPattern.h"
#include "PDFWriter/TiledPatternContentContext.h"
/****************************************************************************** /******************************************************************************
* pdf_hummus_renderer * pdf_hummus_renderer
******************************************************************************/ ******************************************************************************/
typedef triple<int,int,int> rgb; typedef triple<int,int,int> rgb;
typedef quartet<string,int,SI,SI> dest_data; typedef quartet<string,int,SI,SI> dest_data;
typedef quintuple<string,int,SI,SI,int> outline_data; typedef quintuple<string,int,SI,SI,int> outline_data;
class pdf_image; class pdf_image;
class pdf_raw_image; class pdf_raw_image;
class t3font; class t3font;
class pdf_pattern;
class pdf_hummus_renderer_rep : public renderer_rep { class pdf_hummus_renderer_rep : public renderer_rep {
static const int default_dpi= 72; // PDF initial coordinate system corresponds to 72 dpi static const int default_dpi= 72; // PDF initial coordinate system corresponds to 72 dpi
bool started; // initialisation is OK bool started; // initialisation is OK
url pdf_file_name; url pdf_file_name;
int dpi; int dpi;
int nr_pages; int nr_pages;
string page_type; string page_type;
bool landscape; bool landscape;
skipping to change at line 81 skipping to change at line 86
bool inText; bool inText;
int alpha; int alpha;
rgb stroke_rgb; rgb stroke_rgb;
rgb fill_rgb; rgb fill_rgb;
color fg, bg; color fg, bg;
SI lw; SI lw;
double current_width; double current_width;
int clip_level; int clip_level;
pencil pen; pencil pen;
brush bgb; brush bgb, fgb;
string cfn; string cfn;
PDFUsedFont* cfid; PDFUsedFont* cfid;
double fsize; double fsize;
double prev_text_x, prev_text_y; double prev_text_x, prev_text_y;
double width, height; double width, height;
hashmap<string,PDFUsedFont*> pdf_fonts; hashmap<string,PDFUsedFont*> pdf_fonts;
//hashmap<string,ObjectIDType> image_resources;
hashmap<string,pdf_raw_image> pdf_glyphs; hashmap<string,pdf_raw_image> pdf_glyphs;
hashmap<tree,pdf_image> image_pool; hashmap<tree,pdf_image> image_pool;
hashmap<tree,pdf_image> pattern_image_pool;
hashmap<tree,pdf_pattern> pattern_pool;
array<url> temp_images;
hashmap<int,ObjectIDType> alpha_id; hashmap<int,ObjectIDType> alpha_id;
hashmap<int,ObjectIDType> page_id; hashmap<int,ObjectIDType> page_id;
hashmap<string,t3font> t3font_list; hashmap<string,t3font> t3font_list;
// link annotation support // link annotation support
hashmap<ObjectIDType,string> annot_list; hashmap<ObjectIDType,string> annot_list;
list<dest_data> dests; list<dest_data> dests;
ObjectIDType destId; ObjectIDType destId;
hashmap<string,int> label_id; hashmap<string,int> label_id;
skipping to change at line 136 skipping to change at line 143
return y; return y;
}; };
// various internal routines // various internal routines
void init_page_size (); void init_page_size ();
void select_stroke_color (color c); void select_stroke_color (color c);
void select_fill_color (color c); void select_fill_color (color c);
void select_alpha (int a); void select_alpha (int a);
void register_pattern_image (brush br, SI pixel);
void select_stroke_pattern (brush br);
void select_fill_pattern (brush br);
void select_line_width (SI w); void select_line_width (SI w);
void compile_glyph (scheme_tree t); void compile_glyph (scheme_tree t);
void begin_text (); void begin_text ();
void end_text (); void end_text ();
void begin_page(); void begin_page();
void end_page(); void end_page();
int get_label_id(string label); int get_label_id(string label);
// glyph positioning // glyph positioning
typedef quartet<int,int,int,glyph> drawn_glyph; typedef quartet<int,int,int,glyph> drawn_glyph;
list <drawn_glyph> drawn_glyphs; list <drawn_glyph> drawn_glyphs;
void draw_glyphs(); void draw_glyphs();
// various internal routines // various internal routines
void flush_images(); void flush_images();
void flush_patterns();
void flush_glyphs(); void flush_glyphs();
void flush_dests(); void flush_dests();
void flush_outlines(); void flush_outlines();
void flush_fonts(); void flush_fonts();
PDFImageXObject *create_pdf_image_raw (string raw_data, SI width, SI height, O bjectIDType imageXObjectID); PDFImageXObject *create_pdf_image_raw (string raw_data, SI width, SI height, O bjectIDType imageXObjectID);
void make_pdf_font (string fontname); void make_pdf_font (string fontname);
void draw_bitmap_glyph (int ch, font_glyphs fn, SI x, SI y); void draw_bitmap_glyph (int ch, font_glyphs fn, SI x, SI y);
void image (url u, SI w, SI h, SI x, SI y, void image (url u, SI w, SI h, SI x, SI y,
int alpha); int alpha);
skipping to change at line 211 skipping to change at line 223
void next_page (); void next_page ();
void set_transformation (frame fr); void set_transformation (frame fr);
void reset_transformation (); void reset_transformation ();
void set_clipping (SI x1, SI y1, SI x2, SI y2, bool restore= false); void set_clipping (SI x1, SI y1, SI x2, SI y2, bool restore= false);
pencil get_pencil (); pencil get_pencil ();
brush get_background (); brush get_background ();
void set_pencil (pencil pen2); void set_pencil (pencil pen2);
void set_brush (brush b2);
void set_background (brush b2); void set_background (brush b2);
void draw (int char_code, font_glyphs fn, SI x, SI y); void draw (int char_code, font_glyphs fn, SI x, SI y);
void line (SI x1, SI y1, SI x2, SI y2); void line (SI x1, SI y1, SI x2, SI y2);
void lines (array<SI> x, array<SI> y); void lines (array<SI> x, array<SI> y);
void clear (SI x1, SI y1, SI x2, SI y2); void clear (SI x1, SI y1, SI x2, SI y2);
void fill (SI x1, SI y1, SI x2, SI y2); void fill (SI x1, SI y1, SI x2, SI y2);
void arc (SI x1, SI y1, SI x2, SI y2, int alpha, int delta); void arc (SI x1, SI y1, SI x2, SI y2, int alpha, int delta);
void fill_arc (SI x1, SI y1, SI x2, SI y2, int alpha, int delta); void fill_arc (SI x1, SI y1, SI x2, SI y2, int alpha, int delta);
void polygon (array<SI> x, array<SI> y, bool convex=true); void polygon (array<SI> x, array<SI> y, bool convex=true);
void draw_picture (picture p, SI x, SI y, int alpha); void draw_picture (picture p, SI x, SI y, int alpha);
void draw_scalable (scalable im, SI x, SI y, int alpha); void draw_scalable (scalable im, SI x, SI y, int alpha);
renderer shadow (picture& pic, SI x1, SI y1, SI x2, SI y2); renderer shadow (picture& pic, SI x1, SI y1, SI x2, SI y2);
void fetch (SI x1, SI y1, SI x2, SI y2, renderer ren, SI x, SI y); void fetch (SI x1, SI y1, SI x2, SI y2, renderer ren, SI x, SI y);
void new_shadow (renderer& ren); void new_shadow (renderer& ren);
void delete_shadow (renderer& ren); void delete_shadow (renderer& ren);
void get_shadow (renderer ren, SI x1, SI y1, SI x2, SI y2); void get_shadow (renderer ren, SI x1, SI y1, SI x2, SI y2);
void put_shadow (renderer ren, SI x1, SI y1, SI x2, SI y2); void put_shadow (renderer ren, SI x1, SI y1, SI x2, SI y2);
void apply_shadow (SI x1, SI y1, SI x2, SI y2); void apply_shadow (SI x1, SI y1, SI x2, SI y2);
/************************ subroutines hyperlinks ***************************/ /************************ subroutines hyperlinks ***************************/
skipping to change at line 255 skipping to change at line 267
static void static void
write_indirect_obj(ObjectsContext& objectsContext, ObjectIDType destId, string payload) { write_indirect_obj(ObjectsContext& objectsContext, ObjectIDType destId, string payload) {
objectsContext.StartNewIndirectObject(destId); objectsContext.StartNewIndirectObject(destId);
c_string buf (payload); c_string buf (payload);
objectsContext.StartFreeContext()->Write((unsigned char *)(char*)buf, N(payloa d)); objectsContext.StartFreeContext()->Write((unsigned char *)(char*)buf, N(payloa d));
objectsContext.EndFreeContext(); objectsContext.EndFreeContext();
objectsContext.EndIndirectObject(); objectsContext.EndIndirectObject();
} }
void pdf_image_info (url image, int& w, int& h, PDFRectangle& cropBox, double (&
tMat)[6], PDFPageInput& pageInput);
/****************************************************************************** /******************************************************************************
* constructors and destructors * constructors and destructors
******************************************************************************/ ******************************************************************************/
pdf_hummus_renderer_rep::pdf_hummus_renderer_rep ( pdf_hummus_renderer_rep::pdf_hummus_renderer_rep (
url pdf_file_name2, int dpi2, int nr_pages2, url pdf_file_name2, int dpi2, int nr_pages2,
string page_type2, bool landscape2, double paper_w2, double paper_h2): string page_type2, bool landscape2, double paper_w2, double paper_h2):
renderer_rep (false), renderer_rep (false),
pdf_file_name (pdf_file_name2), dpi (dpi2), pdf_file_name (pdf_file_name2), dpi (dpi2),
nr_pages (nr_pages2), page_type (page_type2), nr_pages (nr_pages2), page_type (page_type2),
skipping to change at line 283 skipping to change at line 297
destId(0), destId(0),
label_count(0), label_count(0),
outlineId(0) outlineId(0)
{ {
width = default_dpi * paper_w / 2.54; width = default_dpi * paper_w / 2.54;
height= default_dpi * paper_h / 2.54; height= default_dpi * paper_h / 2.54;
// setup library // setup library
EStatusCode status; EStatusCode status;
#if (defined (__MINGW__) || defined (__MINGW32__))
// WIN is using 8bit encodings, but pdfwriter expects UTF8
// if path or file contains non-ascii characters we need an extra conversion
step.
status = pdfWriter.StartPDF(as_charp(western_to_utf8(concretize (pdf_file_na
me))), ePDFVersion14 ); // PDF 1.4 for alpha
#else
status = pdfWriter.StartPDF(as_charp(concretize (pdf_file_name)), ePDFVer sion14 ); // PDF 1.4 for alpha status = pdfWriter.StartPDF(as_charp(concretize (pdf_file_name)), ePDFVer sion14 ); // PDF 1.4 for alpha
#endif
// , LogConfiguration(true, true, "/Users/mgubi/Desktop/pdfwriter-x.log ") // , LogConfiguration(true, true, "/Users/mgubi/Desktop/pdfwriter-x.log ")
// , PDFCreationSettings(false) ); // true = compression on // , PDFCreationSettings(false) ); // true = compression on
if (status != PDFHummus::eSuccess) { if (status != PDFHummus::eSuccess) {
convert_error << "failed to start PDF\n"; convert_error << "failed to start PDF\n";
started=false; started=false;
} else { } else {
started=true; started=true;
pdfWriter.GetDocumentContext().AddDocumentContextExtender (new De stinationsWriter(this)); pdfWriter.GetDocumentContext().AddDocumentContextExtender (new De stinationsWriter(this));
// start real work // start real work
begin_page(); begin_page();
} }
} }
pdf_hummus_renderer_rep::~pdf_hummus_renderer_rep () { pdf_hummus_renderer_rep::~pdf_hummus_renderer_rep () {
if (!started) return; // no cleanup to do if (!started) return; // no cleanup to do
end_page(); end_page();
flush_images(); flush_images();
flush_patterns();
flush_glyphs(); flush_glyphs();
flush_dests(); flush_dests();
flush_outlines(); flush_outlines();
flush_fonts(); flush_fonts();
flush_metadata(); flush_metadata();
{ {
// flush alphas // flush alphas
iterator<int> it = iterate(alpha_id); iterator<int> it = iterate(alpha_id);
ObjectsContext& objectsContext = pdfWriter.GetObjectsContext(); ObjectsContext& objectsContext = pdfWriter.GetObjectsContext();
skipping to change at line 342 skipping to change at line 363
while (it->busy()) { while (it->busy()) {
ObjectIDType id = it->next(); ObjectIDType id = it->next();
write_indirect_obj(objectsContext, id, annot_list(id)); write_indirect_obj(objectsContext, id, annot_list(id));
} }
} }
EStatusCode status = pdfWriter.EndPDF(); EStatusCode status = pdfWriter.EndPDF();
if (status != PDFHummus::eSuccess) { if (status != PDFHummus::eSuccess) {
convert_error << "Failed in end PDF\n"; convert_error << "Failed in end PDF\n";
} }
// remove temporary pictures
for (int i=0; i<N(temp_images); i++)
if (!is_none (temp_images[i]))
remove (temp_images[i]);
} }
bool bool
pdf_hummus_renderer_rep::is_printer () { pdf_hummus_renderer_rep::is_printer () {
// debug_convert << "is_printer\n"; // debug_convert << "is_printer\n";
return true; return true;
} }
bool bool
pdf_hummus_renderer_rep::is_started () { pdf_hummus_renderer_rep::is_started () {
skipping to change at line 491 skipping to change at line 517
void void
pdf_hummus_renderer_rep::set_clipping (SI x1, SI y1, SI x2, SI y2, bool restore) { pdf_hummus_renderer_rep::set_clipping (SI x1, SI y1, SI x2, SI y2, bool restore) {
renderer_rep::set_clipping (x1, y1, x2, y2, restore); renderer_rep::set_clipping (x1, y1, x2, y2, restore);
end_text(); end_text();
outer_round (x1, y1, x2, y2); outer_round (x1, y1, x2, y2);
if (restore) { if (restore) {
// debug_convert << "restore clipping\n"; // debug_convert << "restore clipping\n";
contentContext->Q(); if (clip_level > 0) { contentContext->Q(); clip_level--; }
if (clip_level > 0) clip_level--;
cfn= ""; cfn= "";
} }
else { else {
// debug_convert << "set clipping\n"; // debug_convert << "set clipping\n";
contentContext->q(); clip_level++; contentContext->q(); clip_level++;
double xx1= to_x (min (x1, x2)); double xx1= to_x (min (x1, x2));
double yy1= to_y (min (y1, y2)); double yy1= to_y (min (y1, y2));
double xx2= to_x (max (x1, x2)); double xx2= to_x (max (x1, x2));
double yy2= to_y (max (y1, y2)); double yy2= to_y (max (y1, y2));
contentContext->re(xx1, yy1, xx2-xx1, yy2-yy1); contentContext->re(xx1, yy1, xx2-xx1, yy2-yy1);
contentContext->W(); contentContext->W();
contentContext->n(); contentContext->n();
} }
} }
/****************************************************************************** /******************************************************************************
* Images
******************************************************************************/
class pdf_image_rep : public concrete_struct
{
public:
url u;
int w,h;
ObjectIDType id;
pdf_image_rep(url _u, ObjectIDType _id)
: u(_u), id(_id)
{ image_size (u, w, h); }
~pdf_image_rep() {}
bool flush_jpg (PDFWriter& pdfw, url image);
bool flush_raster (PDFWriter& pdfw, url image);
void flush (PDFWriter& pdfw);
bool flush_for_pattern (PDFWriter& pdfw);
}; // class pdf_image_ref
class pdf_image {
CONCRETE_NULL(pdf_image);
pdf_image (url _u, ObjectIDType _id):
rep (tm_new<pdf_image_rep> (_u,_id)) {};
};
CONCRETE_NULL_CODE(pdf_image);
/******************************************************************************
* Tiled patterns
******************************************************************************/
class pdf_pattern_rep : public concrete_struct {
public:
pdf_image im;
SI w, h, sx, sy;
double scale_x, scale_y;
ObjectIDType id;
pdf_pattern_rep (pdf_image _im, SI _w, SI _h, SI _sx, SI _sy,
double _scale_x, double _scale_y, ObjectIDType _id)
: im (_im), w (_w), h (_h), sx (_sx), sy (_sy),
scale_x (_scale_x), scale_y (_scale_y), id (_id) {}
~pdf_pattern_rep () {}
void flush (PDFWriter& pdfw) {
const double matrix[]= { scale_x, 0, 0, scale_y, (double) sx, (double) sy };
DocumentContext& documentContext= pdfw.GetDocumentContext();
PDFTiledPattern* tiledPattern= documentContext.StartTiledPattern
(1, // int inPaintType,
2, // int inTilingType,
PDFRectangle(0, 0, w, h),
w, // double inXStep,
h, // double inYStep,
id,
matrix);
TiledPatternContentContext* tiledPatternContentContext =
tiledPattern->GetContentContext();
std::string imageName=
tiledPattern->GetResourcesDictionary().AddImageXObjectMapping (im->id);
tiledPatternContentContext->q();
tiledPatternContentContext->cm(w, 0, 0, h, 0, 0);
tiledPatternContentContext->Do(imageName);
tiledPatternContentContext->Q();
PDFHummus::EStatusCode st=
documentContext.EndTiledPatternAndRelease (tiledPattern);
if (st != PDFHummus::eSuccess)
convert_error << "Cannot flush tiled pattern "
<< im->u << "\n"; }
};
class pdf_pattern {
CONCRETE_NULL(pdf_pattern);
pdf_pattern (pdf_image _im, SI _w, SI _h, SI _sx, SI _sy,
double _scale_x, double _scale_y, ObjectIDType _id):
rep (tm_new<pdf_pattern_rep> (_im, _w, _h, _sx, _sy,
_scale_x, _scale_y, _id)) {};
};
CONCRETE_NULL_CODE(pdf_pattern);
void
pdf_hummus_renderer_rep::register_pattern_image (brush br, SI pixel) {
// debug_convert << "register_pattern_image\n";
if (is_nil (br) || br->get_type () != brush_pattern) {
convert_warning << "register_pattern_image: "
<< "brush with pattern expected\n";
return;
}
tree p= br->get_pattern ();
// debug_convert << p << "\n";
if (pattern_pool->contains(p)) return;
url u;
SI w, h;
get_pattern_data (u, w, h, br, pixel);
pdf_image image_pdf;
tree u_tree= tuple (u->t);
if (pattern_image_pool->contains(u_tree))
image_pdf= pattern_image_pool[u_tree];
else {
// debug_convert << " insert pattern image\n";
ObjectIDType image_id= pdfWriter.GetObjectsContext()
.GetInDirectObjectsRegistry().AllocateNewObjectID();
image_pdf= pdf_image (u, image_id);
pattern_image_pool(u_tree) = image_pdf;
}
// debug_convert << " insert pattern\n";
ObjectIDType id= pdfWriter.GetObjectsContext()
.GetInDirectObjectsRegistry().AllocateNewObjectID();
// debug_convert << "pdf_pattern " << ox << ", " << oy
// << ", " << pixel << ", " << shrinkf
// << ", " << zoomf << LF;
// debug_convert << " " << to_x(0) << ", " << to_y(0) << LF;
// debug_convert << " " << w << ", " << h << LF;
pdf_pattern p_pdf (image_pdf, w, h,
width + to_x(0), height, // FIXME ???
((double) default_dpi) / dpi,
((double) default_dpi) / dpi, id);
pattern_pool(p) = p_pdf;
}
/******************************************************************************
* Graphic state management * Graphic state management
******************************************************************************/ ******************************************************************************/
void void
pdf_hummus_renderer_rep::select_alpha (int a) { pdf_hummus_renderer_rep::select_alpha (int a) {
draw_glyphs ();
if (alpha != a) { if (alpha != a) {
alpha = a; alpha = a;
if (!alpha_id->contains(a)) { if (!alpha_id->contains(a)) {
ObjectIDType temp = pdfWriter.GetObjectsContext().GetInDirectObjectsRegist ry().AllocateNewObjectID(); ObjectIDType temp = pdfWriter.GetObjectsContext().GetInDirectObjectsRegist ry().AllocateNewObjectID();
alpha_id(a) = temp; alpha_id(a) = temp;
} }
std::string name = page->GetResourcesDictionary().AddExtGStateMapping(alpha_ id(a)); std::string name = page->GetResourcesDictionary().AddExtGStateMapping(alpha_ id(a));
contentContext->gs(name); contentContext->gs(name);
} }
} }
skipping to change at line 553 skipping to change at line 705
void void
pdf_hummus_renderer_rep::select_fill_color (color c) {; pdf_hummus_renderer_rep::select_fill_color (color c) {;
int r, g, b, a; int r, g, b, a;
get_rgb_color (c, r, g, b, a); get_rgb_color (c, r, g, b, a);
r= ((r*1000)/255); r= ((r*1000)/255);
g= ((g*1000)/255); g= ((g*1000)/255);
b= ((b*1000)/255); b= ((b*1000)/255);
a= ((a*1000)/255); a= ((a*1000)/255);
rgb c1 = rgb(r,g,b); rgb c1 = rgb(r,g,b);
if (fill_rgb != c1) { //if (fill_rgb != c1) {
double dr= ((double) r) / 1000.0; double dr= ((double) r) / 1000.0;
double dg= ((double) g) / 1000.0; double dg= ((double) g) / 1000.0;
double db= ((double) b) / 1000.0; double db= ((double) b) / 1000.0;
contentContext->rg(dr, dg, db); // non-stroking color contentContext->rg(dr, dg, db); // non-stroking color
fill_rgb = c1; fill_rgb = c1;
} //}
select_alpha(a); select_alpha(a);
} }
void void
pdf_hummus_renderer_rep::select_stroke_pattern (brush br) {
if (is_nil(br) || br->get_type () != brush_pattern) return;
tree p_tree= br->get_pattern ();
register_pattern_image (br, brushpx == -1 ? pixel : brushpx);
if (!pattern_pool->contains (p_tree)) {
convert_error << "select_stroke_pattern: "
<< "cannot find registered pattern\n";
return;
}
pdf_pattern p= pattern_pool[p_tree];
std::string patternName=
page->GetResourcesDictionary().AddPatternMapping(p->id);
contentContext->CS("Pattern");
contentContext->SCN((double*) NULL, 0, patternName);
}
void
pdf_hummus_renderer_rep::select_fill_pattern (brush br) {
if (is_nil(br) || br->get_type () != brush_pattern) return;
tree p_tree= br->get_pattern ();
register_pattern_image (br, brushpx==-1? pixel: brushpx);
if (!pattern_pool->contains (p_tree)) {
convert_error << "select_fill_pattern: "
<< "cannot find registered pattern\n";
return;
}
pdf_pattern p= pattern_pool[p_tree];
std::string patternName=
page->GetResourcesDictionary().AddPatternMapping(p->id);
contentContext->cs("Pattern");
contentContext->scn((double*) NULL, 0, patternName);
select_alpha ((1000*br->get_alpha ())/255);
}
void
pdf_hummus_renderer_rep::select_line_width (SI w) { pdf_hummus_renderer_rep::select_line_width (SI w) {
double pw = w /pixel; double pw = w /pixel;
//if (pw < 1) pw= 1; //if (pw < 1) pw= 1;
if (pw != current_width) { if (pw != current_width) {
contentContext->w(pw); contentContext->w(pw);
current_width = pw; current_width = pw;
} }
} }
pencil pencil
skipping to change at line 587 skipping to change at line 774
} }
brush brush
pdf_hummus_renderer_rep::get_background () { pdf_hummus_renderer_rep::get_background () {
// debug_convert << "get_background\n"; // debug_convert << "get_background\n";
return bgb; return bgb;
} }
void void
pdf_hummus_renderer_rep::set_pencil (pencil pen2) { pdf_hummus_renderer_rep::set_pencil (pencil pen2) {
// debug_convert << "set_color\n"; // debug_convert << "set_pencil\n";
draw_glyphs ();
pen= pen2; pen= pen2;
color c= pen->get_color ();
if (fg!=c) {
fg= c;
draw_glyphs();
select_fill_color (c);
select_stroke_color (c);
}
//if (pen->w != lw) {
// FIXME: apparently, the line width can be overidden by some of
// the graphical constructs (example file: newimpl.tm, in which
// the second dag was not printed using the right width)
lw= pen->get_width (); lw= pen->get_width ();
select_line_width (lw); select_line_width (lw);
//} color c= pen->get_color ();
fg= c;
select_fill_color (c);
select_stroke_color (c);
if (pen->get_type () == pencil_brush) {
// debug_convert << "pencil has brush type" << LF;
brush br= pen->get_brush ();
fgb= br;
select_fill_pattern (br);
select_stroke_pattern (br);
}
if (pen->get_cap () == cap_round)
contentContext->J(1); // round cap
else
contentContext->J(2); // square cap
contentContext->j(1); // round join
} }
void void
pdf_hummus_renderer_rep::set_brush (brush br) {
// debug_convert << "set_brush\n";
draw_glyphs();
fgb= br;
pen= pencil (br);
set_pencil (pen); // FIXME ???
if (is_nil (br)) return;
if (br->get_type () == brush_none) {
pen = pencil ();
fgb = brush ();
}
else {
select_fill_color (pen->get_color ());
select_stroke_color (pen->get_color ());
}
if (br->get_type () == brush_pattern) {
register_pattern_image (br, brushpx==-1? pixel: brushpx);
select_fill_pattern (br);
select_stroke_pattern (br);
}
//select_alpha (br->get_alpha ());
}
void
pdf_hummus_renderer_rep::set_background (brush b) { pdf_hummus_renderer_rep::set_background (brush b) {
// debug_convert << "set_background\n"; // debug_convert << "set_background\n";
//if (bgb==b) return; //if (bgb==b) return;
bgb= b; bgb= b;
bg= b->get_color (); bg= b->get_color ();
} }
/****************************************************************************** /******************************************************************************
* Raw images * Raw images
******************************************************************************/ ******************************************************************************/
skipping to change at line 720 skipping to change at line 934
ObjectIDType id; ObjectIDType id;
pdf_raw_image_rep (string _data, int _w, int _h, ObjectIDType _id) pdf_raw_image_rep (string _data, int _w, int _h, ObjectIDType _id)
: data(_data), w(_w), h(_h), id(_id) {} : data(_data), w(_w), h(_h), id(_id) {}
pdf_raw_image_rep () {} pdf_raw_image_rep () {}
void flush(PDFWriter& pdfw) { void flush(PDFWriter& pdfw) {
// debug_convert << "flushing :" << id << LF; // debug_convert << "flushing :" << id << LF;
create_pdf_image_raw (pdfw, data, w, h, id); create_pdf_image_raw (pdfw, data, w, h, id);
} }
}; // pdf_raw_image_ref }; // pdf_raw_image_rep
class pdf_raw_image { class pdf_raw_image {
CONCRETE_NULL(pdf_raw_image); CONCRETE_NULL(pdf_raw_image);
pdf_raw_image (string _data, int _w, int _h, ObjectIDType _id): pdf_raw_image (string _data, int _w, int _h, ObjectIDType _id):
rep (tm_new<pdf_raw_image_rep> (_data,_w,_h,_id)) {}; rep (tm_new<pdf_raw_image_rep> (_data,_w,_h,_id)) {};
}; };
CONCRETE_NULL_CODE(pdf_raw_image); CONCRETE_NULL_CODE(pdf_raw_image);
void void
skipping to change at line 971 skipping to change at line 1185
} }
if (!is_none (u)) { if (!is_none (u)) {
int pos= search_forwards (".", fontname); int pos= search_forwards (".", fontname);
string rname= (pos==-1? fontname: fontname (0, pos)); string rname= (pos==-1? fontname: fontname (0, pos));
//double fsize= font_size (fn->res_name); //double fsize= font_size (fn->res_name);
//char *_rname = as_charp(fname); //char *_rname = as_charp(fname);
PDFUsedFont* font; PDFUsedFont* font;
{ {
//debug_convert << "GetFontForFile " << u << LF; //debug_convert << "GetFontForFile " << u << LF;
#if (defined (__MINGW__) || defined (__MINGW32__))
// WIN is using 8bit encodings, but pdfwriter expects UTF8
// if path or file contains non-ascii characters we need an extra conversion
step.
c_string _u (western_to_utf8(concretize (u)));
#else
c_string _u (concretize (u)); c_string _u (concretize (u));
#endif
font = pdfWriter.GetFontForFile((char*)_u); font = pdfWriter.GetFontForFile((char*)_u);
//tm_delete_array(_rname); //tm_delete_array(_rname);
} }
if (font != 0) { if (font != 0) {
pdf_fonts (fontname)= font; pdf_fonts (fontname)= font;
} }
else { else {
convert_error << "pdf_hummus_renderer, problems with font: " << fname << " file " << u << LF; convert_error << "pdf_hummus_renderer, problems with font: " << fname << " file " << u << LF;
} }
skipping to change at line 1050 skipping to change at line 1270
} }
} }
static double static double
font_size (string name) { font_size (string name) {
int pos= search_backwards (".", name); int pos= search_backwards (".", name);
int szpos= pos-1; int szpos= pos-1;
while ((szpos>0) && is_numeric (name[szpos-1])) szpos--; while ((szpos>0) && is_numeric (name[szpos-1])) szpos--;
double size= as_double (name (szpos, pos)); double size= as_double (name (szpos, pos));
if (size == 0) size= 10; if (size == 0) size= 10;
double dpi= as_double (name (pos+1, N(name)-2)); int end= pos+1;
while (end < N(name) && is_numeric (name[end])) end++;
double dpi= as_double (name (pos+1, end));
double mag= (size) * (dpi/72.0); double mag= (size) * (dpi/72.0);
return mag; return mag;
} }
void void
pdf_hummus_renderer_rep::draw (int ch, font_glyphs fn, SI x, SI y) { pdf_hummus_renderer_rep::draw (int ch, font_glyphs fn, SI x, SI y) {
//debug_convert << "draw \"" << (char)ch << "\" " << ch << " " << fn->res_name << "\n"; //debug_convert << "draw \"" << (char)ch << "\" " << ch << " " << fn->res_name << "\n";
glyph gl= fn->get(ch); glyph gl= fn->get(ch);
if (is_nil (gl)) return; if (is_nil (gl)) return;
string fontname = fn->res_name; string fontname = fn->res_name;
skipping to change at line 1148 skipping to change at line 1370
contentContext->l(to_x (x2), to_y (y2)); contentContext->l(to_x (x2), to_y (y2));
contentContext->S(); contentContext->S();
} }
void void
pdf_hummus_renderer_rep::lines (array<SI> x, array<SI> y) { pdf_hummus_renderer_rep::lines (array<SI> x, array<SI> y) {
// debug_convert << "lines\n"; // debug_convert << "lines\n";
end_text (); end_text ();
int i, n= N(x); int i, n= N(x);
if ((N(y) != n) || (n<1)) return; if ((N(y) != n) || (n<1)) return;
end_text ();
contentContext->q();
if (pen->get_cap () == cap_round ||
(x[N(x)-1] == x[0] && y[N(y)-1] == y[0]))
contentContext->J(1); // round cap
else
contentContext->J(2); // square cap
contentContext->j(1); // round join
contentContext->m(to_x (x[0]), to_y (y[0])); contentContext->m(to_x (x[0]), to_y (y[0]));
for (i=1; i<n; i++) { for (i=1; i<n; i++) {
contentContext->l(to_x (x[i]), to_y (y[i])); contentContext->l(to_x (x[i]), to_y (y[i]));
} }
contentContext->S(); contentContext->S();
contentContext->Q();
} }
void void
pdf_hummus_renderer_rep::clear (SI x1, SI y1, SI x2, SI y2) { pdf_hummus_renderer_rep::clear (SI x1, SI y1, SI x2, SI y2) {
end_text (); end_text ();
double xx1= to_x (min (x1, x2)); double xx1= to_x (min (x1, x2));
double yy1= to_y (min (y1, y2)); double yy1= to_y (min (y1, y2));
double xx2= to_x (max (x1, x2)); double xx2= to_x (max (x1, x2));
double yy2= to_y (max (y1, y2)); double yy2= to_y (max (y1, y2));
// debug_convert << "clear" << xx1 << " " << yy1 << " " << xx2 << " " << yy2 < < LF; // debug_convert << "clear" << xx1 << " " << yy1 << " " << xx2 << " " << yy2 < < LF;
contentContext->q(); contentContext->q();
select_fill_color (bg); select_fill_color (bg);
select_fill_pattern (bgb);
contentContext->re(xx1, yy1, xx2-xx1, yy2-yy1); contentContext->re(xx1, yy1, xx2-xx1, yy2-yy1);
contentContext->h(); contentContext->h();
contentContext->f(); contentContext->f();
select_fill_color (fg); select_fill_color (fg);
select_fill_pattern (fgb);
contentContext->Q(); contentContext->Q();
} }
void void
pdf_hummus_renderer_rep::fill (SI x1, SI y1, SI x2, SI y2) { pdf_hummus_renderer_rep::fill (SI x1, SI y1, SI x2, SI y2) {
if ((x1<x2) && (y1<y2)) { if ((x1<x2) && (y1<y2)) {
end_text (); end_text ();
double xx1= to_x (min (x1, x2)); double xx1= to_x (min (x1, x2));
double yy1= to_y (min (y1, y2)); double yy1= to_y (min (y1, y2));
double xx2= to_x (max (x1, x2)); double xx2= to_x (max (x1, x2));
double yy2= to_y (max (y1, y2)); double yy2= to_y (max (y1, y2));
contentContext->re(xx1, yy1, xx2-xx1, yy2-yy1); contentContext->re(xx1, yy1, xx2-xx1, yy2-yy1);
contentContext->h(); contentContext->h();
contentContext->f(); contentContext->f(); // FIXME Winding
} }
} }
void void
pdf_hummus_renderer_rep::bezier_arc (SI x1, SI y1, SI x2, SI y2, int alpha, int delta, bool filled) pdf_hummus_renderer_rep::bezier_arc (SI x1, SI y1, SI x2, SI y2, int alpha, int delta, bool filled)
{ {
// PDF can describe only cubic bezier paths, so we have to make up the arc wit h them // PDF can describe only cubic bezier paths, so we have to make up the arc wit h them
// Since this is not mathematically exact, we minimize errors by drawing bezie // Since this is not mathematically exact, we minimize errors by drawing bezie
rs sub-arcs of at most 90° rs sub-arcs of at most 90??
end_text ();
contentContext->q(); // save graphics state contentContext->q(); // save graphics state
double xx1 = to_x(x1), yy1 = to_y(y1), xx2 = to_x(x2), yy2 = to_y(y2); double xx1 = to_x(x1), yy1 = to_y(y1), xx2 = to_x(x2), yy2 = to_y(y2);
double cx = (xx1+xx2)/2, cy = (yy1+yy2)/2; double cx = (xx1+xx2)/2, cy = (yy1+yy2)/2;
double rx = (xx2-xx1)/2, ry = (yy2-yy1)/2; double rx = (xx2-xx1)/2, ry = (yy2-yy1)/2;
contentContext->cm(1, 0, 0, 1, cx, cy); // centering contentContext->cm(1, 0, 0, 1, cx, cy); // centering
//we can't apply scale here because in pdf the pen is scaled too //we can't apply scale here because in pdf the pen is scaled too
int i=1+abs(delta)/(90*64); //number of sub-arcs needed int i=1+abs(delta)/(90*64); //number of sub-arcs needed
if ((abs(delta)%(90*64))==0) i-- ; //correction needed if exact multiple of 90° if ((abs(delta)%(90*64))==0) i-- ; //correction needed if exact multiple of 90??
double phi= 2.0*M_PI*(delta)/(i*360.0*64.0); //angular span of each sub-a rc double phi= 2.0*M_PI*(delta)/(i*360.0*64.0); //angular span of each sub-a rc
double a = 2.0*M_PI*(alpha)/(360.0*64.0); //start angle in radians double a = 2.0*M_PI*(alpha)/(360.0*64.0); //start angle in radians
// Control points for an arc of radius 1, centered on the x-axis and spanning phi degrees // Control points for an arc of radius 1, centered on the x-axis and spanning phi degrees
// from: http://www.tinaja.com/glib/bezcirc2.pdf // from: http://www.tinaja.com/glib/bezcirc2.pdf
double sphi = sin(phi/2), cphi = cos(phi/2); double sphi = sin(phi/2), cphi = cos(phi/2);
double bx0 = cphi, by0 = -sphi; double bx0 = cphi, by0 = -sphi;
double bx1 = (4.0-bx0)/3.0, by1 = (1.0-bx0)*(3.0-bx0)/(3.0*by0); double bx1 = (4.0-bx0)/3.0, by1 = (1.0-bx0)*(3.0-bx0)/(3.0*by0);
double bx2 = bx1, by2 = -by1; double bx2 = bx1, by2 = -by1;
double bx3 = bx0, by3 = -by0; double bx3 = bx0, by3 = -by0;
skipping to change at line 1253 skipping to change at line 1486
void void
pdf_hummus_renderer_rep::fill_arc (SI x1, SI y1, SI x2, SI y2, int alpha, int de lta) { pdf_hummus_renderer_rep::fill_arc (SI x1, SI y1, SI x2, SI y2, int alpha, int de lta) {
// debug_convert << "fill_arc\n"; // debug_convert << "fill_arc\n";
end_text (); end_text ();
bezier_arc(x1, y1, x2, y2, alpha, delta, true); bezier_arc(x1, y1, x2, y2, alpha, delta, true);
} }
void void
pdf_hummus_renderer_rep::polygon (array<SI> x, array<SI> y, bool convex) { pdf_hummus_renderer_rep::polygon (array<SI> x, array<SI> y, bool convex) {
end_text ();
// debug_convert << "polygon\n"; // debug_convert << "polygon\n";
int i, n= N(x); int i, n= N(x);
if ((N(y) != n) || (n<1)) return; if ((N(y) != n) || (n<1)) return;
end_text ();
contentContext->m(to_x (x[0]), to_y (y[0])); contentContext->m(to_x (x[0]), to_y (y[0]));
for (i=1; i<n; i++) { for (i=1; i<n; i++)
contentContext->l(to_x (x[i]), to_y (y[i])); contentContext->l(to_x (x[i]), to_y (y[i]));
}
contentContext->h(); contentContext->h();
contentContext->f(); if (convex)
contentContext->f(); // odd-even
else
contentContext->fStar(); // nonzero winding
} }
class pdf_image_rep : public concrete_struct
{
public:
url u;
int w,h;
ObjectIDType id;
pdf_image_rep(url _u, ObjectIDType _id)
: u(_u), id(_id)
{ image_size (u, w, h); }
~pdf_image_rep() {}
bool flush_jpg (PDFWriter& pdfw, url image);
bool flush_raster (PDFWriter& pdfw, url image);
void flush (PDFWriter& pdfw);
}; // class pdf_image_ref
class pdf_image {
CONCRETE_NULL(pdf_image);
pdf_image (url _u, ObjectIDType _id):
rep (tm_new<pdf_image_rep> (_u,_id)) {};
};
CONCRETE_NULL_CODE(pdf_image);
void void
pdf_image_rep::flush (PDFWriter& pdfw) pdf_image_rep::flush (PDFWriter& pdfw)
{ {
url name= resolve (u); url name= resolve (u);
if (is_none (name)) if (is_none (name))
name= "$TEXMACS_PATH/misc/pixmaps/unknown.ps"; name= "$TEXMACS_PATH/misc/pixmaps/unknown.ps";
// do not use "convert" to convert from eps to pdf since it rasterizes the pic
ture
url temp; url temp;
string s= suffix (name); string s= suffix (name);
double scale_x = 1, scale_y = 1;
// debug_convert << "flushing :" << fname << LF; // debug_convert << "flushing :" << fname << LF;
if (s == "pdf") {
if (s == "pdf") { temp=name;
temp=name; name=url_none();
name=url_none(); }
} else { else {
temp= url_temp (".pdf"); temp= url_temp (".pdf");
// first try to work out inclusion using our own tools
if ( s != "ps" && s != "eps") { // note that we have to return since flush_raster and flush_jpg
// * generic image format // already build the appopriate Form XObject into the PDF
// try to work out inclusion using our own tools if ((s == "jpg") || (s == "jpeg"))
// note that we have to return since flush_raster if (flush_jpg(pdfw, name)) return;
// already build the appopriate Form XObject into the PDF
// other formats we generate a pdf (with available converters) that we'll embb
if ((s == "jpg") || (s == "jpeg")) ed
if (flush_jpg(pdfw, name)) return; image_to_pdf (name, temp, w, h, 300);
// the 300 dpi setting is the maximum dpi of raster images that will be genera
if (!(s == "png" && exists_in_path ("convert"))) ted:
if (flush_raster (pdfw, name)) return; // images that are to dense will de downsampled to keep file small
// (other are not up-sampled)
// if this fails try using convert from ImageMagik // dpi DOES NOT apply for vector images that we know how to handle : eps, svg(
// to convert to pdf if inkscape present)
string cmd= "convert"; //
system (cmd, sys_concretize (name), sys_concretize(temp)) // TODO: make the max dpi setting smarter (printer resolution, preference ...)
; }
} else {
// * ps or eps
// use gs to convert eps to pdf and take care of properly
handling the bounding box
// the resulting pdf image will always start at 0,0.
int bx1, by1, bx2, by2; // bounding box
ps_bounding_box(u, bx1, by1, bx2, by2);
string cmd= gs_prefix();
cmd << " -dQUIET -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwr
ite ";
cmd << " -sOutputFile=" << sys_concretize(temp) << " ";
cmd << " -c \" << /PageSize [ " << as_string(bx2-bx1) <<
" " << as_string(by2-by1)
<< " ] >> setpagedevice gsave "
<< as_string(-bx1) << " " << as_string(-by1) << "
translate \" ";
cmd << " -f " << sys_concretize (name);
cmd << " -c \" grestore \" ";
// debug_convert << cmd << LF;
system(cmd);
scale_x = w/((double)(bx2-bx1));
scale_y = h/((double)(by2-by1));
}
}
EStatusCode status = PDFHummus::eFailure; EStatusCode status = PDFHummus::eFailure;
DocumentContext& dc = pdfw.GetDocumentContext(); DocumentContext& dc = pdfw.GetDocumentContext();
PDFRectangle cropBox (0, 0, w, h); #if (defined (__MINGW__) || defined (__MINGW32__))
double tMat[6] = { scale_x, 0, 0, scale_y, 0, 0}; PDFDocumentCopyingContext *copyingContext = pdfw.CreatePDFCopyingContext(as_ch
arp(western_to_utf8(concretize(temp))));
#else
PDFDocumentCopyingContext *copyingContext = pdfw.CreatePDFCopyingContext(as_ch arp(concretize(temp))); PDFDocumentCopyingContext *copyingContext = pdfw.CreatePDFCopyingContext(as_ch arp(concretize(temp)));
#endif
if(copyingContext) { if(copyingContext) {
PDFFormXObject *form = dc.StartFormXObject(cropBox, id, tMat); PDFPageInput pageInput(copyingContext->GetSourceDocumentParser(),
copyingContext->GetSourceDocumentParser()
->ParsePage(0));
double tMat[6] ={ 1,0, 0, 1, 0, 0} ;
PDFRectangle cropBox (0,0,0,0);
pdf_image_info (temp, w, h, cropBox, tMat, pageInput);
PDFFormXObject *form = dc.StartFormXObject(cropBox, id, tMat, true);
status = copyingContext->MergePDFPageToFormXObject(form,0); status = copyingContext->MergePDFPageToFormXObject(form,0);
if(status == eSuccess) pdfw.EndFormXObjectAndRelease(form); if(status == eSuccess) pdfw.EndFormXObjectAndRelease(form);
delete copyingContext; delete copyingContext;
} }
if(!is_none(name)) remove (temp); if(!is_none(name)) remove (temp);
if (status == PDFHummus::eFailure) { if (status == PDFHummus::eFailure) {
convert_error << "pdf_hummus, failed to include image file: " convert_error << "pdf_hummus, failed to include image file: "
<< temp << LF; << temp << LF;
} }
} }
void
hummus_pdf_image_size (url image, int& w, int& h) {
InputFile pdfFile;
PDFParser* parser= new PDFParser();
#if (defined (__MINGW__) || defined (__MINGW32__))
pdfFile.OpenFile(as_charp(western_to_utf8(concretize(image))));
#else
pdfFile.OpenFile(as_charp(concretize(image)));
#endif
EStatusCode status = parser->StartPDFParsing(pdfFile.GetInputStream());
if (status != PDFHummus::eFailure) {
PDFPageInput pageInput(parser, parser->ParsePage(0));
double tMat[6] ={ 1,0, 0, 1, 0, 0};
PDFRectangle cropBox (0,0,0,0);
pdf_image_info (image, w, h, cropBox, tMat, pageInput);
delete(parser);
}
else {
convert_error << "pdf_hummus, failed to get image size for: "
<<image << LF;
w=h=0;
}
}
void
pdf_image_info (url image, int& w, int& h, PDFRectangle& cropBox, double (&tMat)
[6], PDFPageInput& pageInput) {
int rot= (pageInput.GetRotate())%360;
if (rot < 0) rot +=360;
cropBox=pageInput.GetCropBox();
//PDFRectangle mediaBox=pageInput.GetMediaBox();
w= cropBox.UpperRightX-cropBox.LowerLeftX;
h= cropBox.UpperRightY-cropBox.LowerLeftY;
if (DEBUG_CONVERT) {
debug_convert << "hummus_pdf_image_info:"<< LF
<< "image ="<<image<<LF
<< "crop box={"<<cropBox.LowerLeftX<< ", "<<cropBox.UpperRightX
<< ", "<<cropBox.LowerLeftY<< ", "<<cropBox.UpperRightY<<"}"<< LF
<< "w,h={"<<w<< ", "<<h <<"}"<< LF;
}
int z;
switch (rot) {
case 0 :
tMat[0] = 1;
tMat[1] = 0;
tMat[2] = 0;
tMat[3] = 1;
tMat[4] = -cropBox.LowerLeftX;
tMat[5] = -cropBox.LowerLeftY;
break;
case 90 :
tMat[0] = 0;
tMat[1] = -1 ;
tMat[2] = 1;
tMat[3] = 0;
tMat[4] = -cropBox.LowerLeftY;
tMat[5] = cropBox.UpperRightX ;
z = w;
w = h;
h = z;
break;
case 180 :
tMat[0] = -1;
tMat[1] = 0;
tMat[2] = 0;
tMat[3] = -1;
tMat[4] = cropBox.UpperRightX ;
tMat[5] = cropBox.UpperRightY ;
break;
case 270 :
tMat[0] = 0;
tMat[1] = 1 ;
tMat[2] = -1;
tMat[3] = 0;
tMat[4] = cropBox.UpperRightY ;
tMat[5] = -cropBox.LowerLeftX;
z = w;
w = h;
h = z;
break;
default :
convert_error << "unexpected rotate()="<< rot<<" in image "<<image << LF;
}
if (DEBUG_CONVERT) debug_convert << "degrees image rotated :"<< rot << LF
<< "dx,dy={"<<tMat[4]<< ", "<<tMat[5] <<"}"<< LF;
}
/* not used any longer
bool bool
pdf_image_rep::flush_raster (PDFWriter& pdfw, url image) { pdf_image_rep::flush_raster (PDFWriter& pdfw, url image) {
string data, mask, palette; string data, mask, palette;
int iw = 0, ih =0; int iw = 0, ih =0;
#ifdef QTTEXMACS #ifdef QTTEXMACS
qt_image_data (image, iw, ih, data, palette, mask); qt_image_data (image, iw, ih, data, palette, mask);
#endif #endif
if ((iw==0)||(ih==0)) return false; if ((iw==0)||(ih==0)) return false;
skipping to change at line 1478 skipping to change at line 1753
delete imageXObject; imageXObject = NULL; delete imageXObject; imageXObject = NULL;
EStatusCode status = pdfw.EndFormXObjectAndRelease(xobjectForm); EStatusCode status = pdfw.EndFormXObjectAndRelease(xobjectForm);
(void) status; (void) status;
} while (false); } while (false);
} }
return true; return true;
} }
*/
bool
pdf_image_rep::flush_for_pattern (PDFWriter& pdfw) {
string data, mask, palette;
int iw = 0, ih =0;
#ifdef QTTEXMACS
qt_image_data (u, iw, ih, data, palette, mask);
#endif
if ((iw==0)||(ih==0)) return false;
ObjectsContext& objectsContext = pdfw.GetObjectsContext();
objectsContext.StartNewIndirectObject(id);
// write stream dictionary
DictionaryContext* imageContext = objectsContext.StartDictionary();
// type
imageContext->WriteKey(scType);
imageContext->WriteNameValue(scXObject);
// subtype
imageContext->WriteKey(scSubType);
imageContext->WriteNameValue(scImage);
// Width
imageContext->WriteKey(scWidth);
imageContext->WriteIntegerValue(iw);
// Height
imageContext->WriteKey(scHeight);
imageContext->WriteIntegerValue(ih);
// Bits Per Component
imageContext->WriteKey(scBitsPerComponent);
imageContext->WriteIntegerValue(8);
// Color Space and Decode Array if necessary
imageContext->WriteKey(scColorSpace);
imageContext->WriteNameValue(scDeviceRGB);
// Data stream
PDFStream* imageStream = objectsContext.StartPDFStream(imageContext, true);
OutputStreamTraits outputTraits(imageStream->GetWriteStream());
c_string buf (data);
InputByteArrayStream reader((IOBasicTypes::Byte*)(char *)buf, N(data));
EStatusCode status = outputTraits.CopyToOutputStream(&reader);
if(status != PDFHummus::eSuccess) {
delete imageStream;
return false;
}
objectsContext.EndPDFStream(imageStream);
delete imageStream;
objectsContext.EndIndirectObject();
return true;
}
bool bool
pdf_image_rep::flush_jpg (PDFWriter& pdfw, url image) { pdf_image_rep::flush_jpg (PDFWriter& pdfw, url image) {
// direct embedding of jpg images // direct embedding of jpg images
// the JPG parsing code is an adaptation of the code in writejpg.w // the JPG parsing code is an adaptation of the code in writejpg.w
// from the luatex program // from the luatex program
// https://foundry.supelec.fr/svn/luatex/tags/beta-0.76.0/source/texk/web2c/luat exdir/image/writejpg.w // https://foundry.supelec.fr/svn/luatex/tags/beta-0.76.0/source/texk/web2c/luat exdir/image/writejpg.w
skipping to change at line 1806 skipping to change at line 2134
{ {
// flush all images // flush all images
iterator<tree> it = iterate (image_pool); iterator<tree> it = iterate (image_pool);
while (it->busy()) { while (it->busy()) {
pdf_image im = image_pool[it->next()]; pdf_image im = image_pool[it->next()];
im->flush(pdfWriter); im->flush(pdfWriter);
} }
} }
void void
pdf_hummus_renderer_rep::flush_patterns ()
{
// flush all pattern images
iterator<tree> it = iterate (pattern_image_pool);
while (it->busy()) {
pdf_image im = pattern_image_pool[it->next()];
im->flush_for_pattern(pdfWriter);
}
// flush all patterns
it = iterate (pattern_pool);
while (it->busy()) {
pdf_pattern pa = pattern_pool[it->next()];
pa->flush(pdfWriter);
}
}
void
pdf_hummus_renderer_rep::image ( pdf_hummus_renderer_rep::image (
url u, SI w, SI h, SI x, SI y, int alpha) url u, SI w, SI h, SI x, SI y, int alpha)
{ {
// debug_convert << "image " << u << LF; // debug_convert << "image " << u << LF;
(void) alpha; // FIXME
tree lookup= tuple (u->t); tree lookup= tuple (u->t);
pdf_image im = ( image_pool->contains(lookup) ? image_pool[lookup] : pdf_image () ); pdf_image im = ( image_pool->contains(lookup) ? image_pool[lookup] : pdf_image () );
if (is_nil(im)) { if (is_nil(im)) {
im = pdf_image(u, pdfWriter.GetObjectsContext().GetInDirectObjectsRegistry() .AllocateNewObjectID()); im = pdf_image(u, pdfWriter.GetObjectsContext().GetInDirectObjectsRegistry() .AllocateNewObjectID());
image_pool(lookup) = im; image_pool(lookup) = im;
} }
if (is_nil(im)) return; if (is_nil(im)) return;
end_text(); end_text();
contentContext->q(); contentContext->q();
contentContext->cm(((double)w)/(pixel*(double)im->w), 0, 0, ((double)h)/(pixel double ratio= ((double)h)/(pixel*(double)im->h);
*(double)im->h), to_x(x), to_y(y)); contentContext->cm(((double)w)/(pixel*(double)im->w), 0, 0,
((double)h)/(pixel*(double)im->h),
to_x(x - ((SI) (ratio*PIXEL))),
to_y(y - ((SI) (ratio*PIXEL))));
std::string pdfFormName = page->GetResourcesDictionary().AddFormXObjectMapping (im->id); std::string pdfFormName = page->GetResourcesDictionary().AddFormXObjectMapping (im->id);
select_alpha((1000 * alpha) / 255);
contentContext->Do(pdfFormName); contentContext->Do(pdfFormName);
//contentContext->re(0,0,im->w,im->h); //contentContext->re(0,0,im->w,im->h);
contentContext->S(); //contentContext->S();
contentContext->Q(); contentContext->Q();
} }
void void
pdf_hummus_renderer_rep::draw_picture (picture p, SI x, SI y, int alpha) { pdf_hummus_renderer_rep::draw_picture (picture p, SI x, SI y, int alpha) {
(void) alpha; // FIXME
int w= p->get_width (), h= p->get_height (); int w= p->get_width (), h= p->get_height ();
int ox= p->get_origin_x (), oy= p->get_origin_y (); int ox= p->get_origin_x (), oy= p->get_origin_y ();
//int pixel= 5*PIXEL;
string name= "picture"; string name= "picture";
string eps= picture_as_eps (p, 600); string eps= picture_as_eps (p, 600);
#if 0 x -= (int) (5 * ox * pixel);
int x1= -ox; y -= (int) (5 * oy * pixel);
int y1= -oy;
int x2= w - ox;
int y2= h - oy;
#endif
x -= (int) 2.06 * ox * pixel; // FIXME: where does the magic 2.06 come from?
y -= (int) 2.06 * oy * pixel;
url temp= url_temp (".eps"); url temp= url_temp (".eps");
save_string(temp, eps); save_string (temp, eps);
image (temp, w * pixel, h * pixel, x, y, 255); image (temp, 5 * w * pixel, 5 * h * pixel, x, y, alpha);
remove(temp); temp_images << temp;
} }
void void
pdf_hummus_renderer_rep::draw_scalable (scalable im, SI x, SI y, int alpha) { pdf_hummus_renderer_rep::draw_scalable (scalable im, SI x, SI y, int alpha) {
if (im->get_type () != scalable_image) if (im->get_type () != scalable_image)
renderer_rep::draw_scalable (im, x, y, alpha); renderer_rep::draw_scalable (im, x, y, alpha);
else { else {
url u= im->get_name (); url u= im->get_name ();
rectangle r= im->get_logical_extents (); rectangle r= im->get_logical_extents ();
SI w= r->x2, h= r->y2; SI w= r->x2 - r->x1, h= r->y2 - r->y1;
//string ps_image= ps_load (u); int _ox= r->x1, _oy= r->y1;
//string imtext= is_ramdisc (u)? "inline image": as_string (u); x -= (int) 2.06 * _ox * pixel; // FIXME: where does the magic 2.06 come from
//int x1, y1, x2, y2; ?
//ps_bounding_box (u, x1, y1, x2, y2); y -= (int) 2.06 * _oy * pixel;
image (u,w, h, x, y, alpha); image (u, w, h, x, y, alpha);
} }
} }
/****************************************************************************** /******************************************************************************
* Conversions between strings and std::string * Conversions between strings and std::string
******************************************************************************/ ******************************************************************************/
string string
std_string_to_string (std::string str) { std_string_to_string (std::string str) {
string r; string r;
skipping to change at line 2126 skipping to change at line 2465
info.Producer= as_hummus_string (producer); info.Producer= as_hummus_string (producer);
} }
/****************************************************************************** /******************************************************************************
* shadow rendering is trivial on pdf * shadow rendering is trivial on pdf
******************************************************************************/ ******************************************************************************/
void void
pdf_hummus_renderer_rep::fetch (SI x1, SI y1, SI x2, SI y2, renderer ren, SI x, SI y) { pdf_hummus_renderer_rep::fetch (SI x1, SI y1, SI x2, SI y2, renderer ren, SI x, SI y) {
// debug_convert << "fetch\n"; // debug_convert << "fetch\n";
/* (void) x1; (void) y1; (void) x2; (void) y2; (void) x1; (void) y1; (void) x2; (void) y2;
(void) ren; (void) x; (void) y;*/ (void) ren; (void) x; (void) y;
} }
void void
pdf_hummus_renderer_rep::new_shadow (renderer& ren) { pdf_hummus_renderer_rep::new_shadow (renderer& ren) {
// debug_convert << "new_shadow\n"; // debug_convert << "new_shadow\n";
// (void) ren; (void) ren;
} }
void void
pdf_hummus_renderer_rep::delete_shadow (renderer& ren) { pdf_hummus_renderer_rep::delete_shadow (renderer& ren) {
// debug_convert << "delete_shadow\n"; // debug_convert << "delete_shadow\n";
// (void) ren; (void) ren;
} }
void void
pdf_hummus_renderer_rep::get_shadow (renderer ren, SI x1, SI y1, SI x2, SI y2) { pdf_hummus_renderer_rep::get_shadow (renderer ren, SI x1, SI y1, SI x2, SI y2) {
// debug_convert << "get_shadow\n"; // debug_convert << "get_shadow\n";
// (void) ren; (void) x1; (void) y1; (void) x2; (void) y2; (void) ren; (void) x1; (void) y1; (void) x2; (void) y2;
} }
void void
pdf_hummus_renderer_rep::put_shadow (renderer ren, SI x1, SI y1, SI x2, SI y2) { pdf_hummus_renderer_rep::put_shadow (renderer ren, SI x1, SI y1, SI x2, SI y2) {
// debug_convert << "put_shadow\n"; // debug_convert << "put_shadow\n";
// (void) ren; (void) x1; (void) y1; (void) x2; (void) y2; (void) ren; (void) x1; (void) y1; (void) x2; (void) y2;
} }
void void
pdf_hummus_renderer_rep::apply_shadow (SI x1, SI y1, SI x2, SI y2) { pdf_hummus_renderer_rep::apply_shadow (SI x1, SI y1, SI x2, SI y2) {
// debug_convert << "apply_shadow\n"; // debug_convert << "apply_shadow\n";
// (void) x1; (void) y1; (void) x2; (void) y2; (void) x1; (void) y1; (void) x2; (void) y2;
} }
renderer renderer
pdf_hummus_renderer_rep::shadow (picture& pic, SI x1, SI y1, SI x2, SI y2) { pdf_hummus_renderer_rep::shadow (picture& pic, SI x1, SI y1, SI x2, SI y2) {
double old_zoomf= this->zoomf;
set_zoom_factor (1.0);
renderer ren= renderer_rep::shadow (pic, x1, y1, x2, y2); renderer ren= renderer_rep::shadow (pic, x1, y1, x2, y2);
ren->set_zoom_factor (1.0); set_zoom_factor (old_zoomf);
return ren; return ren;
} }
/****************************************************************************** /******************************************************************************
* user interface * user interface
******************************************************************************/ ******************************************************************************/
renderer renderer
pdf_hummus_renderer (url pdf_file_name, int dpi, int nr_pages, pdf_hummus_renderer (url pdf_file_name, int dpi, int nr_pages,
string page_type, bool landscape, double paper_w, double pa per_h) string page_type, bool landscape, double paper_w, double pa per_h)
{ {
//cout << "Hummus print to " << pdf_file_name << " at " << dpi << " dpi\n";
page_type= as_string (call ("standard-paper-size", object (page_type))); page_type= as_string (call ("standard-paper-size", object (page_type)));
return tm_new<pdf_hummus_renderer_rep> (pdf_file_name, dpi, nr_pages, return tm_new<pdf_hummus_renderer_rep> (pdf_file_name, dpi, nr_pages,
page_type, landscape, paper_w, paper_h); page_type, landscape, paper_w, paper_h);
} }
 End of changes. 69 change blocks. 
150 lines changed or deleted 496 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS