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
void AP_Dialog_FormatFrame::setCurFrameProps(void)
{
	XAP_Frame * frame = m_pApp->getLastFocussedFrame();
	if (!frame) {
		if (m_bSensitive) {
			m_bSensitive = false;
			setAllSensitivities();
		}
		return;
	}

	FV_View * pView = static_cast<FV_View *>(frame->getCurrentView());
	if (!pView) {
		if (m_bSensitive) {
			m_bSensitive = false;
			setAllSensitivities();
		}
		return;
	}

	PT_DocPosition pos = pView->getPoint();

	if (/* m_bSettingsChanged || */ m_iOldPos == pos) {
		// comparing the actual cell pos would be even better; but who cares :)
		return;
	}
	m_iOldPos = pos;

	if (!pView->isInFrame(pos)) {
		if (m_bSensitive) {
			m_bSensitive = false;
			setAllSensitivities();
		}
		return;
	}

	m_bLineToggled = false;

	m_borderLineStyleRight  = LS_NORMAL;
	m_borderLineStyleLeft   = LS_NORMAL;
	m_borderLineStyleTop    = LS_NORMAL;
	m_borderLineStyleBottom = LS_NORMAL;

	UT_RGBColor black(0,0,0);
	UT_RGBColor white(255,255,255);

	m_borderColor = black;

	m_borderColorRight  = black;
	m_borderColorLeft   = black;
	m_borderColorTop    = black;
	m_borderColorBottom = black;

	m_borderThicknessRight  = 1.0f;
	m_borderThicknessLeft   = 1.0f;
	m_borderThicknessTop    = 1.0f;
	m_borderThicknessBottom = 1.0f;

	m_sBorderThickness = "1.00pt",
 
	m_sBorderThicknessRight  = "1.00pt";
	m_sBorderThicknessLeft   = "1.00pt";
	m_sBorderThicknessTop    = "1.00pt";
	m_sBorderThicknessBottom = "1.00pt";

	m_backgroundColor = white;

	m_bSetWrapping = false;

	m_iFramePositionTo = FL_FRAME_POSITIONED_TO_BLOCK;

	PD_Document * pDoc = pView->getDocument();

	PL_StruxDocHandle sdh;

	m_bSensitive = false;

	if (pDoc->getStruxOfTypeFromPosition(pos, PTX_SectionFrame, &sdh))
		if (PT_AttrPropIndex api = pDoc->getAPIFromSDH(sdh)) {
			const PP_AttrProp * pAP = 0;
			if (pDoc->getAttrProp(api, &pAP))
				if (pAP) {
					m_bSensitive = true;

#define REPLACE_CELL_PROPERTY(X) \
	do { \
		const gchar * prop = 0; \
		if (pAP->getProperty(X, prop)) \
			m_vecProps.addOrReplaceProp(X, prop); \
		else \
			m_vecProps.removeProp(X); \
	} while (0)

					REPLACE_CELL_PROPERTY("right-style");
					REPLACE_CELL_PROPERTY("left-style");
					REPLACE_CELL_PROPERTY("top-style");
					REPLACE_CELL_PROPERTY("bot-style");

					REPLACE_CELL_PROPERTY("right-thickness");
					REPLACE_CELL_PROPERTY("left-thickness");
					REPLACE_CELL_PROPERTY("top-thickness");
					REPLACE_CELL_PROPERTY("bot-thickness");

					REPLACE_CELL_PROPERTY("right-color");
					REPLACE_CELL_PROPERTY("left-color");
					REPLACE_CELL_PROPERTY("top-color");
					REPLACE_CELL_PROPERTY("bot-color");

					REPLACE_CELL_PROPERTY("background-color");

					REPLACE_CELL_PROPERTY("wrap-mode");
					REPLACE_CELL_PROPERTY("position-to");
				}
		}
	if (!m_bSensitive) {
		setAllSensitivities();
		return;
	}

	if(pView->isImageAtStrux(m_iOldPos,PTX_SectionFrame))
	{
		if(true /* pView->isInFrame(pView->getPoint()) */)
		{
			fl_BlockLayout * pBL = pView->getCurrentBlock();
			fl_FrameLayout * pFrame = static_cast<fl_FrameLayout *>(pBL->myContainingLayout());
			if(pFrame->getContainerType() != FL_CONTAINER_FRAME)
			{
				UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
				DELETEP(m_pGraphic);
				DELETEP(m_pImage);
				m_sImagePath.clear();
			}
			else
			{
				FG_Graphic * pFG = FG_GraphicRaster::createFromStrux(pFrame);
				if(pFG)
				{
					DELETEP(m_pGraphic);
					DELETEP(m_pImage);
					m_sImagePath.clear();
					m_pGraphic = pFG;
					m_sImagePath = pFG->getDataId();

					GR_Graphics * pG = m_pFormatFramePreview->getGraphics();
                    m_pImage = _makeImageForRaster(m_sImagePath, pG, m_pGraphic);
				}
			}
		}
		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()); // FIXME ??
		
	const gchar * pszStyle = 0;
	m_vecProps.getProp("background-color", pszStyle);
	if (pszStyle) {
		m_backgroundColor.setColor(pszStyle);
	}

	/* update border properties
	 */
	long linestyle;

	pszStyle = 0;
	m_vecProps.getProp("right-style", pszStyle);
	if (pszStyle) {
		linestyle = LS_NORMAL;
		sscanf(pszStyle, "%ld", &linestyle);
		m_borderLineStyleRight = linestyle;
	}
	pszStyle = 0;
	m_vecProps.getProp("left-style", pszStyle);
	if (pszStyle) {
		linestyle = LS_NORMAL;
		sscanf(pszStyle, "%ld", &linestyle);
		m_borderLineStyleLeft = linestyle;
	}
	pszStyle = 0;
	m_vecProps.getProp("top-style", pszStyle);
	if (pszStyle) {
		linestyle = LS_NORMAL;
		sscanf(pszStyle, "%ld", &linestyle);
		m_borderLineStyleTop = linestyle;
	}
	pszStyle = 0;
	m_vecProps.getProp("bot-style", pszStyle);
	if (pszStyle) {
		linestyle = LS_NORMAL;
		sscanf(pszStyle, "%ld", &linestyle);
		m_borderLineStyleBottom = linestyle;
	}

	pszStyle = 0;
	m_vecProps.getProp("right-color", pszStyle);
	if (pszStyle) {
		m_borderColorRight.setColor(pszStyle);
	}
	pszStyle = 0;
	m_vecProps.getProp("left-color", pszStyle);
	if (pszStyle) {
		m_borderColorLeft.setColor(pszStyle);
	}
	pszStyle = 0;
	m_vecProps.getProp("top-color", pszStyle);
	if (pszStyle) {
		m_borderColorTop.setColor(pszStyle);
	}
	pszStyle = 0;
	m_vecProps.getProp("bot-color", pszStyle);
	if (pszStyle) {
		m_borderColorBottom.setColor(pszStyle);
	}

	UT_UTF8String thickness;

	pszStyle = 0;
	m_vecProps.getProp("right-thickness", pszStyle);
	if (pszStyle) {
		thickness = pszStyle;
		setBorderThicknessRight(thickness);
	}
	pszStyle = 0;
	m_vecProps.getProp("left-thickness", pszStyle);
	if (pszStyle) {
		thickness = pszStyle;
		setBorderThicknessLeft(thickness);
	}
	pszStyle = 0;
	m_vecProps.getProp("top-thickness", pszStyle);
	if (pszStyle) {
		thickness = pszStyle;
		setBorderThicknessTop(thickness);
	}
	pszStyle = 0;
	m_vecProps.getProp("bot-thickness", pszStyle);
	if (pszStyle) {
		thickness = pszStyle;
		setBorderThicknessBottom(thickness);
	}

	/* update wrap properties
	 */
	pszStyle = 0;
	m_vecProps.getProp("wrap-mode", pszStyle);
	if (pszStyle) {
		if (strcmp (pszStyle, "wrapped-both") == 0) {
			m_bSetWrapping = true;
		}
	}

	/* update position properties
	 */
	pszStyle = 0;
	m_vecProps.getProp("position-to", pszStyle);
	if (pszStyle) {
		if (strcmp (pszStyle, "block-above-text") == 0) {
			m_iFramePositionTo = FL_FRAME_POSITIONED_TO_BLOCK;
		}
		else if (strcmp (pszStyle, "column-above-text") == 0) {
			m_iFramePositionTo = FL_FRAME_POSITIONED_TO_COLUMN;
		}
		else if (strcmp (pszStyle, "page-above-text") == 0) {
			m_iFramePositionTo = FL_FRAME_POSITIONED_TO_PAGE;
		}
	}

	/* draw the preview with the changed properties
	 */
	if(m_pFormatFramePreview) {
		m_pFormatFramePreview->draw();
	}

	m_bSettingsChanged = false;
	setActiveFrame(frame); // this is just to trigger the subclass to update the dialog
}
示例#3
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;
}
示例#4
0
/*!
 * Import graphic for cell background.
 */
