File: poppler_splash_renderer.cc

package info (click to toggle)
popplerkit.framework 0.0.20051227svn-8
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,548 kB
  • sloc: objc: 2,303; cpp: 669; sh: 465; ansic: 55; makefile: 27
file content (168 lines) | stat: -rw-r--r-- 4,747 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 * Copyright (C) 2004  Stefan Kleine Stegemann
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#include <stdio.h>
#include <stdlib.h>
#include "poppler_splash_renderer.h"
#include "poppler.h"
#include <PDFDoc.h>
#include <Page.h>
#include <goo/GooString.h>
#include <SplashOutputDev.h>
#include <splash/SplashBitmap.h>

#define PDF_DOC(obj) static_cast<PDFDoc*>(obj)
#define PAGE(obj) static_cast<Page*>(obj)
#define SPLASH_DEV(obj) static_cast<SplashOutputDev*>(obj)
#define SPLASH_BITMAP(obj) static_cast<SplashBitmap*>(obj)

void* poppler_splash_device_create(int bg_red, int bg_green, int bg_blue)
{  
   BEGIN_SYNCHRONIZED;
      SplashColor white;
#ifdef POPPLER_0_4
      white.rgb8 = splashMakeRGB8(bg_red, bg_green, bg_blue);
      void* splashDevice = new SplashOutputDev(splashModeRGB8, false, white);
#else // 0.5, 0.6
      white[0] = bg_red;
      white[1] = bg_green;
      white[2] = bg_blue;
      // I'm not sure what bitmapRowPad should be, 1 is just a guess.
      void* splashDevice = new SplashOutputDev(splashModeRGB8, 1, false, white);
#endif
   END_SYNCHRONIZED;
   
   return splashDevice;
}

void poppler_splash_device_start_doc(void* output_dev, void* poppler_document)
{
   if (!output_dev || !poppler_document)
   {
     return;
   }
    
   SYNCHRONIZED(SPLASH_DEV(output_dev)->startDoc(
#ifdef POPPLER_0_20
	PDF_DOC(poppler_document)
#else
	PDF_DOC(poppler_document)->getXRef()
#endif
   ));
}

void poppler_splash_device_destroy(void* output_dev)
{
   if (!output_dev)
   {
      return;
   }
   
   delete SPLASH_DEV(output_dev);
}

int poppler_splash_device_display_slice(void* output_dev, void* poppler_page,
                                        void* poppler_document,
                                        float hDPI, float vDPI, int rotate,
                                        float sliceX, float sliceY,
                                        float sliceW, float sliceH)
{
   if (!output_dev || !poppler_page || !poppler_document)
   {
      return 0;
   }

   
   SYNCHRONIZED(PAGE(poppler_page)->displaySlice(SPLASH_DEV(output_dev),
                                                 (double)hDPI, (double)vDPI,
                                                 rotate,
#ifndef POPPLER_0_4 // 0.5, 0.6
						 true, // useMediaBox
#endif
                                                 true, // Crop
                                                 (int)sliceX, (int)sliceY,
                                                 (int)sliceW, (int)sliceH,
#ifdef POPPLER_0_6
												 false // printing
#else
                                                 NULL // Links
#endif
#ifndef POPPLER_0_20
                                                 , PDF_DOC(poppler_document)->getCatalog()
#endif
                                                 ));

   return 1;
}

int poppler_splash_device_get_bitmap(void* output_dev, void** bitmap,
                                     int* width, int* height)
{
   if (!output_dev)
   {
      return 0;
   }
   
   SplashBitmap* _bitmap = SPLASH_DEV(output_dev)->getBitmap();
   *width = _bitmap->getWidth();
   *height = _bitmap->getHeight();
   *bitmap = _bitmap;

   return 1;
}

int poppler_splash_device_get_rgb(void* bitmap, unsigned char** data)
{
   if (!bitmap)
   {
      return 0;
   }

#ifdef POPPLER_0_4
   SplashRGB8*     rgb8;
#else // 0.5, 0.6
   SplashColorPtr  color;
#endif
   unsigned char*  dataPtr;

#ifdef POPPLER_0_4
   rgb8 = SPLASH_BITMAP(bitmap)->getDataPtr().rgb8;
#else // 0.5, 0.6
   color = SPLASH_BITMAP(bitmap)->getDataPtr();
#endif

   dataPtr = *data;
   for (int row = 0; row < SPLASH_BITMAP(bitmap)->getHeight(); row++)
   {
      for (int col = 0; col < SPLASH_BITMAP(bitmap)->getWidth(); col++)
      {
#ifdef POPPLER_0_4
         *dataPtr++ = splashRGB8R(*rgb8);
         *dataPtr++ = splashRGB8G(*rgb8);
         *dataPtr++ = splashRGB8B(*rgb8);
         ++rgb8;
#else // 0.5, 0.6
	 *dataPtr++ = splashRGB8R(color);
	 *dataPtr++ = splashRGB8G(color);
	 *dataPtr++ = splashRGB8B(color);
	 color = color + 3;
#endif
      }
   }
   return 1;
}