From: Fridrich S. <str...@us...> - 2008-07-17 14:41:46
|
Update of /cvsroot/libwpg/libwpg/src/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27838/src/lib Modified Files: Tag: STABLE-0-1-0 WPG1Parser.cpp WPG1Parser.h Log Message: attempt to handle embedded postscript in WPG1 files (if I could at least have some documents to test with) Index: WPG1Parser.h =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPG1Parser.h,v retrieving revision 1.15.2.1 retrieving revision 1.15.2.2 diff -u -d -r1.15.2.1 -r1.15.2.2 --- WPG1Parser.h 16 Jul 2008 09:25:06 -0000 1.15.2.1 +++ WPG1Parser.h 17 Jul 2008 14:41:39 -0000 1.15.2.2 @@ -58,6 +58,8 @@ void fillPixels(libwpg::WPGBitmap& bitmap, unsigned char* buffer, int width, int height, int depth); void handleBitmapTypeOne(); void handleBitmapTypeTwo(); + void handlePostscriptTypeOne(); + void handlePostscriptTypeTwo(); void resetPalette(); Index: WPG1Parser.cpp =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPG1Parser.cpp,v retrieving revision 1.33.2.6 retrieving revision 1.33.2.7 diff -u -d -r1.33.2.6 -r1.33.2.7 --- WPG1Parser.cpp 16 Jul 2008 10:47:38 -0000 1.33.2.6 +++ WPG1Parser.cpp 17 Jul 2008 14:41:39 -0000 1.33.2.7 @@ -157,33 +157,33 @@ static const struct RecordHandler handlers[] = { - { 0x01, "Fill Attributes", &WPG1Parser::handleFillAttributes }, - { 0x02, "Line Attributes", &WPG1Parser::handleLineAttributes }, - { 0x03, "Marker Atttibutes", 0 }, - { 0x04, "Polymarker", 0 }, - { 0x05, "Line", &WPG1Parser::handleLine }, - { 0x06, "Polyline", &WPG1Parser::handlePolyline }, - { 0x07, "Rectangle", &WPG1Parser::handleRectangle }, - { 0x08, "Polygon", &WPG1Parser::handlePolygon }, - { 0x09, "Ellipse", &WPG1Parser::handleEllipse }, - { 0x0a, "Reserved", 0 }, - { 0x0b, "Bitmap (Type 1)", &WPG1Parser::handleBitmapTypeOne }, - { 0x0c, "Graphics Text (Type 1)", 0 }, - { 0x0d, "Grephics Text Attributes", 0 }, - { 0x0e, "Colormap", &WPG1Parser::handleColormap }, - { 0x0f, "Start WPG", &WPG1Parser::handleStartWPG }, - { 0x10, "End WPG", &WPG1Parser::handleEndWPG }, - { 0x11, "Postscript Data Follows", 0 }, - { 0x12, "Output Attributes", 0 }, - { 0x13, "Curved Polyline", &WPG1Parser::handleCurvedPolyline }, - { 0x14, "Bitmap (Type 2)", &WPG1Parser::handleBitmapTypeTwo }, - { 0x15, "Start Figure", 0 }, - { 0x16, "Start Chart", 0 }, - { 0x17, "Planperfect Data", 0 }, - { 0x18, "Graphics Text (Type 2)", 0 }, - { 0x19, "Start WPG (Type 2)", 0 }, - { 0x1a, "Graphics Text (Type 3)", 0 }, - { 0x1b, "Ellipse", 0 }, + { 0x01, "Fill Attributes", &WPG1Parser::handleFillAttributes }, + { 0x02, "Line Attributes", &WPG1Parser::handleLineAttributes }, + { 0x03, "Marker Atttibutes", 0 }, + { 0x04, "Polymarker", 0 }, + { 0x05, "Line", &WPG1Parser::handleLine }, + { 0x06, "Polyline", &WPG1Parser::handlePolyline }, + { 0x07, "Rectangle", &WPG1Parser::handleRectangle }, + { 0x08, "Polygon", &WPG1Parser::handlePolygon }, + { 0x09, "Ellipse", &WPG1Parser::handleEllipse }, + { 0x0a, "Reserved", 0 }, + { 0x0b, "Bitmap (Type 1)", &WPG1Parser::handleBitmapTypeOne }, + { 0x0c, "Graphics Text (Type 1)", 0 }, + { 0x0d, "Grephics Text Attributes", 0 }, + { 0x0e, "Colormap", &WPG1Parser::handleColormap }, + { 0x0f, "Start WPG", &WPG1Parser::handleStartWPG }, + { 0x10, "End WPG", &WPG1Parser::handleEndWPG }, + { 0x11, "Postscript Data (Type 1)", &WPG1Parser::handlePostscriptTypeOne }, + { 0x12, "Output Attributes", 0 }, + { 0x13, "Curved Polyline", &WPG1Parser::handleCurvedPolyline }, + { 0x14, "Bitmap (Type 2)", &WPG1Parser::handleBitmapTypeTwo }, + { 0x15, "Start Figure", 0 }, + { 0x16, "Start Chart", 0 }, + { 0x17, "Planperfect Data", 0 }, + { 0x18, "Graphics Text (Type 2)", 0 }, + { 0x19, "Start WPG (Type 2)", 0 }, + { 0x1a, "Graphics Text (Type 3)", 0 }, + { 0x1b, "Postscript Data (Type 2)", &WPG1Parser::handlePostscriptTypeTwo }, { 0x00, 0, 0 } // end marker }; @@ -733,6 +733,76 @@ } } +void WPG1Parser::handlePostscriptTypeOne() +{ + if (!m_graphicsStarted) + return; + long x1 = readS16(); + long y1 = readS16(); + long x2 = readS16(); + long y2 = readS16(); + libwpg::WPGBinaryData data; + data.rect.x1 = (double)x1/72.0; + data.rect.y1 = (double)m_height/1200.0 - (double)y1/72.0; + data.rect.x2 = (double)x2/72.0; + data.rect.y2 = (double)m_height/1200.0 - (double)y2/72.0; + + data.clear(); + while (m_input->tell() <= m_recordEnd) + data.append((char)readU8()); + data.mimeType = "application/x-postscript"; + if (data.size()) + m_painter->drawImageObject(data); +} + +void WPG1Parser::handlePostscriptTypeTwo() +{ + if (!m_graphicsStarted) + return; +#ifdef DEBUG + size_t lengthOfData = readU32(); + int rotation = readS16(); +#else + readU32(); + readS16(); +#endif + int x1 = readS16(); + int y1 = readS16(); + int x2 = readS16(); + int y2 = readS16(); + + WPG_DEBUG_MSG(("Postscript (Type 2)\n")); + WPG_DEBUG_MSG((" Length of Data: %d\n", lengthOfData)); + WPG_DEBUG_MSG((" Rotation Angle: %d\n", rotation)); + WPG_DEBUG_MSG((" Bottom left corner: %d,%d\n", x1, y1)); + WPG_DEBUG_MSG((" Top right corner: %d,%d\n", x2, y2)); + + y1 = m_height - y1; + y2 = m_height - y2; + + long xs1 = (x1 <= x2) ? x1 : x2; + long xs2 = (x1 <= x2) ? x2 : x1; + long ys1 = (y1 <= y2) ? y1 : y2; + long ys2 = (y1 <= y2) ? y2 : y1; + WPG_DEBUG_MSG(("%li %li %li %li\n", xs1, ys1, xs2, ys2)); + + libwpg::WPGBinaryData data; + data.rect.x1 = (double)xs1/1200.0; + data.rect.y1 = (double)(ys1)/1200.0; + data.rect.x2 = (double)xs2/1200.0; + data.rect.y2 = (double)(ys2)/1200.0; + + data.mimeType = "image/x-eps"; + + m_input->seek(48, WPX_SEEK_CUR); + + data.clear(); + while (m_input->tell() <= m_recordEnd) + data.append((char)readU8()); + if (data.size()) + m_painter->drawImageObject(data); +} + void WPG1Parser::resetPalette() { m_colorPalette.clear(); |