~ubuntu-branches/ubuntu/jaunty/texlive-bin/jaunty-security

« back to all changes in this revision

Viewing changes to build/source/texk/dvipdfm/epdf.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2008-06-26 23:14:59 UTC
  • mfrom: (2.1.30 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080626231459-y02rjsrgtafu83yr
Tags: 2007.dfsg.2-3
add missing source roadmap.fig of roadmap.eps in fontinst documentation
(Closes: #482915) (urgency medium due to RC bug)
(new patch add-missing-fontinst-source)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  $Header$
 
2
 
 
3
    This is dvipdfm, a DVI to PDF translator.
 
4
    Copyright (C) 1998, 1999 by Mark A. Wicks
 
5
 
 
6
    This program is free software; you can redistribute it and/or modify
 
7
    it under the terms of the GNU General Public License as published by
 
8
    the Free Software Foundation; either version 2 of the License, or
 
9
    (at your option) any later version.
 
10
 
 
11
    This program is distributed in the hope that it will be useful,
 
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
    GNU General Public License for more details.
 
15
 
 
16
    You should have received a copy of the GNU General Public License
 
17
    along with this program; if not, write to the Free Software
 
18
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
    
 
20
    The author may be contacted via the e-mail address
 
21
 
 
22
        mwicks@kettering.edu
 
23
*/
 
24
 
 
25
#include "system.h"
 
26
#include "mem.h"
 
27
#include "mfileio.h"
 
28
#include "pdfobj.h"
 
29
#include "pdfdoc.h"
 
30
#include "pdfspecial.h"
 
31
#include "epdf.h"
 
32
 
 
33
pdf_obj *pdf_include_page(FILE *image_file, struct xform_info *p, char *res_name)
 
34
{
 
35
  pdf_obj *trailer = NULL, *catalog = NULL, *page_tree = NULL;
 
36
  pdf_obj *kids_ref, *kids;
 
37
  pdf_obj *media_box = NULL, *crop_box = NULL, *resources = NULL,
 
38
    *contents = NULL, *contents_ref = NULL;
 
39
  pdf_obj *tmp1;
 
40
#ifdef MEM_DEBUG
 
41
MEM_START
 
42
#endif
 
43
  if (!(trailer = pdf_open (image_file))) {
 
44
    fprintf (stderr, "\nCorrupt PDF file?\n");
 
45
  }
 
46
 
 
47
  /* Now just lookup catalog location */
 
48
  /* Deref catalog */
 
49
  if (trailer && (catalog = pdf_deref_obj(pdf_lookup_dict (trailer,"Root"))) ==
 
50
      NULL) {
 
51
    fprintf (stderr, "\nCatalog isn't where I expect it.\n");
 
52
  }
 
53
  if (trailer)
 
54
    pdf_release_obj (trailer);
 
55
 
 
56
  /* Lookup page tree in catalog */
 
57
  if (catalog) {
 
58
    page_tree = pdf_deref_obj (pdf_lookup_dict (catalog, "Pages"));
 
59
    /* Should be finished with catalog */
 
60
    pdf_release_obj (catalog);
 
61
  }
 
62
  /* Media box and resources can be inherited so start looking for
 
63
     them here */
 
64
  if (page_tree) {
 
65
    if ((tmp1 = pdf_lookup_dict (page_tree, "CropBox")))
 
66
      crop_box = pdf_deref_obj (tmp1);
 
67
    if ((tmp1 = pdf_lookup_dict (page_tree, "MediaBox")))
 
68
      media_box = pdf_deref_obj (tmp1);
 
69
    resources = pdf_deref_obj (pdf_lookup_dict (page_tree, "Resources"));
 
70
    if (resources == NULL) {
 
71
      resources = pdf_new_dict();
 
72
    }
 
73
    while ((kids_ref = pdf_lookup_dict (page_tree, "Kids")) != NULL) {
 
74
      kids = pdf_deref_obj (kids_ref);
 
75
      pdf_release_obj (page_tree);
 
76
      page_tree = pdf_deref_obj (pdf_get_array(kids, 0));
 
77
      pdf_release_obj (kids);
 
78
      /* Replace MediaBox if it's here */
 
79
      tmp1 = pdf_deref_obj(pdf_lookup_dict (page_tree, "MediaBox"));
 
80
      if (tmp1 && media_box)
 
81
        pdf_release_obj (media_box);
 
82
      if (tmp1) 
 
83
        media_box = tmp1;
 
84
      /* Do same for CropBox */
 
85
      tmp1 = pdf_deref_obj(pdf_lookup_dict (page_tree, "CropBox"));
 
86
      if (tmp1 && crop_box)
 
87
        pdf_release_obj (crop_box);
 
88
      if (tmp1) 
 
89
        crop_box = tmp1;
 
90
      /* Add resources if they're here */
 
91
      tmp1 = pdf_deref_obj (pdf_lookup_dict (page_tree, "Resources"));
 
92
      if (tmp1) {
 
93
        pdf_merge_dict (tmp1, resources);
 
94
        pdf_release_obj (resources);
 
95
        resources = tmp1;
 
96
      }
 
97
    }
 
98
    /* At this point, page_tree contains the first page.  media_box,
 
99
       crop_box,  and resources should also be set. */
 
100
    /* If there's a crop_box, replace media_box with crop_box.
 
101
       The rest of this routine assumes crop_box has been released */
 
102
    if (crop_box) {
 
103
      pdf_release_obj (media_box);
 
104
      media_box = crop_box;
 
105
      crop_box = NULL;
 
106
    }
 
107
    /* This gets bit confusing.  In the following code,
 
108
       media_box is the box the image is cropped to. 
 
109
       The bounding box is the box the image is scaled to */
 
110
    /* If user did not supply bounding box, use media_box
 
111
       (which may really be cropbox) as bounding box */
 
112
    /* Set the crop box parameters in the xform_info structure */
 
113
    p->c_llx = pdf_number_value (pdf_get_array (media_box, 0));
 
114
    p->c_lly = pdf_number_value (pdf_get_array (media_box, 1));
 
115
    p->c_urx = pdf_number_value (pdf_get_array (media_box, 2));
 
116
    p->c_ury = pdf_number_value (pdf_get_array (media_box, 3));
 
117
 
 
118
    /* Adjust scaling and clipping information as necessary */
 
119
    pdf_scale_image (p);
 
120
 
 
121
    /* Set the media box to whatever pdf_scale_image() decided
 
122
       for the crop box (which may be unchanged) */
 
123
    pdf_release_obj (media_box);
 
124
    media_box = pdf_new_array ();
 
125
    pdf_add_array (media_box, pdf_new_number (p->c_llx));
 
126
    pdf_add_array (media_box, pdf_new_number (p->c_lly));
 
127
    pdf_add_array (media_box, pdf_new_number (p->c_urx));
 
128
    pdf_add_array (media_box, pdf_new_number (p->c_ury));
 
129
 
 
130
    if ((contents =
 
131
         pdf_deref_obj(pdf_lookup_dict(page_tree,"Contents")))==NULL) {
 
132
      fprintf (stderr, "\nNo Contents found\n");
 
133
      return NULL;
 
134
    }
 
135
    pdf_release_obj (page_tree);
 
136
  }
 
137
  /* Arrays of contents must be handled very differently (not implemented) */
 
138
  if (contents && contents -> type != PDF_ARRAY) {
 
139
    doc_make_form_xobj (contents, media_box,
 
140
                        p->user_bbox? p->u_llx: 0.0,
 
141
                        p->user_bbox? p->u_lly: 0.0,
 
142
                        1.0, 1.0,
 
143
                        resources, res_name);
 
144
  } else {
 
145
    fprintf (stderr, "\nIgnoring stream with with multiple segments\n");
 
146
    contents = NULL;
 
147
  }
 
148
  if (contents) {
 
149
    contents_ref = pdf_ref_obj (contents);
 
150
    pdf_release_obj (contents);
 
151
  }
 
152
  pdf_close ();
 
153
#ifdef MEM_DEBUG
 
154
MEM_END
 
155
#endif
 
156
  return (contents_ref);
 
157
}
 
158
 
 
159