UT_Error IE_Imp_GraphicAsDocument::_loadFile(GsfInput * input) { UT_Error error; UT_DEBUGMSG(("trying to open an image as a document...\n")); if (!getDoc()->appendStrux(PTX_Section, NULL) || !getDoc()->appendStrux(PTX_Block, NULL)) return UT_IE_NOMEMORY; FG_Graphic* pFG; error = m_pGraphicImporter->importGraphic(input, &pFG); DELETEP(m_pGraphicImporter); if (error != UT_OK) return error; const UT_ByteBuf * buf; buf = pFG->getBuffer(); const gchar* propsArray[3]; propsArray[0] = "dataid"; propsArray[1] = "image_0"; propsArray[2] = NULL; if (!getDoc()->appendObject(PTO_Image, propsArray)) { delete pFG; return UT_IE_NOMEMORY; } if (!getDoc()->createDataItem("image_0", false, buf, pFG->getMimeType(), NULL)) { delete pFG; return UT_IE_NOMEMORY; } delete pFG; return UT_OK; }
void AP_FormatTable_preview::draw(const UT_Rect *clip) { UT_UNUSED(clip); GR_Painter painter(m_gc); UT_sint32 iWidth = m_gc->tlu (getWindowWidth()); UT_sint32 iHeight = m_gc->tlu (getWindowHeight()); UT_Rect pageRect(m_gc->tlu(7), m_gc->tlu(7), iWidth - m_gc->tlu(14), iHeight - m_gc->tlu(14)); painter.fillRect(GR_Graphics::CLR3D_Background, 0, 0, iWidth, iHeight); painter.clearArea(pageRect.left, pageRect.top, pageRect.width, pageRect.height); UT_RGBColor tmpCol; UT_RGBColor black(0, 0, 0); m_gc->setLineWidth(m_gc->tlu(1)); int border = m_gc->tlu(20); int cornerLength = m_gc->tlu(5); // // Draw the cell background // const gchar * pszBGCol = NULL; if(m_pFormatTable->getImage()) { GR_Image * pImg = m_pFormatTable->getImage(); FG_Graphic * pFG = m_pFormatTable->getGraphic(); const char * szName = pFG->getDataId(); const UT_ByteBuf * pBB = pFG->getBuffer(); if(pFG->getType() == FGT_Raster) { pImg = static_cast<GR_Image *>( m_gc->createNewImage( szName, pBB, pFG->getMimeType(), pageRect.width - 2*border, pageRect.height - 2*border, GR_Image::GRT_Raster)); } else { pImg = static_cast<GR_Image *>( m_gc->createNewImage( szName, pBB, pFG->getMimeType(), pageRect.width - 2*border, pageRect.height - 2*border, GR_Image::GRT_Vector)); } UT_Rect rec(pageRect.left + border, pageRect.top + border, pageRect.width - 2*border, pageRect.height - 2*border); painter.drawImage(pImg,pageRect.left + border, pageRect.top + border); delete pImg; } else { m_pFormatTable->getPropVector().getProp(static_cast<const gchar *>("background-color"), pszBGCol); if (pszBGCol && *pszBGCol) { UT_parseColor(pszBGCol, tmpCol); painter.fillRect(tmpCol, pageRect.left + border, pageRect.top + border, pageRect.width - 2*border, pageRect.height - 2*border); } } // // Draw the cell corners // m_gc->setColor(UT_RGBColor(127,127,127)); // top left corner painter.drawLine(pageRect.left + border - cornerLength, pageRect.top + border, pageRect.left + border, pageRect.top + border); painter.drawLine(pageRect.left + border, pageRect.top + border - cornerLength, pageRect.left + border, pageRect.top + border); // top right corner painter.drawLine(pageRect.left + pageRect.width - border + cornerLength, pageRect.top + border, pageRect.left + pageRect.width - border, pageRect.top + border); painter.drawLine(pageRect.left + pageRect.width - border, pageRect.top + border - cornerLength, pageRect.left + pageRect.width - border, pageRect.top + border); // bottom left corner painter.drawLine(pageRect.left + border - cornerLength, pageRect.top + pageRect.height - border, pageRect.left + border, pageRect.top + pageRect.height - border); painter.drawLine(pageRect.left + border, pageRect.top + pageRect.height - border + cornerLength, pageRect.left + border, pageRect.top + pageRect.height - border); // bottom right corner painter.drawLine(pageRect.left + pageRect.width - border + cornerLength, pageRect.top + pageRect.height - border, pageRect.left + pageRect.width - border, pageRect.top + pageRect.height - border); painter.drawLine(pageRect.left + pageRect.width - border, pageRect.top + pageRect.height - border + cornerLength, pageRect.left + pageRect.width - border, pageRect.top + pageRect.height - border); // // Draw the cell borders // // top border if (m_pFormatTable->getTopToggled()) { const gchar * pszTopColor = NULL; m_pFormatTable->getPropVector().getProp("top-color", pszTopColor); if (pszTopColor) { UT_parseColor(pszTopColor, tmpCol); m_gc->setColor(tmpCol); } else m_gc->setColor(black); const gchar * pszTopThickness = NULL; m_pFormatTable->getPropVector().getProp("top-thickness", pszTopThickness); if(pszTopThickness) { UT_sint32 iTopThickness = UT_convertToLogicalUnits(pszTopThickness); m_gc->setLineWidth(iTopThickness); } else { m_gc->setLineWidth(m_gc->tlu(1)); } painter.drawLine(pageRect.left + border, pageRect.top + border, pageRect.left + pageRect.width - border, pageRect.top + border); } // left border if (m_pFormatTable->getLeftToggled()) { const gchar * pszLeftColor = NULL; m_pFormatTable->getPropVector().getProp("left-color", pszLeftColor); if (pszLeftColor) { UT_parseColor(pszLeftColor, tmpCol); m_gc->setColor(tmpCol); } else m_gc->setColor(black); const gchar * pszLeftThickness = NULL; m_pFormatTable->getPropVector().getProp("left-thickness", pszLeftThickness); if(pszLeftThickness) { UT_sint32 iLeftThickness = UT_convertToLogicalUnits(pszLeftThickness); m_gc->setLineWidth(iLeftThickness); } else { m_gc->setLineWidth(m_gc->tlu(1)); } painter.drawLine(pageRect.left + border, pageRect.top + border, pageRect.left + border, pageRect.top + pageRect.height - border); } // right border if (m_pFormatTable->getRightToggled()) { const gchar * pszRightColor = NULL; m_pFormatTable->getPropVector().getProp("right-color", pszRightColor); if (pszRightColor) { UT_parseColor(pszRightColor, tmpCol); m_gc->setColor(tmpCol); } else m_gc->setColor(black); const gchar * pszRightThickness = NULL; m_pFormatTable->getPropVector().getProp("right-thickness", pszRightThickness); if(pszRightThickness) { UT_sint32 iRightThickness = UT_convertToLogicalUnits(pszRightThickness); m_gc->setLineWidth(iRightThickness); } else { m_gc->setLineWidth(m_gc->tlu(1)); } painter.drawLine(pageRect.left + pageRect.width - border, pageRect.top + border, pageRect.left + pageRect.width - border, pageRect.top + pageRect.height - border); } // bottom border if (m_pFormatTable->getBottomToggled()) { const gchar * pszBottomColor = NULL; m_pFormatTable->getPropVector().getProp("bot-color", pszBottomColor); if (pszBottomColor) { UT_parseColor(pszBottomColor, tmpCol); m_gc->setColor(tmpCol); } else m_gc->setColor(black); const gchar * pszBotThickness = NULL; m_pFormatTable->getPropVector().getProp("bot-thickness", pszBotThickness); if(pszBotThickness) { UT_sint32 iBotThickness = UT_convertToLogicalUnits(pszBotThickness); m_gc->setLineWidth(iBotThickness); } else { m_gc->setLineWidth(m_gc->tlu(1)); } painter.drawLine(pageRect.left + border, pageRect.top + pageRect.height - border, pageRect.left + pageRect.width - border, pageRect.top + pageRect.height - border); } }
/** * Adds an data item (<d> tag) in the AbiWord document for the specified image. * * Code mainly from Dom Lachowicz and/or Robert Staudinger. * * @param rDataId Receives the id that has been given to the added data item. * @param ppAtts The attributes of a <draw:image> element. */ bool ODi_Abi_Data::addImageDataItem(UT_String& rDataId, const gchar** ppAtts) { const gchar* pHRef = UT_getAttribute ("xlink:href", ppAtts); UT_return_val_if_fail(pHRef,false); // If we have a string smaller then this we are in trouble. File corrupted? UT_return_val_if_fail((strlen(pHRef) >= 10 /*10 == strlen("Pictures/a")*/), false); UT_Error error = UT_OK; UT_ByteBuf img_buf; GsfInfile* pPictures_dir; FG_Graphic* pFG = NULL; const UT_ByteBuf* pPictData = NULL; UT_uint32 imageID; // The subdirectory that holds the picture. e.g: "ObjectReplacements" or "Pictures" UT_String dirName; // The file name of the picture. e.g.: "Object 1" or "10000201000000D100000108FF0E3707.png" UT_String fileName; const std::string id = m_href_to_id[pHRef]; if (!id.empty()) { // This image was already added. // Use the existing data item id. rDataId = id; return true; } // Get a new, unique, ID. imageID = m_pAbiDocument->getUID(UT_UniqueId::Image); UT_String_sprintf(rDataId, "%d", imageID); // Add this id to the list UT_DebugOnly<href_id_map_t::iterator> iter = m_href_to_id .insert(m_href_to_id.begin(), href_id_map_t::value_type(pHRef, rDataId.c_str())); UT_ASSERT((href_id_map_t::iterator)iter != m_href_to_id.end()); _splitDirectoryAndFileName(pHRef, dirName, fileName); pPictures_dir = GSF_INFILE(gsf_infile_child_by_name(m_pGsfInfile, dirName.c_str())); UT_return_val_if_fail(pPictures_dir, false); // Loads img_buf error = _loadStream(pPictures_dir, fileName.c_str(), img_buf); g_object_unref (G_OBJECT (pPictures_dir)); if (error != UT_OK) { return false; } // Builds pImporter from img_buf error = IE_ImpGraphic::loadGraphic (img_buf, IEGFT_Unknown, &pFG); if ((error != UT_OK) || !pFG) { // pictData is already freed in ~FG_Graphic return false; } // Builds pPictData from pFG // TODO: can we get back a vector graphic? pPictData = pFG->getBuffer(); if (!pPictData) { // i don't think that this could ever happen, but... UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN); return false; } // // Create the data item. // if (!m_pAbiDocument->createDataItem(rDataId.c_str(), false, pPictData, pFG->getMimeType(), NULL)) { UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN); return false; } return true; }
void AP_Dialog_FormatTable::setCurCellProps(void) { XAP_Frame *frame = XAP_App::getApp()->getLastFocussedFrame(); if (frame) { FV_View * pView = static_cast<FV_View *>(frame->getCurrentView()); if (m_bSettingsChanged || m_iOldPos == pView->getPoint()) // comparing the actual cell pos would be even better; but who cares :) return; m_iOldPos = pView->getPoint(); /* * update the border colors */ gchar * color = NULL; if (pView->getCellProperty("left-color", color)) m_vecProps.addOrReplaceProp("left-color", color); else m_vecProps.removeProp("left-color"); if (pView->getCellProperty("right-color", color)) m_vecProps.addOrReplaceProp("right-color", color); else m_vecProps.removeProp("right-color"); if (pView->getCellProperty("top-color", color)) m_vecProps.addOrReplaceProp("top-color", color); else m_vecProps.removeProp("top-color"); if (pView->getCellProperty("bot-color", color)) m_vecProps.addOrReplaceProp("bot-color", color); else m_vecProps.removeProp("bot-color"); /* * update the background color */ UT_RGBColor clr; gchar * bgColor = NULL; if (pView->getCellProperty("background-color", bgColor)) { m_vecProps.addOrReplaceProp("background-color", bgColor); clr.setColor(bgColor); setBackgroundColorInGUI(clr); } else { m_vecProps.removeProp("background-color"); setBackgroundColorInGUI(UT_RGBColor(255,255,255)); // No color == white for now - MARCM } if(pView->isImageAtStrux(m_iOldPos,PTX_SectionCell)) { if(pView->isInTable()) { fl_BlockLayout * pBL = pView->getCurrentBlock(); fl_CellLayout * pCell = static_cast<fl_CellLayout *>(pBL->myContainingLayout()); if(pCell->getContainerType() != FL_CONTAINER_CELL) { UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN); DELETEP(m_pGraphic); DELETEP(m_pImage); m_sImagePath.clear(); } else { FG_Graphic * pFG = FG_GraphicRaster::createFromStrux(pCell); if(pFG) { DELETEP(m_pGraphic); DELETEP(m_pImage); m_sImagePath.clear(); m_pGraphic = pFG; m_sImagePath = pFG->getDataId(); GR_Graphics * pG = m_pFormatTablePreview->getGraphics(); const UT_ByteBuf * pBB = pFG->getBuffer(); if(m_pGraphic->getType() == FGT_Raster) { m_pImage = static_cast<GR_Image *>( pG->createNewImage( m_sImagePath.c_str(), pBB, pFG->getMimeType(), pFG->getWidth(), pFG->getHeight(), GR_Image::GRT_Raster)); } else { m_pImage = static_cast<GR_Image *>( pG->createNewImage( m_sImagePath.c_str(), pBB, pFG->getMimeType(), m_pFormatTablePreview->getWindowWidth()-2, m_pFormatTablePreview->getWindowHeight()-2, GR_Image::GRT_Vector)); } } } } else { DELETEP(m_pGraphic); DELETEP(m_pImage); m_sImagePath.clear(); } } else { DELETEP(m_pGraphic); DELETEP(m_pImage); m_sImagePath.clear(); } UT_String bstmp = UT_String_sprintf("%d", FS_FILL); m_vecProps.addOrReplaceProp("bg-style", bstmp.c_str()); // draw the preview with the changed properties if(m_pFormatTablePreview) m_pFormatTablePreview->queueDraw(); } }