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;
}
예제 #2
0
/**
 * 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;
}
예제 #3
0
void AP_FormatFrame_preview::draw(void)
{
	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_pFormatFrame->getImage())
	{
		GR_Image * pImg = m_pFormatFrame->getImage();
		FG_Graphic * pFG = m_pFormatFrame->getGraphic();
		const char * szName = pFG->getDataId();
        const UT_ByteBuf * pBB = static_cast<FG_GraphicRaster *>(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_pFormatFrame->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
//
	// right border
	if (m_pFormatFrame->getRightToggled())
	{
		UT_sint32 linestyle = m_pFormatFrame->borderLineStyleRight();
		if (linestyle == LS_DOTTED)
			m_gc->setLineProperties(1, GR_Graphics::JOIN_MITER, GR_Graphics::CAP_BUTT, GR_Graphics::LINE_DOTTED);
		else if (linestyle == LS_DASHED)
			m_gc->setLineProperties(1, GR_Graphics::JOIN_MITER, GR_Graphics::CAP_BUTT, GR_Graphics::LINE_ON_OFF_DASH);
		else
			m_gc->setLineProperties(1, GR_Graphics::JOIN_MITER, GR_Graphics::CAP_BUTT, GR_Graphics::LINE_SOLID);

		m_gc->setColor(m_pFormatFrame->borderColorRight());

		UT_sint32 iRightThickness = UT_convertToLogicalUnits(m_pFormatFrame->getBorderThicknessRight().utf8_str());
		m_gc->setLineWidth(iRightThickness);

		painter.drawLine(pageRect.left + pageRect.width - border, pageRect.top + border,
						 pageRect.left + pageRect.width - border, pageRect.top + pageRect.height - border);
	}

	// left border
	if (m_pFormatFrame->getLeftToggled())
	{
		UT_sint32 linestyle = m_pFormatFrame->borderLineStyleLeft();
		if (linestyle == LS_DOTTED)
			m_gc->setLineProperties(1, GR_Graphics::JOIN_MITER, GR_Graphics::CAP_BUTT, GR_Graphics::LINE_DOTTED);
		else if (linestyle == LS_DASHED)
			m_gc->setLineProperties(1, GR_Graphics::JOIN_MITER, GR_Graphics::CAP_BUTT, GR_Graphics::LINE_ON_OFF_DASH);
		else
			m_gc->setLineProperties(1, GR_Graphics::JOIN_MITER, GR_Graphics::CAP_BUTT, GR_Graphics::LINE_SOLID);

		m_gc->setColor(m_pFormatFrame->borderColorLeft());

		UT_sint32 iLeftThickness = UT_convertToLogicalUnits(m_pFormatFrame->getBorderThicknessLeft().utf8_str());
		m_gc->setLineWidth(iLeftThickness);

		painter.drawLine(pageRect.left + border, pageRect.top + border,
						 pageRect.left + border, pageRect.top + pageRect.height - border);
	}

	// top border
	if (m_pFormatFrame->getTopToggled())
	{
		UT_sint32 linestyle = m_pFormatFrame->borderLineStyleTop();
		if (linestyle == LS_DOTTED)
			m_gc->setLineProperties(1, GR_Graphics::JOIN_MITER, GR_Graphics::CAP_BUTT, GR_Graphics::LINE_DOTTED);
		else if (linestyle == LS_DASHED)
			m_gc->setLineProperties(1, GR_Graphics::JOIN_MITER, GR_Graphics::CAP_BUTT, GR_Graphics::LINE_ON_OFF_DASH);
		else
			m_gc->setLineProperties(1, GR_Graphics::JOIN_MITER, GR_Graphics::CAP_BUTT, GR_Graphics::LINE_SOLID);

		m_gc->setColor(m_pFormatFrame->borderColorTop());		
		UT_sint32 iTopThickness = UT_convertToLogicalUnits(m_pFormatFrame->getBorderThicknessTop().utf8_str());
		m_gc->setLineWidth(iTopThickness);

		painter.drawLine(pageRect.left + border, pageRect.top + border,
						 pageRect.left + pageRect.width - border, pageRect.top + border);
	}

	// bottom border
	if (m_pFormatFrame->getBottomToggled())
	{
		UT_sint32 linestyle = m_pFormatFrame->borderLineStyleBottom();
		if (linestyle == LS_DOTTED)
			m_gc->setLineProperties(1, GR_Graphics::JOIN_MITER, GR_Graphics::CAP_BUTT, GR_Graphics::LINE_DOTTED);
		else if (linestyle == LS_DASHED)
			m_gc->setLineProperties(1, GR_Graphics::JOIN_MITER, GR_Graphics::CAP_BUTT, GR_Graphics::LINE_ON_OFF_DASH);
		else
			m_gc->setLineProperties(1, GR_Graphics::JOIN_MITER, GR_Graphics::CAP_BUTT, GR_Graphics::LINE_SOLID);

		m_gc->setColor(m_pFormatFrame->borderColorBottom());

		UT_sint32 iBottomThickness = UT_convertToLogicalUnits(m_pFormatFrame->getBorderThicknessBottom().utf8_str());
		m_gc->setLineWidth(iBottomThickness);

		painter.drawLine(pageRect.left + border, pageRect.top + pageRect.height - border,
						 pageRect.left + pageRect.width - border, pageRect.top + pageRect.height - border);
	}
}
예제 #4
0
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);
    }
}
예제 #5
0
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();
    }
}
예제 #6
0
/*!
 * Import graphic for cell background.
 */
