File: poppler_splash_renderer.cc

package info (click to toggle)
popplerkit.framework 0.0.20051227svn-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,384 kB
  • ctags: 119
  • sloc: objc: 2,303; sh: 857; cpp: 574; ansic: 55; makefile: 23
file content (130 lines) | stat: -rw-r--r-- 3,873 bytes parent folder | download | duplicates (9)
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
/*
 * 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;
      white.rgb8 = splashMakeRGB8(bg_red, bg_green, bg_blue);
      void* splashDevice = new SplashOutputDev(splashModeRGB8, gFalse, white);
   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(PDF_DOC(poppler_document)->getXRef()));
}

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,
                                                 gTrue, // Crop
                                                 (int)sliceX, (int)sliceY,
                                                 (int)sliceW, (int)sliceH,
                                                 NULL, // Links
                                                 PDF_DOC(poppler_document)->getCatalog()));

   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;
   }

   SplashRGB8*     rgb8;
   unsigned char*  dataPtr;

   rgb8 = SPLASH_BITMAP(bitmap)->getDataPtr().rgb8;

   dataPtr = *data;
   for (int row = 0; row < SPLASH_BITMAP(bitmap)->getHeight(); row++)
   {
      for (int col = 0; col < SPLASH_BITMAP(bitmap)->getWidth(); col++)
      {
         *dataPtr++ = splashRGB8R(*rgb8);
         *dataPtr++ = splashRGB8G(*rgb8);
         *dataPtr++ = splashRGB8B(*rgb8);
         ++rgb8;
      }
   }
   
   return 1;
}