| 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 _LUA_CONVERTER_H_ |
| 22 | #define _LUA_CONVERTER_H_ |
| 23 | |
| 24 | #include "iconverter.h" |
| 25 | |
| 26 | struct lua_State; |
| 27 | |
| 28 | class LuaMachina |
| 29 | { |
| 30 | lua_State *L; |
| 31 | |
| 32 | public: |
| 33 | LuaMachina(); |
| 34 | ~LuaMachina(); |
| 35 | |
| 36 | inline lua_State* State() |
| 37 | { |
| 38 | return L; |
| 39 | } |
| 40 | }; |
| 41 | |
| 42 | /** |
| 43 | * Converter that calls a lua script |
| 44 | * to do the color conversions. |
| 45 | */ |
| 46 | class LuaConverter : public IConverter { |
| 47 | |
| 48 | public: |
| 49 | LuaConverter( const std::string & sLuaScript ); |
| 50 | virtual ~LuaConverter(); |
| 51 | |
| 52 | /** |
| 53 | * A helper method that is called to inform the converter |
| 54 | * when a new page is analyzed. |
| 55 | * |
| 56 | * @param pPage page object |
| 57 | * @param nPageIndex index of the page in the document |
| 58 | */ |
| 59 | virtual void StartPage( PoDoFo::PdfPage* pPage, int nPageIndex ); |
| 60 | |
| 61 | /** |
| 62 | * A helper method that is called to inform the converter |
| 63 | * when a new page has been analyzed completely. |
| 64 | * |
| 65 | * @param pPage page object |
| 66 | * @param nPageIndex index of the page in the document |
| 67 | */ |
| 68 | virtual void EndPage( PoDoFo::PdfPage* pPage, int nPageIndex ); |
| 69 | |
| 70 | /** |
| 71 | * A helper method that is called to inform the converter |
| 72 | * when a new xobjext is analyzed. |
| 73 | * |
| 74 | * @param pObj the xobject |
| 75 | */ |
| 76 | virtual void StartXObject( PoDoFo::PdfXObject* pObj ); |
| 77 | |
| 78 | /** |
| 79 | * A helper method that is called to inform the converter |
| 80 | * when a xobjext has been analyzed. |
| 81 | * |
| 82 | * @param pObj the xobject |
| 83 | */ |
| 84 | virtual void EndXObject( PoDoFo::PdfXObject* pObj ); |
| 85 | |
| 86 | /** |
| 87 | * This method is called whenever a gray stroking color is set |
| 88 | * using the 'G' PDF command. |
| 89 | * |
| 90 | * @param a grayscale color object |
| 91 | * @returns a new color which should be set instead (any colorspace) |
| 92 | */ |
| 93 | virtual PoDoFo::PdfColor SetStrokingColorGray( const PoDoFo::PdfColor & rColor ); |
| 94 | |
| 95 | /** |
| 96 | * This method is called whenever a RGB stroking color is set |
| 97 | * using the 'RG' PDF command. |
| 98 | * |
| 99 | * @param a RGB color object |
| 100 | * @returns a new color which should be set instead (any colorspace) |
| 101 | */ |
| 102 | virtual PoDoFo::PdfColor SetStrokingColorRGB( const PoDoFo::PdfColor & rColor ); |
| 103 | |
| 104 | /** |
| 105 | * This method is called whenever a CMYK stroking color is set |
| 106 | * using the 'K' PDF command. |
| 107 | * |
| 108 | * @param a CMYK color object |
| 109 | * @returns a new color which should be set instead (any colorspace) |
| 110 | */ |
| 111 | virtual PoDoFo::PdfColor SetStrokingColorCMYK( const PoDoFo::PdfColor & rColor ); |
| 112 | |
| 113 | /** |
| 114 | * This method is called whenever a gray non-stroking color is set |
| 115 | * using the 'g' PDF command. |
| 116 | * |
| 117 | * @param a grayscale color object |
| 118 | * @returns a new color which should be set instead (any colorspace) |
| 119 | */ |
| 120 | virtual PoDoFo::PdfColor SetNonStrokingColorGray( const PoDoFo::PdfColor & rColor ); |
| 121 | |
| 122 | /** |
| 123 | * This method is called whenever a RGB non-stroking color is set |
| 124 | * using the 'rg' PDF command. |
| 125 | * |
| 126 | * @param a RGB color object |
| 127 | * @returns a new color which should be set instead (any colorspace) |
| 128 | */ |
| 129 | virtual PoDoFo::PdfColor SetNonStrokingColorRGB( const PoDoFo::PdfColor & rColor ); |
| 130 | |
| 131 | /** |
| 132 | * This method is called whenever a CMYK non-stroking color is set |
| 133 | * using the 'k' PDF command. |
| 134 | * |
| 135 | * @param a CMYK color object |
| 136 | * @returns a new color which should be set instead (any colorspace) |
| 137 | */ |
| 138 | virtual PoDoFo::PdfColor SetNonStrokingColorCMYK( const PoDoFo::PdfColor & rColor ); |
| 139 | |
| 140 | private: |
| 141 | /** |
| 142 | * Create a PdfColor from an array returned on the stack |
| 143 | * by a Lua function. |
| 144 | * @param pszFunctionName name of Lua function for error reporting |
| 145 | * @returns a PdfColor or throws a PdfError if color cannot be created |
| 146 | */ |
| 147 | PoDoFo::PdfColor GetColorFromReturnValue(const char* pszFunctionName); |
| 148 | |
| 149 | private: |
| 150 | LuaMachina m_machina; |
| 151 | }; |
| 152 | |
| 153 | |
| 154 | #endif // _LUA_CONVERTER_H_ |