void AP_Dialog_FormatTable::askForGraphicPathName(void)
{
    XAP_Frame * pFrame = XAP_App::getApp()->getLastFocussedFrame();

    UT_return_if_fail(pFrame);
    XAP_DialogFactory * pDialogFactory
        = static_cast<XAP_DialogFactory *>(pFrame->getDialogFactory());

    UT_return_if_fail(pDialogFactory);
    XAP_Dialog_FileOpenSaveAs * pDialog
        = static_cast<XAP_Dialog_FileOpenSaveAs *>(pDialogFactory->requestDialog(XAP_DIALOG_ID_INSERT_PICTURE));
    UT_return_if_fail (pDialog);

    pDialog->setCurrentPathname(NULL);
    pDialog->setSuggestFilename(false);

    // to fill the file types popup list, we need to convert AP-level
    // ImpGraphic descriptions, suffixes, and types into strings.

    UT_uint32 filterCount = IE_ImpGraphic::getImporterCount();

    const char ** szDescList = static_cast<const char **>(UT_calloc(filterCount + 1, sizeof(char *)));
    const char ** szSuffixList = static_cast<const char **>(UT_calloc(filterCount + 1, sizeof(char *)));
    IEGraphicFileType * nTypeList = (IEGraphicFileType *)
                                    UT_calloc(filterCount + 1,	sizeof(IEGraphicFileType));
    UT_uint32 k = 0;

    while (IE_ImpGraphic::enumerateDlgLabels(k, &szDescList[k], &szSuffixList[k], &nTypeList[k]))
        k++;

    pDialog->setFileTypeList(szDescList, szSuffixList, static_cast<const UT_sint32 *>(nTypeList));
    pDialog->runModal(pFrame);

    XAP_Dialog_FileOpenSaveAs::tAnswer ans = pDialog->getAnswer();
    bool bOK = (ans == XAP_Dialog_FileOpenSaveAs::a_OK);

    if (bOK)
    {
        m_sImagePath = pDialog->getPathname();
        UT_sint32 type = pDialog->getFileType();

        // If the number is negative, it's a special type.
        // Some operating systems which depend solely on filename
        // suffixes to identify type (like Windows) will always
        // want auto-detection.
        if (type < 0)
            switch (type)
            {
            case XAP_DIALOG_FILEOPENSAVEAS_FILE_TYPE_AUTO:
                // do some automagical detecting
                m_iGraphicType = IEGFT_Unknown;
                break;
            default:
                // it returned a type we don't know how to handle
                UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
            }
        else
            m_iGraphicType = static_cast<IEGraphicFileType>(pDialog->getFileType());
    }

    FREEP(szDescList);
    FREEP(szSuffixList);
    FREEP(nTypeList);

    pDialogFactory->releaseDialog(pDialog);
    if(m_sImagePath.size() == 0)
    {
        return;
    }

    FG_Graphic* pFG = NULL;

    UT_Error errorCode;

    errorCode = IE_ImpGraphic::loadGraphic(m_sImagePath.c_str(), m_iGraphicType, &pFG);
    if(errorCode != UT_OK || !pFG)
    {
        ShowErrorBox(m_sImagePath, errorCode);
        return;
    }

    DELETEP(m_pGraphic);
    DELETEP(m_pImage);
    m_pGraphic = pFG->clone();
    GR_Graphics * pG = m_pFormatTablePreview->getGraphics();

    FV_View * pView = static_cast<FV_View *>(pFrame->getCurrentView());
    UT_return_if_fail(pView && pView->getDocument());

    UT_uint32 uid = pView->getDocument()->getUID(UT_UniqueId::Image); //see Bug 10852
    m_sImagePath.clear();
    UT_String_sprintf(m_sImagePath,"%d",uid);

    const UT_ByteBuf * pBB = m_pGraphic->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));
    }

    // draw the preview with the changed properties
    if(m_pFormatTablePreview)
        m_pFormatTablePreview->queueDraw();

}