| 1 |
/*************************************************************************** |
| 2 |
* Copyright (C) 2010 by Dominik Seichter * |
| 3 |
* [email protected] * |
| 4 |
* * |
| 5 |
* This program is free software; you can redistribute it and/or modify * |
| 6 |
* it under the terms of the GNU General Public License as published by * |
| 7 |
* the Free Software Foundation; either version 2 of the License, or * |
| 8 |
* (at your option) any later version. * |
| 9 |
* * |
| 10 |
* This program is distributed in the hope that it will be useful, * |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 13 |
* GNU General Public License for more details. * |
| 14 |
* * |
| 15 |
* You should have received a copy of the GNU General Public License * |
| 16 |
* along with this program; if not, write to the * |
| 17 |
* Free Software Foundation, Inc., * |
| 18 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
| 19 |
***************************************************************************/ |
| 20 |
|
| 21 |
#ifndef _COLORCHANGER_H_ |
| 22 |
#define _COLORCHANGER_H_ |
| 23 |
|
| 24 |
#include <string> |
| 25 |
#include <vector> |
| 26 |
#include <podofo/podofo.h> |
| 27 |
|
| 28 |
class IConverter; |
| 29 |
class GraphicsStack; |
| 30 |
|
| 31 |
/** |
| 32 |
* This class provides a tool to change all colors |
| 33 |
* in a PDF file. |
| 34 |
*/ |
| 35 |
class ColorChanger |
| 36 |
{ |
| 37 |
public: |
| 38 |
enum EKeywordType |
| 39 |
{ |
| 40 |
eKeyword_GraphicsStack_Push, |
| 41 |
eKeyword_GraphicsStack_Pop, |
| 42 |
|
| 43 |
eKeyword_SelectGray_Stroking, |
| 44 |
eKeyword_SelectRGB_Stroking, |
| 45 |
eKeyword_SelectCMYK_Stroking, |
| 46 |
|
| 47 |
eKeyword_SelectGray_NonStroking, |
| 48 |
eKeyword_SelectRGB_NonStroking, |
| 49 |
eKeyword_SelectCMYK_NonStroking, |
| 50 |
|
| 51 |
eKeyword_SelectColorSpace_Stroking, |
| 52 |
eKeyword_SelectColorSpace_NonStroking, |
| 53 |
|
| 54 |
eKeyword_SelectColor_Stroking, |
| 55 |
eKeyword_SelectColor_NonStroking, |
| 56 |
|
| 57 |
eKeyword_SelectColor_Stroking2, |
| 58 |
eKeyword_SelectColor_NonStroking2, |
| 59 |
|
| 60 |
eKeyword_Undefined = 0xffff |
| 61 |
}; |
| 62 |
|
| 63 |
|
| 64 |
/** |
| 65 |
* KWInfo describes a single PDF keyword's characteristics. See kwInfo[] . |
| 66 |
*/ |
| 67 |
struct KWInfo |
| 68 |
{ |
| 69 |
ColorChanger::EKeywordType eKeywordType; |
| 70 |
/// null-terminated keyword text |
| 71 |
const char pszText[6]; |
| 72 |
/// Number of arguments |
| 73 |
int nNumArguments; |
| 74 |
/// Short description text (optional, set to NULL if undesired). |
| 75 |
const char* pszDescription; |
| 76 |
}; |
| 77 |
|
| 78 |
/** |
| 79 |
* Construct a new colorchanger object |
| 80 |
* @param pConverter a converter which is applied to all color definitions |
| 81 |
* @param sInput the input PDF file |
| 82 |
* @param sOutput write output to this filename |
| 83 |
*/ |
| 84 |
ColorChanger(IConverter* convert, const std::string_view& input, const std::string_view& output); |
| 85 |
|
| 86 |
/** |
| 87 |
* Start processing the input file. |
| 88 |
*/ |
| 89 |
void start(); |
| 90 |
|
| 91 |
private: |
| 92 |
/** |
| 93 |
* Replace all colors in the given page. |
| 94 |
* @param pPage may not be NULL |
| 95 |
*/ |
| 96 |
void ReplaceColorsInPage(PoDoFo::PdfCanvas& page); |
| 97 |
|
| 98 |
/** |
| 99 |
* Convert a keyword name to a keyword typee |
| 100 |
* @param pszKeyword name of a keyword |
| 101 |
* @return the keyword type or eKeywordType_Undefined if unknown |
| 102 |
*/ |
| 103 |
const KWInfo* FindKeyWordByName(const std::string_view& keyword); |
| 104 |
|
| 105 |
PoDoFo::PdfColor GetColorFromStack(int argCount, std::vector<PoDoFo::PdfVariant>& args); |
| 106 |
void PutColorOnStack(const PoDoFo::PdfColor& color, std::vector<PoDoFo::PdfVariant> |
| 107 |
& args); |
| 108 |
|
| 109 |
const char* ProcessColor(EKeywordType keywordType, int numArgs, std::vector<PoDoFo::PdfVariant>& args, GraphicsStack& graphicsStack); |
| 110 |
|
| 111 |
const char* GetKeywordForColor(const PoDoFo::PdfColor& color, bool isStroking); |
| 112 |
|
| 113 |
/** Write a list of arguments and optionally a keyword |
| 114 |
* to an output device |
| 115 |
* |
| 116 |
* @param rArgs list of arguments which will be written to rDevice (will be cleared afterwards). |
| 117 |
* @param pszKeyword a keyword or NULL to be written after the arguments |
| 118 |
* @param rDevice output device |
| 119 |
*/ |
| 120 |
void WriteArgumentsAndKeyword(std::vector<PoDoFo::PdfVariant>& args, const std::string_view& keyword, PoDoFo::OutputStreamDevice& stream); |
| 121 |
|
| 122 |
/** |
| 123 |
* unused |
| 124 |
*/ |
| 125 |
PoDoFo::PdfColorSpaceType GetColorSpaceForName(const PoDoFo::PdfName& name, PoDoFo::PdfCanvas& page); |
| 126 |
|
| 127 |
/** |
| 128 |
* unused |
| 129 |
*/ |
| 130 |
PoDoFo::PdfColorSpaceType GetColorSpaceForArray(const PoDoFo::PdfArray& arr, PoDoFo::PdfCanvas& page); |
| 131 |
private: |
| 132 |
IConverter* m_converter; |
| 133 |
std::string m_input; |
| 134 |
std::string m_output; |
| 135 |
}; |
| 136 |
|
| 137 |
#endif // _COLORCHANGER_H_ |