void AP_Dialog_FormatFrame::askForGraphicPathName(void)
{
	UT_return_if_fail(m_pApp);
	XAP_Frame * pFrame = m_pApp->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_pFormatFramePreview->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 10851
	m_sImagePath.clear();
	m_sImagePath = UT_std_string_sprintf("%d",uid);

    m_pImage = _makeImageForRaster(m_sImagePath, pG, m_pGraphic);

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

}
示例#5
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);
	}
}
/*!
  Load the picture data
  \param format the Picture Format.
  \param image_name the name of the image. Must be unique.
  \param imgProps the RTF properties for the image.
  \return true if success, otherwise false.
  \desc Load the picture data from the flow. Will move the file position
  and assume proper RTF file structure. It will take care of inserting
  the picture into the document.
  \todo TODO: We assume the data comes in hex. Check this assumption
  as we might have to handle binary data as well
  \see IE_Imp_RTF::HandlePicture
*/
bool IE_Imp_RTF::LoadPictData(PictFormat format, const char * image_name,
							  struct RTFProps_ImageProps & imgProps, 
							  bool isBinary, long binaryLen)
{
	// first, we load the actual data into a buffer
	bool ok;
	bool retval = true;

	const UT_uint16 chars_per_byte = 2;
	const UT_uint16 BITS_PER_BYTE = 8;
	const UT_uint16 bits_per_char = BITS_PER_BYTE / chars_per_byte;

	UT_ByteBuf pictData;
	UT_uint16 chLeft = chars_per_byte;
	UT_Byte pic_byte = 0;
	FG_Graphic* pFG = NULL;
	UT_Error error = UT_OK;
	unsigned char ch;

	if (!isBinary) {
		if (!ReadCharFromFile(&ch)) {
			retval = false;
			goto cleanup;
		}

		while (ch != '}')
		{
			int digit;
			
			if (!hexVal(ch, digit)) {
				retval = false;
				goto cleanup;
			}
			
			pic_byte = (pic_byte << bits_per_char) + digit;
			
			// if we have a complete byte, we put it in the buffer
			if (--chLeft == 0)
			{
				pictData.append(&pic_byte, 1);
				chLeft = chars_per_byte;
				pic_byte = 0;
			}
			
			if (!ReadCharFromFile(&ch)) {
				retval = false;
				goto cleanup;
			}
		}
	} else {
		UT_ASSERT_HARMLESS(binaryLen);
		UT_DEBUGMSG(("Loading binary data image of %ld bytes\n", binaryLen));
		for (long i = 0; i < binaryLen; i++) {
			if (!ReadCharFromFileWithCRLF(&ch)) {
				retval = false;
				goto cleanup;
			}
			pictData.append(&ch, 1);
		}
	}

	// We let the caller handle this
	SkipBackChar(ch);

	error = IE_ImpGraphic::loadGraphic(pictData, iegftForRTF(format), &pFG);

	if ((error == UT_OK) && pFG)
	{
		imgProps.width = static_cast<UT_uint32>(pFG->getWidth ());
		imgProps.height = static_cast<UT_uint32>(pFG->getHeight ());
		// Not sure whether this is the right way, but first, we should
		// insert any pending chars
		if (!FlushStoredChars(true))
		{
			UT_DEBUGMSG(("Error flushing stored chars just before inserting a picture\n"));
			DELETEP(pFG);
			return false;
		}

		ok = InsertImage (pFG, image_name, imgProps);
		DELETEP(pFG);
		if (!ok)
		{
			return false;
		}
	}
	else
	{
		// if we're not inserting a graphic, we should destroy the buffer
		UT_DEBUGMSG (("no translator found: %d\n", error));
	}

 cleanup:
	return retval;
}
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);
    }
}
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();
    }
}