merge the formfield patch from ooo-build
[ooovba.git] / sdext / source / pdfimport / xpdfwrapper / pdfioutdev_gpl.cxx
blobd29be09b6af2786d223f2e2f970c2a7e92a62d19
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: pdfioutdev_gpl.cxx,v $
7 * $Revision: 1.1.2.1 $
9 * last change: $Author: cmc $ $Date: 2008/08/25 16:17:55 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU General Public License Version 2.
15 * GNU General Public License, version 2
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This program is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU General Public License as
22 * published by the Free Software Foundation; either version 2 of
23 * the License, or (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public
31 * License along with this program; if not, write to the Free
32 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
33 * Boston, MA 02110-1301, USA.
35 ************************************************************************/
37 #include "pdfioutdev_gpl.hxx"
38 #include "pnghelper.hxx"
40 #include <stdlib.h>
41 #include <stdio.h>
42 #include <assert.h>
43 #include <math.h>
44 #include <vector>
46 #if defined __SUNPRO_CC
47 #pragma disable_warn
48 #elif defined _MSC_VER
49 #pragma warning(push, 1)
50 #endif
52 #include "UTF8.h"
54 #if defined __SUNPRO_CC
55 #pragma enable_warn
56 #elif defined _MSC_VER
57 #pragma warning(pop)
58 #endif
60 #ifdef WNT
61 # define snprintf _snprintf
62 #endif
65 /* SYNC STREAMS
66 ============
68 We stream human-readble tokens to stdout, and binary data (fonts,
69 bitmaps) to g_binary_out. Another process reads from those pipes, and
70 there lies the rub: things can deadlock, if the two involved
71 processes access the pipes in different order. At any point in
72 time, both processes must access the same pipe. To ensure this,
73 data must be flushed to the OS before writing to a different pipe,
74 otherwise not-yet-written data will leave the reading process
75 waiting on the wrong pipe.
78 namespace pdfi
81 /// cut off very small numbers & clamp value to zero
82 inline double normalize( double val )
84 return fabs(val) < 0.0000001 ? 0.0 : val;
87 const char* escapeLineFeed( const char* pStr )
89 // TODO(Q3): Escape linefeeds
90 return pStr;
93 /// for the temp char buffer the header gets snprintfed in
94 #define WRITE_BUFFER_SIZE 1024
96 /// for the initial std::vector capacity when copying stream from xpdf
97 #define WRITE_BUFFER_INITIAL_CAPACITY (1024*100)
99 void initBuf(OutputBuffer& io_rBuffer)
101 io_rBuffer.reserve(WRITE_BUFFER_INITIAL_CAPACITY);
104 void writeBinaryBuffer( const OutputBuffer& rBuffer )
106 // ---sync point--- see SYNC STREAMS above
107 fflush(stdout);
109 // put buffer to stderr
110 if( !rBuffer.empty() )
111 if( fwrite(&rBuffer[0], sizeof(char),
112 rBuffer.size(), g_binary_out) != (size_t)rBuffer.size() )
113 exit(1); // error
115 // ---sync point--- see SYNC STREAMS above
116 fflush(g_binary_out);
119 void writeJpeg_( OutputBuffer& o_rOutputBuf, Stream* str, bool bWithLinefeed )
121 // dump JPEG file as-is
122 str = ((DCTStream *)str)->getRawStream();
123 str->reset();
125 int c;
126 o_rOutputBuf.clear();
127 while((c=str->getChar()) != EOF)
128 o_rOutputBuf.push_back(static_cast<char>(c));
130 printf( " JPEG %d", (int)o_rOutputBuf.size() );
131 if( bWithLinefeed )
132 printf("\n");
134 str->close();
137 void writePbm_(OutputBuffer& o_rOutputBuf, Stream* str, int width, int height, bool bWithLinefeed, bool bInvert )
139 // write as PBM (char by char, to avoid stdlib lineend messing)
140 o_rOutputBuf.clear();
141 o_rOutputBuf.resize(WRITE_BUFFER_SIZE);
142 o_rOutputBuf[0] = 'P';
143 o_rOutputBuf[1] = '4';
144 o_rOutputBuf[2] = 0x0A;
145 int nOutLen = snprintf(&o_rOutputBuf[3], WRITE_BUFFER_SIZE-10, "%d %d", width, height);
146 if( nOutLen < 0 )
147 nOutLen = WRITE_BUFFER_SIZE-10;
148 o_rOutputBuf[3+nOutLen] =0x0A;
149 o_rOutputBuf[3+nOutLen+1]=0;
151 const int header_size = 3+nOutLen+1;
152 const int size = height * ((width + 7) / 8);
154 printf( " PBM %d", size + header_size );
155 if( bWithLinefeed )
156 printf("\n");
158 // trim buffer to exact header length
159 o_rOutputBuf.resize(header_size);
161 // initialize stream
162 str->reset();
164 // copy the raw stream
165 if( bInvert )
167 for( int i=0; i<size; ++i)
168 o_rOutputBuf.push_back(static_cast<char>(str->getChar() ^ 0xff));
170 else
172 for( int i=0; i<size; ++i)
173 o_rOutputBuf.push_back(static_cast<char>(str->getChar()));
176 str->close();
179 void writePpm_( OutputBuffer& o_rOutputBuf,
180 Stream* str,
181 int width,
182 int height,
183 GfxImageColorMap* colorMap,
184 bool bWithLinefeed )
186 // write as PPM (char by char, to avoid stdlib lineend messing)
187 o_rOutputBuf.clear();
188 o_rOutputBuf.resize(WRITE_BUFFER_SIZE);
189 o_rOutputBuf[0] = 'P';
190 o_rOutputBuf[1] = '6';
191 o_rOutputBuf[2] = '\n';
192 int nOutLen = snprintf(&o_rOutputBuf[3], WRITE_BUFFER_SIZE-10, "%d %d", width, height);
193 if( nOutLen < 0 )
194 nOutLen = WRITE_BUFFER_SIZE-10;
195 o_rOutputBuf[3+nOutLen] ='\n';
196 o_rOutputBuf[3+nOutLen+1]='2';
197 o_rOutputBuf[3+nOutLen+2]='5';
198 o_rOutputBuf[3+nOutLen+3]='5';
199 o_rOutputBuf[3+nOutLen+4]='\n';
200 o_rOutputBuf[3+nOutLen+5]=0;
202 const int header_size = 3+nOutLen+5;
203 const int size = width*height*3 + header_size;
205 printf( " PPM %d", size );
206 if( bWithLinefeed )
207 printf("\n");
209 // trim buffer to exact header size
210 o_rOutputBuf.resize(header_size);
212 // initialize stream
213 Guchar *p;
214 GfxRGB rgb;
215 ImageStream* imgStr =
216 new ImageStream(str,
217 width,
218 colorMap->getNumPixelComps(),
219 colorMap->getBits());
220 imgStr->reset();
222 for( int y=0; y<height; ++y)
224 p = imgStr->getLine();
225 for( int x=0; x<width; ++x)
227 colorMap->getRGB(p, &rgb);
228 o_rOutputBuf.push_back(colToByte(rgb.r));
229 o_rOutputBuf.push_back(colToByte(rgb.g));
230 o_rOutputBuf.push_back(colToByte(rgb.b));
232 p +=colorMap->getNumPixelComps();
236 delete imgStr;
240 // call this only for 1 bit image streams !
241 void writePng_( OutputBuffer& o_rOutputBuf,
242 Stream* str,
243 int width,
244 int height,
245 GfxRGB& zeroColor,
246 GfxRGB& oneColor,
247 bool bIsMask,
248 bool bWithLinefeed )
250 o_rOutputBuf.clear();
252 // get png image
253 PngHelper::createPng( o_rOutputBuf, str, width, height, zeroColor, oneColor, bIsMask );
255 printf( " PNG %d", (int)o_rOutputBuf.size() );
256 if( bWithLinefeed )
257 printf("\n");
260 void writePng_( OutputBuffer& o_rOutputBuf,
261 Stream* str,
262 int width, int height, GfxImageColorMap* colorMap,
263 Stream* maskStr,
264 int maskWidth, int maskHeight, GfxImageColorMap* maskColorMap,
265 bool bWithLinefeed )
267 o_rOutputBuf.clear();
269 // get png image
270 PngHelper::createPng( o_rOutputBuf, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap );
272 printf( " PNG %d", (int)o_rOutputBuf.size() );
273 if( bWithLinefeed )
274 printf("\n");
277 void writePng_( OutputBuffer& o_rOutputBuf,
278 Stream* str,
279 int width, int height, GfxImageColorMap* colorMap,
280 Stream* maskStr,
281 int maskWidth, int maskHeight, bool maskInvert,
282 bool bWithLinefeed )
284 o_rOutputBuf.clear();
286 // get png image
287 PngHelper::createPng( o_rOutputBuf, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert );
289 printf( " PNG %d", (int)o_rOutputBuf.size() );
290 if( bWithLinefeed )
291 printf("\n");
294 // stolen from ImageOutputDev.cc
295 void writeMask_( OutputBuffer& o_rOutputBuf, Stream* str, int width, int height, bool bWithLinefeed, bool bInvert )
297 if( str->getKind() == strDCT )
298 writeJpeg_(o_rOutputBuf, str, bWithLinefeed);
299 else
300 writePbm_(o_rOutputBuf, str, width, height, bWithLinefeed, bInvert );
303 void writeImage_( OutputBuffer& o_rOutputBuf,
304 Stream* str,
305 int width,
306 int height,
307 GfxImageColorMap* colorMap,
308 bool bWithLinefeed )
310 // dump JPEG file
311 if( str->getKind() == strDCT &&
312 (colorMap->getNumPixelComps() == 1 ||
313 colorMap->getNumPixelComps() == 3) )
315 writeJpeg_(o_rOutputBuf, str, bWithLinefeed);
317 else if (colorMap->getNumPixelComps() == 1 &&
318 colorMap->getBits() == 1)
320 // this is a two color bitmap, write a png
321 // provide default colors
322 GfxRGB zeroColor = { 0, 0, 0 },
323 oneColor = { byteToCol( 0xff ), byteToCol( 0xff ), byteToCol( 0xff ) };
324 if( colorMap->getColorSpace()->getMode() == csIndexed || colorMap->getColorSpace()->getMode() == csDeviceGray )
326 Guchar nIndex = 0;
327 colorMap->getRGB( &nIndex, &zeroColor );
328 nIndex = 1;
329 colorMap->getRGB( &nIndex, &oneColor );
331 writePng_( o_rOutputBuf, str, width, height, zeroColor, oneColor, false, bWithLinefeed );
333 else
334 writePpm_( o_rOutputBuf, str, width, height, colorMap, bWithLinefeed );
337 // forwarders
338 // ------------------------------------------------------------------
340 inline void writeImage( OutputBuffer& o_rOutputBuf,
341 Stream* str,
342 int width,
343 int height,
344 GfxImageColorMap* colorMap ) { writeImage_(o_rOutputBuf,str,width,height,colorMap,false); }
345 inline void writeImageLF( OutputBuffer& o_rOutputBuf,
346 Stream* str,
347 int width,
348 int height,
349 GfxImageColorMap* colorMap ) { writeImage_(o_rOutputBuf,str,width,height,colorMap,true); }
350 inline void writeMask( OutputBuffer& o_rOutputBuf,
351 Stream* str,
352 int width,
353 int height,
354 bool bInvert ) { writeMask_(o_rOutputBuf,str,width,height,false,bInvert); }
355 inline void writeMaskLF( OutputBuffer& o_rOutputBuf,
356 Stream* str,
357 int width,
358 int height,
359 bool bInvert ) { writeMask_(o_rOutputBuf,str,width,height,true,bInvert); }
361 // ------------------------------------------------------------------
364 int PDFOutDev::parseFont( long long nNewId, GfxFont* gfxFont, GfxState* state ) const
366 FontAttributes aNewFont;
367 int nSize = 0;
369 GooString* pFamily = gfxFont->getName();
370 if( ! pFamily )
371 pFamily = gfxFont->getOrigName();
372 if( pFamily )
374 aNewFont.familyName.clear();
375 aNewFont.familyName.append( gfxFont->getName() );
377 else
379 aNewFont.familyName.clear();
380 aNewFont.familyName.append( "Arial" );
383 aNewFont.isBold = gfxFont->isBold();
384 aNewFont.isItalic = gfxFont->isItalic();
385 aNewFont.size = state->getTransformedFontSize();
386 aNewFont.isUnderline = false;
388 if( gfxFont->getType() == fontTrueType || gfxFont->getType() == fontType1 )
390 // TODO(P3): Unfortunately, need to read stream twice, since
391 // we must write byte count to stdout before
392 char* pBuf = gfxFont->readEmbFontFile( m_pDoc->getXRef(), &nSize );
393 if( pBuf )
394 aNewFont.isEmbedded = true;
397 m_aFontMap[ nNewId ] = aNewFont;
398 return nSize;
401 void PDFOutDev::writeFontFile( GfxFont* gfxFont ) const
403 if( gfxFont->getType() != fontTrueType && gfxFont->getType() != fontType1 )
404 return;
406 int nSize = 0;
407 char* pBuf = gfxFont->readEmbFontFile( m_pDoc->getXRef(), &nSize );
408 if( !pBuf )
409 return;
411 // ---sync point--- see SYNC STREAMS above
412 fflush(stdout);
414 if( fwrite(pBuf, sizeof(char), nSize, g_binary_out) != (size_t)nSize )
415 exit(1); // error
417 // ---sync point--- see SYNC STREAMS above
418 fflush(g_binary_out);
421 void PDFOutDev::printPath( GfxPath* pPath ) const
423 int nSubPaths = pPath ? pPath->getNumSubpaths() : 0;
424 for( int i=0; i<nSubPaths; i++ )
426 GfxSubpath* pSub = pPath->getSubpath( i );
427 const int nPoints = pSub->getNumPoints();
429 printf( " subpath %d", pSub->isClosed() );
431 for( int n=0; n<nPoints; ++n )
433 printf( " %f %f %d",
434 normalize(pSub->getX(n)),
435 normalize(pSub->getY(n)),
436 pSub->getCurve(n) );
441 PDFOutDev::PDFOutDev( PDFDoc* pDoc ) :
442 m_pDoc( pDoc ),
443 m_aFontMap(),
444 m_pUtf8Map( new UnicodeMap((char*)"UTF-8", gTrue, &mapUTF8) )
448 void PDFOutDev::startPage(int /*pageNum*/, GfxState* state)
450 assert(state);
451 printf("startPage %f %f\n",
452 normalize(state->getPageWidth()),
453 normalize(state->getPageHeight()));
456 void PDFOutDev::endPage()
458 printf("endPage\n");
461 void PDFOutDev::processLink(Link* link, Catalog*)
463 assert(link);
465 double x1,x2,y1,y2;
466 link->getRect( &x1, &y1, &x2, &y2 );
468 LinkAction* pAction = link->getAction();
469 if( pAction->getKind() == actionURI )
471 const char* pURI = static_cast<LinkURI*>(pAction)->getURI()->getCString();
473 printf( "drawLink %f %f %f %f %s\n",
474 normalize(x1),
475 normalize(y1),
476 normalize(x2),
477 normalize(y2),
478 escapeLineFeed(pURI) );
482 void PDFOutDev::saveState(GfxState*)
484 printf( "saveState\n" );
487 void PDFOutDev::restoreState(GfxState*)
489 printf( "restoreState\n" );
492 void PDFOutDev::setDefaultCTM(double *pMat)
494 assert(pMat);
496 OutputDev::setDefaultCTM(pMat);
498 printf( "updateCtm %f %f %f %f %f %f\n",
499 normalize(pMat[0]),
500 normalize(pMat[2]),
501 normalize(pMat[1]),
502 normalize(pMat[3]),
503 normalize(pMat[4]),
504 normalize(pMat[5]) );
507 void PDFOutDev::updateCTM(GfxState* state,
508 double, double,
509 double, double,
510 double, double)
512 assert(state);
514 const double* const pMat = state->getCTM();
515 assert(pMat);
517 printf( "updateCtm %f %f %f %f %f %f\n",
518 normalize(pMat[0]),
519 normalize(pMat[2]),
520 normalize(pMat[1]),
521 normalize(pMat[3]),
522 normalize(pMat[4]),
523 normalize(pMat[5]) );
526 void PDFOutDev::updateLineDash(GfxState *state)
528 assert(state);
530 double* dashArray; int arrayLen; double startOffset;
531 state->getLineDash(&dashArray, &arrayLen, &startOffset);
533 printf( "updateLineDash" );
534 if( arrayLen && dashArray )
536 printf( " %f %d", normalize(startOffset), arrayLen );
537 for( int i=0; i<arrayLen; ++i )
538 printf( " %f", normalize(*dashArray++) );
540 printf( "\n" );
543 void PDFOutDev::updateFlatness(GfxState *state)
545 assert(state);
546 printf( "updateFlatness %d\n", state->getFlatness() );
549 void PDFOutDev::updateLineJoin(GfxState *state)
551 assert(state);
552 printf( "updateLineJoin %d\n", state->getLineJoin() );
555 void PDFOutDev::updateLineCap(GfxState *state)
557 assert(state);
558 printf( "updateLineCap %d\n", state->getLineCap() );
561 void PDFOutDev::updateMiterLimit(GfxState *state)
563 assert(state);
564 printf( "updateMiterLimit %f\n", normalize(state->getMiterLimit()) );
567 void PDFOutDev::updateLineWidth(GfxState *state)
569 assert(state);
570 printf( "updateLineWidth %f\n", normalize(state->getLineWidth()) );
573 void PDFOutDev::updateFillColor(GfxState *state)
575 assert(state);
577 GfxRGB aRGB;
578 state->getFillRGB( &aRGB );
580 printf( "updateFillColor %f %f %f %f\n",
581 normalize(colToDbl(aRGB.r)),
582 normalize(colToDbl(aRGB.g)),
583 normalize(colToDbl(aRGB.b)),
584 normalize(state->getFillOpacity()) );
587 void PDFOutDev::updateStrokeColor(GfxState *state)
589 assert(state);
591 GfxRGB aRGB;
592 state->getStrokeRGB( &aRGB );
594 printf( "updateStrokeColor %f %f %f %f\n",
595 normalize(colToDbl(aRGB.r)),
596 normalize(colToDbl(aRGB.g)),
597 normalize(colToDbl(aRGB.b)),
598 normalize(state->getFillOpacity()) );
601 void PDFOutDev::updateFillOpacity(GfxState *state)
603 updateFillColor(state);
606 void PDFOutDev::updateStrokeOpacity(GfxState *state)
608 updateStrokeColor(state);
611 void PDFOutDev::updateBlendMode(GfxState*)
615 void PDFOutDev::updateFont(GfxState *state)
617 assert(state);
619 GfxFont *gfxFont = state->getFont();
620 if( gfxFont )
622 FontAttributes aFont;
623 int nEmbedSize=0;
625 Ref* pID = gfxFont->getID();
626 // TODO(Q3): Portability problem
627 long long fontID = (long long)pID->gen << 32 | (long long)pID->num;
628 std::hash_map< long long, FontAttributes >::const_iterator it =
629 m_aFontMap.find( fontID );
630 if( it == m_aFontMap.end() )
632 nEmbedSize = parseFont( fontID, gfxFont, state );
633 it = m_aFontMap.find( fontID );
636 printf( "updateFont" );
637 if( it != m_aFontMap.end() )
639 // conflating this with printf below crashes under Windoze
640 printf( " %lld", fontID );
642 aFont = it->second;
643 printf( " %d %d %d %d %f %d %s",
644 aFont.isEmbedded,
645 aFont.isBold,
646 aFont.isItalic,
647 aFont.isUnderline,
648 normalize(state->getTransformedFontSize()),
649 nEmbedSize,
650 escapeLineFeed(aFont.familyName.getCString()) );
652 printf( "\n" );
654 if( nEmbedSize )
655 writeFontFile(gfxFont);
659 void PDFOutDev::updateRender(GfxState *state)
661 assert(state);
663 printf( "setTextRenderMode %d\n", state->getRender() );
666 void PDFOutDev::stroke(GfxState *state)
668 assert(state);
670 printf( "strokePath" );
671 printPath( state->getPath() );
672 printf( "\n" );
675 void PDFOutDev::fill(GfxState *state)
677 assert(state);
679 printf( "fillPath" );
680 printPath( state->getPath() );
681 printf( "\n" );
684 void PDFOutDev::eoFill(GfxState *state)
686 assert(state);
688 printf( "eoFillPath" );
689 printPath( state->getPath() );
690 printf( "\n" );
693 void PDFOutDev::clip(GfxState *state)
695 assert(state);
697 printf( "clipPath" );
698 printPath( state->getPath() );
699 printf( "\n" );
702 void PDFOutDev::eoClip(GfxState *state)
704 assert(state);
706 printf( "eoClipPath" );
707 printPath( state->getPath() );
708 printf( "\n" );
711 /** Output one glyph
714 @param dx
715 horizontal skip for character (already scaled with font size) +
716 inter-char space: cursor is shifted by this amount for next char
718 @param dy
719 vertical skip for character (zero for horizontal writing mode):
720 cursor is shifted by this amount for next char
722 @param originX
723 local offset of character (zero for horizontal writing mode). not
724 taken into account for output pos updates. Used for vertical writing.
726 @param originY
727 local offset of character (zero for horizontal writing mode). not
728 taken into account for output pos updates. Used for vertical writing.
730 void PDFOutDev::drawChar(GfxState *state, double x, double y,
731 double dx, double dy,
732 double originX, double originY,
733 CharCode, int /*nBytes*/, Unicode *u, int uLen)
735 assert(state);
737 if( u == NULL )
738 return;
740 // normalize coordinates: correct from baseline-relative to upper
741 // left corner of glyphs
742 double x2(0.0), y2(0.0);
743 state->textTransformDelta( 0.0,
744 state->getFont()->getAscent(),
745 &x2, &y2 );
746 const double fFontSize(state->getFontSize());
747 x += x2*fFontSize;
748 y += y2*fFontSize;
750 const double aPositionX(x-originX);
751 const double aPositionY(y-originY);
752 // TODO(F2): use leading here, when set
753 const double nWidth(dx != 0.0 ? dx : fFontSize);
754 const double nHeight(dy != 0.0 ? dy : fFontSize);
756 const double* pTextMat=state->getTextMat();
757 printf( "drawChar %f %f %f %f %f %f %f %f ",
758 normalize(aPositionX),
759 normalize(aPositionY),
760 normalize(aPositionX+nWidth),
761 normalize(aPositionY-nHeight),
762 normalize(pTextMat[0]),
763 normalize(pTextMat[2]),
764 normalize(pTextMat[1]),
765 normalize(pTextMat[3]) );
767 // silence spurious warning
768 (void)&mapUCS2;
770 char buf[9];
771 for( int i=0; i<uLen; ++i )
773 buf[ m_pUtf8Map->mapUnicode(u[i], buf, sizeof(buf)-1) ] = 0;
774 printf( "%s", escapeLineFeed(buf) );
777 printf( "\n" );
780 void PDFOutDev::drawString(GfxState*, GooString* /*s*/)
782 // TODO(F3): NYI
785 void PDFOutDev::endTextObject(GfxState*)
787 printf( "endTextObject\n" );
790 void PDFOutDev::drawImageMask(GfxState* pState, Object*, Stream* str,
791 int width, int height, GBool invert,
792 GBool /*inlineImg*/ )
794 OutputBuffer aBuf; initBuf(aBuf);
796 printf( "drawMask %d %d %d", width, height, invert );
798 int bitsPerComponent = 1;
799 StreamColorSpaceMode csMode = streamCSNone;
800 str->getImageParams( &bitsPerComponent, &csMode );
801 if( bitsPerComponent == 1 && (csMode == streamCSNone || csMode == streamCSDeviceGray) )
803 GfxRGB oneColor = { dblToCol( 1.0 ), dblToCol( 1.0 ), dblToCol( 1.0 ) };
804 GfxRGB zeroColor = { dblToCol( 0.0 ), dblToCol( 0.0 ), dblToCol( 0.0 ) };
805 pState->getFillColorSpace()->getRGB( pState->getFillColor(), &zeroColor );
806 if( invert )
807 writePng_( aBuf, str, width, height, oneColor, zeroColor, true, true );
808 else
809 writePng_( aBuf, str, width, height, zeroColor, oneColor, true, true );
811 else
812 writeMaskLF(aBuf, str, width, height, invert != 0);
813 writeBinaryBuffer(aBuf);
816 void PDFOutDev::drawImage(GfxState*, Object*, Stream* str,
817 int width, int height, GfxImageColorMap* colorMap,
818 int* maskColors, GBool /*inlineImg*/ )
820 OutputBuffer aBuf; initBuf(aBuf);
821 OutputBuffer aMaskBuf;
823 printf( "drawImage %d %d", width, height );
825 if( maskColors )
827 // write mask colors. nBytes must be even - first half is
828 // lower bound values, second half upper bound values
829 if( colorMap->getColorSpace()->getMode() == csIndexed )
831 aMaskBuf.push_back( (char)maskColors[0] );
832 aMaskBuf.push_back( (char)maskColors[gfxColorMaxComps] );
834 else
836 GfxRGB aMinRGB;
837 colorMap->getColorSpace()->getRGB(
838 (GfxColor*)maskColors,
839 &aMinRGB );
841 GfxRGB aMaxRGB;
842 colorMap->getColorSpace()->getRGB(
843 (GfxColor*)maskColors+gfxColorMaxComps,
844 &aMaxRGB );
846 aMaskBuf.push_back( colToByte(aMinRGB.r) );
847 aMaskBuf.push_back( colToByte(aMinRGB.g) );
848 aMaskBuf.push_back( colToByte(aMinRGB.b) );
849 aMaskBuf.push_back( colToByte(aMaxRGB.r) );
850 aMaskBuf.push_back( colToByte(aMaxRGB.g) );
851 aMaskBuf.push_back( colToByte(aMaxRGB.b) );
855 printf( " %d", (int)aMaskBuf.size() );
856 writeImageLF( aBuf, str, width, height, colorMap );
857 writeBinaryBuffer(aBuf);
858 writeBinaryBuffer(aMaskBuf);
861 void PDFOutDev::drawMaskedImage(GfxState*, Object*, Stream* str,
862 int width, int height,
863 GfxImageColorMap* colorMap,
864 Stream* maskStr,
865 int maskWidth, int maskHeight,
866 GBool maskInvert)
868 OutputBuffer aBuf; initBuf(aBuf);
869 printf( "drawImage %d %d 0", width, height );
870 writePng_( aBuf, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert, true );
871 writeBinaryBuffer( aBuf );
872 #if 0
873 OutputBuffer aBuf; initBuf(aBuf);
874 OutputBuffer aMaskBuf; initBuf(aMaskBuf);
876 printf( "drawMaskedImage %d %d %d %d %d", width, height, maskWidth, maskHeight, 0 /*maskInvert note: currently we do inversion here*/ );
877 writeImage( aBuf, str, width, height, colorMap );
878 writeMaskLF( aMaskBuf, maskStr, width, height, maskInvert );
879 writeBinaryBuffer(aBuf);
880 writeBinaryBuffer(aMaskBuf);
881 #endif
884 void PDFOutDev::drawSoftMaskedImage(GfxState*, Object*, Stream* str,
885 int width, int height,
886 GfxImageColorMap* colorMap,
887 Stream* maskStr,
888 int maskWidth, int maskHeight,
889 GfxImageColorMap* maskColorMap )
891 OutputBuffer aBuf; initBuf(aBuf);
892 printf( "drawImage %d %d 0", width, height );
893 writePng_( aBuf, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap, true );
894 writeBinaryBuffer( aBuf );
895 #if 0
896 OutputBuffer aBuf; initBuf(aBuf);
897 OutputBuffer aMaskBuf; initBuf(aMaskBuf);
899 printf( "drawSoftMaskedImage %d %d %d %d", width, height, maskWidth, maskHeight );
900 writeImage( aBuf, str, width, height, colorMap );
901 writeImageLF( aMaskBuf, maskStr, maskWidth, maskHeight, maskColorMap );
902 writeBinaryBuffer(aBuf);
903 writeBinaryBuffer(aMaskBuf);
904 #endif
907 void PDFOutDev::setPageNum( int nNumPages )
909 // TODO(F3): printf might format int locale-dependent!
910 printf("setPageNum %d\n", nNumPages);