X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fpdf.cc;h=80c4e3373fe36b4b74db6b5158987a069b800889;hb=4300e287a18cbc4569c79f8e8445609dc7d4546a;hp=b319e162787d7c9dcba63cf00b5f5c3012d8e894;hpb=a4c5ddfc34f2ad0bf4311a1582bde3be060ce8b8;p=lilypond.git diff --git a/lily/pdf.cc b/lily/pdf.cc index b319e16278..80c4e3373f 100644 --- a/lily/pdf.cc +++ b/lily/pdf.cc @@ -1,5 +1,5 @@ /* - pdf.cc -- implement Pdf output routines. + pdf.cc -- implement Pdf output routines. source file of the GNU LilyPond music typesetter @@ -11,9 +11,9 @@ #include "pdf.hh" #include "ly-smobs.icc" -IMPLEMENT_SMOBS(Pdf_object); -IMPLEMENT_DEFAULT_EQUAL_P(Pdf_object); -IMPLEMENT_TYPE_P(Pdf_object, "pdf-object?"); +IMPLEMENT_SMOBS (Pdf_object); +IMPLEMENT_DEFAULT_EQUAL_P (Pdf_object); +IMPLEMENT_TYPE_P (Pdf_object, "pdf-object?"); Pdf_object::Pdf_object () @@ -22,15 +22,20 @@ Pdf_object::Pdf_object () value_ = SCM_BOOL_F; written_ = false; byte_count_ = 0; - + smobify_self (); } +Pdf_object::~Pdf_object () +{ + +} bool Pdf_object::is_dict () const { - return scm_is_pair (value_) && scm_car (value_) == ly_symbol2scm ("dictionary"); + return scm_is_pair (value_) + && scm_car (value_) == ly_symbol2scm ("dictionary"); } bool @@ -39,10 +44,6 @@ Pdf_object::is_indirect () const return object_number_ > 0; } -Pdf_object::~Pdf_object() -{ - -} void Pdf_object::typecheck (SCM val) @@ -70,7 +71,7 @@ Pdf_object::typecheck (SCM val) else if (tag == ly_symbol2scm ("stream")) { if (!scm_is_string (scm_cdr (val))) - error ("stream argument should be string"); + error ("stream argument should be string"); } else { @@ -102,14 +103,14 @@ Pdf_object::set_value (SCM val) typecheck (val); - value_ = val; + value_ = val; } SCM Pdf_object::mark_smob (SCM smob) { Pdf_object *p = (Pdf_object*) SCM_CELL_WORD_1 (smob); - return p->value_; + return p->value_; } int @@ -135,7 +136,7 @@ Pdf_object::write_dict (FILE *file, SCM alist) Pdf_object *val = unsmob_pdf_object (scm_cdar (s)); assert (val && key); - + key->write_to_file (file, false); val->write_to_file (file, false); } @@ -159,12 +160,12 @@ Pdf_object::write_vector (FILE *file, SCM vec) } -void +void Pdf_object::write_stream (FILE *file, SCM scmstr) { String str = ly_scm2string (scmstr); - fprintf (file, "<< /Length %d >>\nstream\n" , str.length()); - fwrite (str.get_bytes(), str.length(), sizeof(Byte), file); + fprintf (file, "<< /Length %d >>\nstream\n" , str.length ()); + fwrite (str.get_bytes (), str.length (), sizeof (Byte), file); fputs ("endstream" , file); } @@ -191,7 +192,7 @@ Pdf_object::to_string () const else if (scm_is_number (value_)) return ::to_string (scm_to_double (value_)); else if (scm_is_symbol (value_)) - return "/" + ly_symbol2string (value_) ; + return "/" + ly_symbol2string (value_); else if (scm_is_string (value_)) return "(" + escape_string (ly_scm2string (value_)) + ")"; @@ -206,32 +207,26 @@ Pdf_object::write_to_file (FILE* file, bool dump_definition) const fprintf (file, "%d 0 R", object_number_); return; } - + if (scm_is_vector (value_)) write_vector (file, value_); else if (scm_is_pair (value_)) { SCM tag = scm_car (value_); if (tag == ly_symbol2scm ("dictionary")) - { - write_dict (file, scm_cdr (value_)); - } + write_dict (file, scm_cdr (value_)); else if (tag == ly_symbol2scm ("stream")) - { - write_stream (file, scm_cdr (value_)); - } + write_stream (file, scm_cdr (value_)); else - { - assert (false); - } + assert (false); } else { String str = to_string (); - fwrite (str.get_bytes(), str.length(), sizeof(Byte), file); - + fwrite (str.get_bytes (), str.length (), sizeof (Byte), file); + fputc (dump_definition ? '\n' : ' ', file); - return ; + return; } } @@ -242,26 +237,28 @@ Pdf_object::is_stream () const } /****************************************************************/ - -IMPLEMENT_SMOBS(Pdf_file); -IMPLEMENT_DEFAULT_EQUAL_P(Pdf_file); -IMPLEMENT_TYPE_P(Pdf_file, "pdf-file?"); + +IMPLEMENT_SMOBS (Pdf_file); +IMPLEMENT_DEFAULT_EQUAL_P (Pdf_file); +IMPLEMENT_TYPE_P (Pdf_file, "pdf-file?"); Pdf_file::Pdf_file (String name) { char const *cp = name.to_str0 (); root_object_ = NULL; - file_ = fopen (cp, "w"); + file_ = fopen (cp, "w"); if (!file_) - { - error (_f ("Can't open file %s", cp)); - } + error (_f ("can't open file: `%s'", cp)); write_header (); smobify_self (); } +Pdf_file::~Pdf_file () +{ +} + void Pdf_file::write_header () { @@ -271,12 +268,12 @@ Pdf_file::write_header () void Pdf_file::make_indirect (Pdf_object *obj) { - assert (!obj->is_indirect()); + assert (!obj->is_indirect ()); /* Skip 0 , the null object. - */ - obj->object_number_ = indirect_objects_.size() + 1; + */ + obj->object_number_ = indirect_objects_.size () + 1; indirect_objects_.push (obj); } @@ -284,24 +281,20 @@ void Pdf_file::write_object (Pdf_object *obj) { assert (!obj->written_); - if (obj->is_stream() && !obj->is_indirect ()) - { - make_indirect (obj); - } - - if (obj->is_indirect()) + if (obj->is_stream () && !obj->is_indirect ()) + make_indirect (obj); + + if (obj->is_indirect ()) { obj->byte_count_ = ftell (file_); fprintf (file_, "%d obj\n", obj->object_number_); } - + obj->write_to_file (file_, true); obj->written_ = true; if (obj->is_indirect ()) - { - fprintf (file_, " \nendobj\n"); - } + fprintf (file_, " \nendobj\n"); } void @@ -312,58 +305,47 @@ Pdf_file::terminate () if (!indirect_objects_[i]->written_) write_object (indirect_objects_[i]); } - + write_trailer (); fclose (file_); file_ = NULL; } -Pdf_file::~Pdf_file() -{ -} - - void Pdf_file::set_root_document (Pdf_object*obj) { if (root_object_) - { - error ("Can have only one root object"); - } - + error ("Can have only one root object"); + root_object_ = obj; if (!obj->is_indirect ()) - { - make_indirect (obj); - } + make_indirect (obj); } void Pdf_file::write_trailer () { long xref_offset = ftell (file_); - fprintf (file_, "xref\n%d %d\n", 0, indirect_objects_.size() + 1); + fprintf (file_, "xref\n%d %d\n", 0, indirect_objects_.size () + 1); char const *xref_entry = "%010d %05d %c \n"; fprintf (file_, xref_entry, 0, 65535, 'f'); - for (int i = 0; i < indirect_objects_.size(); i++) - { - fprintf (file_, xref_entry, indirect_objects_[i]->byte_count_, 0, 'n'); - } + for (int i = 0; i < indirect_objects_.size (); i++) + fprintf (file_, xref_entry, indirect_objects_[i]->byte_count_, 0, 'n'); fprintf (file_, "trailer\n<< /Size %d /Root %d 0 R >>", - indirect_objects_.size () + 1, (root_object_) ? root_object_->object_number_ : 0); + indirect_objects_.size () + 1, + (root_object_) ? root_object_->object_number_ : 0); fprintf (file_, "\nstartxref\n%d\n", xref_offset); fputs ("%%EOF", file_); } - SCM Pdf_file::mark_smob (SCM f) { - Pdf_file *pfile = (Pdf_file*) SCM_CELL_WORD_1(f); - for (int i = 0; i < pfile->indirect_objects_.size(); i++) - scm_gc_mark (pfile->indirect_objects_[i]->self_scm()); + Pdf_file *pfile = (Pdf_file*) SCM_CELL_WORD_1 (f); + for (int i = 0; i < pfile->indirect_objects_.size (); i++) + scm_gc_mark (pfile->indirect_objects_[i]->self_scm ()); return SCM_BOOL_F; }