Esempio n. 1
0
/*!
 Set the color and style of the toggled button
 */
void AP_Dialog_FormatFrame::toggleLineType(toggle_button btn, bool enabled)
{
	UT_String cTmp = UT_String_sprintf("%02x%02x%02x", m_borderColor.m_red, m_borderColor.m_grn, m_borderColor.m_blu);	
	UT_String sTmp = UT_String_sprintf("%d", (enabled ? m_lineStyle : LS_OFF));

	switch (btn)
	{
		case toggle_left:
		{
			m_borderLineStyleLeft = enabled ? LS_NORMAL : LS_OFF;
			m_borderColorLeft = m_borderColor;
			setBorderThicknessLeft(m_sBorderThickness);
			m_vecProps.addOrReplaceProp("left-style", sTmp.c_str());
			m_vecProps.addOrReplaceProp("left-color", cTmp.c_str());
			m_vecProps.addOrReplaceProp("left-thickness",m_sBorderThickness.utf8_str());
		}
		break;

		case toggle_right:
		{	
			m_borderLineStyleRight = enabled ? LS_NORMAL : LS_OFF;
			m_borderColorRight = m_borderColor;
			setBorderThicknessRight(m_sBorderThickness);
			m_vecProps.addOrReplaceProp("right-style", sTmp.c_str());
			m_vecProps.addOrReplaceProp("right-color", cTmp.c_str());
			m_vecProps.addOrReplaceProp("right-thickness",m_sBorderThickness.utf8_str());
		}
		break;

		case toggle_top:
		{			
			m_borderLineStyleTop = enabled ? LS_NORMAL : LS_OFF;
			m_borderColorTop = m_borderColor;
			setBorderThicknessTop(m_sBorderThickness);
			m_vecProps.addOrReplaceProp("top-style", sTmp.c_str());
			m_vecProps.addOrReplaceProp("top-color", cTmp.c_str());
			m_vecProps.addOrReplaceProp("top-thickness",m_sBorderThickness.utf8_str());
		}
		break;

		case toggle_bottom:
		{			
			m_borderLineStyleBottom = enabled ? LS_NORMAL : LS_OFF;
			m_borderColorBottom = m_borderColor;
			setBorderThicknessBottom(m_sBorderThickness);
			m_vecProps.addOrReplaceProp("bot-style", sTmp.c_str());
			m_vecProps.addOrReplaceProp("bot-color", cTmp.c_str());
			m_vecProps.addOrReplaceProp("bot-thickness",m_sBorderThickness.utf8_str());
		}
		break;

	default:
		// should not happen
		break;
	}
	m_bLineToggled = true;
	m_bSettingsChanged = true;
}
void  AP_UnixDialog_FormatTOC::event_Apply(void)
{
	UT_DEBUGMSG(("Doing apply \n"));

// Heading Text

	GtkWidget * pW = _getWidget("edHeadingText");
	UT_UTF8String sVal;
	sVal = gtk_entry_get_text(GTK_ENTRY(pW));
	setTOCProperty("toc-heading",sVal.utf8_str());

// Text before and after

	pW = _getWidget("edTextAfter");
	sVal = gtk_entry_get_text(GTK_ENTRY(pW));
	UT_UTF8String sProp;
	sProp = static_cast<const char *> (g_object_get_data(G_OBJECT(pW),"toc-prop"));
	UT_String sNum =  UT_String_sprintf("%d",getDetailsLevel());
	sProp += sNum.c_str();
	setTOCProperty(sProp,sVal);

	pW = _getWidget("edTextBefore");
	sVal = gtk_entry_get_text(GTK_ENTRY(pW));
	sProp = static_cast<const char *> (g_object_get_data(G_OBJECT(pW),"toc-prop"));
	sProp += sNum.c_str();
	setTOCProperty(sProp,sVal);
	Apply();
}
void IE_Imp_WordPerfect::openEndnote(const WPXPropertyList & /*propList*/)
{
	if (m_bHdrFtrOpenCount) return; // HACK
	const gchar** propsArray = NULL;
	
	UT_String endnoteId;
	UT_String_sprintf(endnoteId,"%i",UT_rand());	
	
	propsArray = static_cast<const gchar **>(UT_calloc(7, sizeof(gchar *)));
	propsArray [0] = "type";
	propsArray [1] = "endnote_ref";
	propsArray [2] = "endnote-id";
	propsArray [3] = endnoteId.c_str();
	propsArray [4] = NULL;
	propsArray [5] = NULL;
	propsArray [6] = NULL;
	X_CheckDocumentError(appendObject(PTO_Field, propsArray));

	const gchar * attribs[3] ={"endnote-id", endnoteId.c_str(), NULL};
	X_CheckDocumentError(appendStrux(PTX_SectionEndnote,attribs));
	
	X_CheckDocumentError(appendStrux(PTX_Block,NULL));
	m_bRequireBlock = false;

	propsArray = static_cast<const gchar **>(UT_calloc(7, sizeof(gchar *)));
	propsArray [0] = "type";
	propsArray [1] = "endnote_anchor";
	propsArray [2] = "endnote-id";
	propsArray [3] = endnoteId.c_str();
	propsArray [4] = NULL;
	propsArray [5] = NULL;
	propsArray [6] = NULL;
	X_CheckDocumentError(appendObject(PTO_Field, propsArray));
}
Esempio n. 4
0
/** Given a data pointer, returns a color string (like cccccc for a medium gray).
 * throws BOGUS_DOCUMENT on error. */
UT_String makeColor(UT_uint8* aData, UT_uint32 aDataLen) {
	// from tools/source/generic/color.cxx line 183ff
	#define COL_NAME_USER		(0x8000)
	#define COL_RED_1B			(0x0001)
	#define COL_RED_2B			(0x0002)
	#define COL_GREEN_1B		(0x0010)
	#define COL_GREEN_2B		(0x0020)
	#define COL_BLUE_1B 		(0x0100)
	#define COL_BLUE_2B 		(0x0200)

	UT_String rv;
	if (aDataLen < 2)
		throw UT_IE_BOGUSDOCUMENT;
	UT_uint16 colorName = GSF_LE_GET_GUINT16(aData);
	if (colorName & COL_NAME_USER) {
		// XXX TODO. Awaiting reply in mailinglist about what CompressMode is.
		return "000000";
	}
	else {
		if (colorName < COLOR_SIZE) {
			UT_String_sprintf(rv, "%02x%02x%02x", gColors[colorName].red,
			                  gColors[colorName].green, gColors[colorName].blue);
			return rv;
		}
		else {
			UT_DEBUGMSG(("SDW: COLOR OUT OF RANGE! has num %u\n", colorName));
			return "000000";
		}
			
	}
}
Esempio n. 5
0
UT_Error IE_Imp_WordPerfect::_appendSection(int numColumns, const float marginLeft, const float marginRight)
{
	UT_DEBUGMSG(("AbiWordPerfect: Appending section\n"));
	
	UT_String myProps("") ;
	UT_LocaleTransactor lt(LC_NUMERIC, "C");
	myProps += UT_String_sprintf("columns:%d; page-margin-left:%.4fin; page-margin-right:%.4fin", numColumns, marginLeft, marginRight);

	if(m_bInSection && m_bRequireBlock) // AbiWord will hang on an empty <section>
	{
		X_CheckDocumentError(appendStrux(PTX_Block,PP_NOPROPS));
	}

	const PP_PropertyVector propsArray = {
		"props", myProps.c_str()
	};
	X_CheckDocumentError(appendStrux(PTX_Section, propsArray));

	m_bInSection = true;
	m_bRequireBlock = true;

	m_bSectionChanged = false;

	return UT_OK;
}
void AP_UnixDialog_FormatTOC::s_NumType_changed(GtkWidget * wid, 
												AP_UnixDialog_FormatTOC * me )
{

	GtkTreeIter iter;
	GtkComboBox * combo = GTK_COMBO_BOX(wid);
	gtk_combo_box_get_active_iter(combo, &iter);
	GtkTreeModel *store = gtk_combo_box_get_model(combo);
	UT_UTF8String sProp;
	if(wid == me->m_wLabelChoose) {
		sProp = "toc-label-type";
	}
	else if (wid == me->m_wPageNumberingChoose) {
		sProp = "toc-page-type";
	}
	else {
		UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
	}
	char * value2;
	gtk_tree_model_get(store, &iter, 2, &value2, -1);

	UT_UTF8String sVal = value2;
	UT_String sNum =  UT_String_sprintf("%d",me->getDetailsLevel());
	sProp += sNum.c_str();
	me->setTOCProperty(sProp,sVal);
	g_free(value2);
}
void ODi_Frame_ListenerState::_drawInlineImage (const gchar** ppAtts)
{
    const gchar* pWidth = NULL;
    const gchar* pHeight = NULL;
    UT_String dataId;

    m_inlinedImage = true;

    if(!m_rAbiData.addImageDataItem(dataId, ppAtts)) {
        UT_DEBUGMSG(("ODT import: no suitable image importer found\n"));
        return;
    }

    UT_String propsBuffer;
        
    pWidth = m_rElementStack.getStartTag(0)->getAttributeValue("svg:width");
    UT_ASSERT(pWidth);
        
    pHeight = m_rElementStack.getStartTag(0)->getAttributeValue("svg:height");
    UT_ASSERT(pHeight);  
        
    UT_String_sprintf(propsBuffer, "width:%s; height:%s", pWidth, pHeight);
        
	m_mPendingImgProps["props"] = propsBuffer.c_str();
	m_mPendingImgProps["dataid"] = dataId.c_str();

	// don't write the image out yet as we might get more properties, for
	// example alt descriptions from the <svg:desc> tag
	m_bInlineImagePending = true;
}
void Markup(GtkWidget * widget, const XAP_StringSet * /*pSS*/, char *string)
{
	gchar * unixstr = NULL;	// used for conversions
	UT_XML_cloneNoAmpersands(unixstr, string);
	UT_String markupStr(UT_String_sprintf(gtk_label_get_label (GTK_LABEL(widget)), unixstr));
	gtk_label_set_markup (GTK_LABEL(widget), markupStr.c_str());
	FREEP(unixstr);	
}
Esempio n. 9
0
bool fp_AnnotationRun::_setValue(void)
{
  UT_uint32 pos = getBlock()->getDocLayout()->getAnnotationVal(getPID()) + 1;
  UT_String tmp;
  UT_String_sprintf(tmp,"(%d)",pos);
  m_sValue = tmp.c_str();
  return true;
}
Esempio n. 10
0
void IE_Imp_WordPerfect::openTable(const librevenge::RVNGPropertyList &propList)
{
	if (m_bHdrFtrOpenCount) return; // HACK
	// TODO: handle 'marginLeftOffset' and 'marginRightOffset'
	UT_DEBUGMSG(("AbiWordPerfect: openTable\n"));
	
	UT_String propBuffer;

	if (propList["table:align"])
	{
		// no need to support left: default behaviour

		//if (strcmp(propList["table:align"]->getStr().cstr(), "right"))
		// abiword does not support this I think
		//if (strcmp(propList["table:align"]->getStr().cstr(), "center"))
		// abiword does not support this I think
		//if (strcmp(propList["table:align"]->getStr().cstr(), "margins"))
		// abiword does not support this I think
		if (strcmp(propList["table:align"]->getStr().cstr(), "margins"))
		{
			if (propList["fo:margin-left"])
				UT_String_sprintf(propBuffer, "table-column-leftpos:%s; ", propList["fo:margin-left"]->getStr().cstr());
		}
	}
	
	const librevenge::RVNGPropertyListVector *columns = propList.child("librevenge:table-columns");
	if (columns)
	{
		propBuffer += "table-column-props:";
		librevenge::RVNGPropertyListVector::Iter i(*columns);
		for (i.rewind(); i.next();)
		{
			UT_String tmpBuffer;
			if (i()["style:column-width"])
				UT_String_sprintf(tmpBuffer, "%s/", i()["style:column-width"]->getStr().cstr());
			propBuffer += tmpBuffer;
		}
	}

	const PP_PropertyVector propsArray = {
		"props", propBuffer.c_str()
	};
	X_CheckDocumentError(appendStrux(PTX_SectionTable, propsArray));
}
Esempio n. 11
0
void AP_Dialog_FormatFrame::setBorderColorLeft (const UT_RGBColor & clr)
{
	m_borderColorLeft = clr;
	
	UT_String s = UT_String_sprintf("%02x%02x%02x", clr.m_red, clr.m_grn, clr.m_blu);	

	m_vecProps.addOrReplaceProp("left-color", s.c_str());
	
	m_bSettingsChanged = true;
}
Esempio n. 12
0
/*!
 * Localizes the label of a widget given the string id
 * It formats the label using the current label of the widget as a format
 * string. The current label is assumed to be something like
 * "<span size="larger">%s</span>".
 */
void localizeLabelMarkup(GtkWidget * widget, const XAP_StringSet * pSS, XAP_String_Id id)
{
	gchar * unixstr = NULL;	// used for conversions
	UT_UTF8String s;
	pSS->getValueUTF8(id,s);
	UT_XML_cloneNoAmpersands(unixstr, s.utf8_str());
	UT_String markupStr(UT_String_sprintf(gtk_label_get_label (GTK_LABEL(widget)), unixstr));
	gtk_label_set_markup (GTK_LABEL(widget), markupStr.c_str());
	FREEP(unixstr);	
}
Esempio n. 13
0
char * XAP_Dialog_History::getListValue(UT_uint32 item, UT_uint32 column) const
{
	UT_return_val_if_fail(m_pDoc, NULL);

	UT_String S;
	time_t tT;
	struct tm * tM;
	char * s;
	
	switch(column)
	{
		case 0:
			UT_String_sprintf(S,"%d",m_pDoc->getHistoryNthId(item));
			return g_strdup(S.c_str());
			
		case 1:
			{
				tT = m_pDoc->getHistoryNthTimeStarted(item);
				tM = localtime(&tT);
				s = (char*)g_try_malloc(30);
				if(!s)
					return NULL;

				size_t len = strftime(s,30,"%c",tM);
				if(!len)
				{
					FREEP(s);
					return NULL;
				}

				return s;
			}

		case 2:
			{
				UT_return_val_if_fail(m_pSS, NULL);

				const char * pszS;
				if(m_pDoc->getHistoryNthAutoRevisioned(item))
					pszS = m_pSS->getValue(XAP_STRING_ID_DLG_MB_Yes);
				else
					pszS = m_pSS->getValue(XAP_STRING_ID_DLG_MB_No);
					
				UT_return_val_if_fail(pszS, NULL);

				return g_strdup(pszS);
			}
			
		default:;
	}

	UT_ASSERT(UT_SHOULD_NOT_HAPPEN);
	return NULL;
}
void AP_UnixDialog_FormatTOC::event_HasLabelChanged(GtkWidget * wid)
{
	UT_UTF8String sProp = static_cast<char *> (g_object_get_data(G_OBJECT(wid),"toc-prop"));
	UT_String sNum =  UT_String_sprintf("%d",getMainLevel());
	sProp += sNum.c_str();
	UT_UTF8String sVal = "1";
	if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wid)) == FALSE)
	{
		sVal = "0";
	}
	setTOCProperty(sProp,sVal);
}
static void s_check_changedDetails(GtkWidget * wid, AP_UnixDialog_FormatTOC * me)
{
	UT_UTF8String sProp = static_cast<char *> (g_object_get_data(G_OBJECT(wid),"toc-prop"));
	UT_UTF8String sVal = "1";
	if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wid)) == FALSE)
	{
		sVal = "0";
	}
	UT_String sNum =  UT_String_sprintf("%d",me->getDetailsLevel());
	sProp += sNum.c_str();
	me->setTOCProperty(sProp,sVal);
}
GtkWidget * AP_UnixDialog_FormatTOC::_getWidget(const char * szNameBase, UT_sint32 iLevel)
{
	UT_return_val_if_fail(m_pBuilder, NULL);

	UT_String sLocal = szNameBase;
	if(iLevel > 0)
	{
		UT_String sVal = UT_String_sprintf("%d",iLevel);
		sLocal += sVal;
	}
	return GTK_WIDGET(gtk_builder_get_object(m_pBuilder, sLocal.c_str()));
}
Esempio n. 17
0
/*!
 Set the color and style and thickness of the toggled button
 */
void AP_Dialog_FormatTable::toggleLineType(toggle_button btn, bool enabled)
{
    UT_String cTmp = UT_String_sprintf("%02x%02x%02x", m_borderColor.m_red, m_borderColor.m_grn, m_borderColor.m_blu);
    UT_String sTmp = UT_String_sprintf("%d", (enabled ? m_lineStyle : LS_OFF));

    switch (btn)
    {
    case toggle_left:
    {
        m_vecProps.addOrReplaceProp("left-style", sTmp.c_str());
        m_vecProps.addOrReplaceProp("left-color", cTmp.c_str());
        m_vecProps.addOrReplaceProp("left-thickness",m_sBorderThickness.utf8_str());
    }
    break;
    case toggle_right:
    {
        m_vecProps.addOrReplaceProp("right-style", sTmp.c_str());
        m_vecProps.addOrReplaceProp("right-color", cTmp.c_str());
        m_vecProps.addOrReplaceProp("right-thickness",m_sBorderThickness.utf8_str());
    }
    break;
    case toggle_top:
    {
        m_vecProps.addOrReplaceProp("top-style", sTmp.c_str());
        m_vecProps.addOrReplaceProp("top-color", cTmp.c_str());
        m_vecProps.addOrReplaceProp("top-thickness",m_sBorderThickness.utf8_str());
    }
    break;
    case toggle_bottom:
    {
        m_vecProps.addOrReplaceProp("bot-style", sTmp.c_str());
        m_vecProps.addOrReplaceProp("bot-color", cTmp.c_str());
        m_vecProps.addOrReplaceProp("bot-thickness",m_sBorderThickness.utf8_str());
    }
    break;
    }

    m_borderToggled = true;
    m_bSettingsChanged = true;
}
Esempio n. 18
0
bool AP_Dialog_FormatFrame::_getToggleButtonStatus(const char * lineStyle)
{
	const gchar * pszStyle = NULL;
	UT_String lsOff = UT_String_sprintf("%d", LS_OFF);	

	m_vecProps.getProp(lineStyle, pszStyle);

	if ((pszStyle && strcmp(pszStyle, lsOff.c_str())) || 
		!pszStyle)
		return true;
	else
		return false;
}
Esempio n. 19
0
void AP_Dialog_FormatTable::setBackgroundColor(UT_RGBColor clr)
{
    UT_String bgcol = UT_String_sprintf("%02x%02x%02x", clr.m_red, clr.m_grn, clr.m_blu);

    m_vecProps.removeProp ("bg-style"); // Why do we remove this property?  We still use it in frames. -MG
    m_vecProps.removeProp ("bgcolor"); // this is only here for backward compatibility with AbiWord < 2.0. Could be removed as far as I can see - MARCM

    if (clr.isTransparent ())
        m_vecProps.removeProp ("background-color");
    else
        m_vecProps.addOrReplaceProp ("background-color", bgcol.c_str ());

    m_bSettingsChanged = true;
}
void AP_UnixDialog_FormatTOC::setStyle(GtkWidget * wid)
{
	UT_UTF8String sVal;
	GtkWidget * pLabel = static_cast<GtkWidget *> (g_object_get_data(G_OBJECT(wid),"display-widget"));
	UT_UTF8String sProp = static_cast<char *> (g_object_get_data(G_OBJECT(pLabel),"toc-prop"));
	if(g_ascii_strcasecmp("toc-heading-style",sProp.utf8_str()) != 0)
	{
		UT_String sNum =  UT_String_sprintf("%d",getMainLevel());
		sProp += sNum.c_str();
	}
	sVal = getNewStyle(sProp);
	gtk_label_set_text(GTK_LABEL(pLabel),sVal.utf8_str());
	setTOCProperty(sProp,sVal);
	applyTOCPropsToDoc();
}
Esempio n. 21
0
void AP_Dialog_FormatFrame::setBGColor(UT_RGBColor clr)
{
	m_backgroundColor = clr;

	UT_String bgcol = UT_String_sprintf("%02x%02x%02x", clr.m_red, clr.m_grn, clr.m_blu);

	m_vecProps.removeProp ("bg-style");
	m_vecProps.removeProp ("bgcolor");

	if (clr.isTransparent ())
		m_vecProps.removeProp ("background-color");
	else
		m_vecProps.addOrReplaceProp ("background-color", bgcol.c_str ());

	m_bSettingsChanged = true;
}
static void s_TabLeader_changed(GtkWidget * wid, AP_UnixDialog_FormatTOC * me )
{

	GtkTreeIter iter;
	GtkComboBox * combo = GTK_COMBO_BOX(wid);
	gtk_combo_box_get_active_iter(combo, &iter);
	GtkTreeModel *store = gtk_combo_box_get_model(combo);
	char * value1;
	char * value2;
	gtk_tree_model_get(store, &iter, 1, &value1, 2, &value2, -1);

	UT_UTF8String sProp = value1;
	UT_UTF8String sVal = value2;
	UT_String sNum =  UT_String_sprintf("%d",me->getDetailsLevel());
	sProp += sNum.c_str();
	me->setTOCProperty(sProp,sVal);
}
Esempio n. 23
0
/*!
 * Localizes a button given the string id
 * It formats its label using the current button label as a format
 * string. It is assumed to be something like
 * "<span size="larger">%s</span>".
 * Note that in addition to doing markup, ampersands will be converted
 * to underscores/mnemonic since this makes sense for buttons
 */
void localizeButtonMarkup(GtkWidget * widget, const XAP_StringSet * pSS, XAP_String_Id id)
{
	UT_UTF8String s;
	pSS->getValueUTF8(id,s);
	gchar * newlbl = g_strdup(s.utf8_str());
	UT_ASSERT(newlbl);
	convertMnemonics(newlbl);
	UT_String markupStr(UT_String_sprintf(gtk_button_get_label (GTK_BUTTON(widget)), newlbl));
	gtk_button_set_use_underline (GTK_BUTTON(widget), TRUE);
	gtk_button_set_label (GTK_BUTTON(widget), markupStr.c_str());

	// by default, they don't like markup, so we teach them
	GtkWidget * button_child = gtk_bin_get_child (GTK_BIN(widget));
	if (GTK_IS_LABEL (button_child))
		gtk_label_set_use_markup (GTK_LABEL(button_child), TRUE);

	FREEP(newlbl);	
}
Esempio n. 24
0
void AP_Dialog_FormatTable::setBorderColor(UT_RGBColor clr)
{
    m_borderColor = clr;

    if (m_borderToggled)
        return;

    UT_String s = UT_String_sprintf("%02x%02x%02x", clr.m_red, clr.m_grn, clr.m_blu);

    m_vecProps.addOrReplaceProp("left-color", s.c_str());
    m_vecProps.addOrReplaceProp("right-color", s.c_str());
    m_vecProps.addOrReplaceProp("top-color", s.c_str());
    m_vecProps.addOrReplaceProp("bot-color", s.c_str());

    m_vecPropsAdjRight.addOrReplaceProp("left-color", s.c_str());
    m_vecPropsAdjBottom.addOrReplaceProp("top-color", s.c_str());

    m_bSettingsChanged = true;
}
void AP_UnixDialog_FormatTOC::event_HasHeadingChanged(GtkWidget * wid)
{
	UT_UTF8String sProp = static_cast<char *> (g_object_get_data(G_OBJECT(wid),"toc-prop"));
	UT_UTF8String sVal = "1";
	if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wid)) == FALSE)
	{
		sVal = "0";
		_setHasHeadingSensitivity(FALSE);
	}
	else
	{
		_setHasHeadingSensitivity(TRUE);
	}
	if(g_ascii_strcasecmp("toc-has-heading",sProp.utf8_str()) != 0)
	{
		UT_String sNum =  UT_String_sprintf("%d",getMainLevel());
		sProp += sNum.c_str();
	}
	setTOCProperty(sProp,sVal);
}
void XAP_App::setDefaultGraphicsId(UT_uint32 i)
{
	if(i == GRID_UNKNOWN)
		return;
	
	m_iDefaultGraphicsId = i;

	if(i < GRID_LAST_BUILT_IN && i > GRID_LAST_DEFAULT)
	{
		// change the preference settings
		UT_return_if_fail(m_prefs)
			
		XAP_PrefsScheme *pPrefsScheme = m_prefs->getCurrentScheme();
		UT_return_if_fail(pPrefsScheme);

		UT_String s;
		UT_String_sprintf(s, "%d", i);
		
		pPrefsScheme->setValue(XAP_PREF_KEY_DefaultGraphics, s.c_str());
	}
}
Esempio n. 27
0
GR_Font* GR_Graphics::findFont(const char* pszFontFamily,
                               const char* pszFontStyle,
                               const char* pszFontVariant,
                               const char* pszFontWeight,
                               const char* pszFontStretch,
                               const char* pszFontSize,
                               const char* pszLang)
{
    GR_Font * pFont = NULL;

    // NOTE: we currently favor a readable hash key to make debugging easier
    // TODO: speed things up with a smaller key (the three AP pointers?)
    UT_String key;

    UT_String_sprintf(key,"%s;%s;%s;%s;%s;%s",pszFontFamily, pszFontStyle, pszFontVariant, pszFontWeight, pszFontStretch, pszFontSize);
    GR_Font *pEntry = m_hashFontCache.pick(key.c_str());
    if (!pEntry)
    {
        // TODO -- note that we currently assume font-family to be a single name,
        // TODO -- not a list.  This is broken.

        pFont = _findFont(pszFontFamily, pszFontStyle,
                          pszFontVariant,pszFontWeight,
                          pszFontStretch, pszFontSize,
                          pszLang);
        UT_ASSERT(pFont);
        xxx_UT_DEBUGMSG(("Insert font %x in gr_Graphics cache \n",pFont));
        // add it to the cache

        if(pFont)
            m_hashFontCache.insert(key.c_str(), pFont);
    }
    else
    {
        pFont = pEntry;
    }
    return pFont;
}
bool XAP_Win32AppImpl::openURL(const char * szURL)
{
	// NOTE: could get finer control over browser window via DDE 
	// NOTE: may need to fallback to WinExec for old NSCP versions

	UT_String sURL = szURL;

	// If this is a file:// URL, strip off file:// and make it backslashed
	if (sURL.substr(0, 7) == "file://")
	{
		sURL = sURL.substr(7, sURL.size() - 7);

		// View as WebPage likes to throw in an extra /\ just for fun, strip it off
		if (sURL.substr(0, 2) == "/\\")
			sURL = sURL.substr(2, sURL.size() - 2);

		if (sURL.substr(0, 1) == "/")
			sURL = sURL.substr(1, sURL.size() - 1);
		
		// Convert all forwardslashes to backslashes
		for (unsigned int i=0; i<sURL.length();i++)	
			if (sURL[i]=='/')	
                sURL[i]='\\';

		// Convert from longpath to 8.3 shortpath, in case of spaces in the path
		char* longpath = NULL;
		char* shortpath = NULL;
		longpath = new char[PATH_MAX];
		shortpath = new char[PATH_MAX];
		strcpy(longpath, sURL.c_str());
		DWORD retval = GetShortPathName(longpath, shortpath, PATH_MAX);
		if((retval == 0) || (retval > PATH_MAX))
		{
			UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
			DELETEP(longpath);
			DELETEP(shortpath);
			return false;
		}
		sURL = shortpath;
		DELETEP(longpath);
		DELETEP(shortpath);
	}

	// Query the registry for the default browser so we can directly invoke it
	UT_String sBrowser;
	HKEY hKey;
	unsigned long lType;
	DWORD dwSize;
	unsigned char* szValue = NULL;

	if (RegOpenKeyEx(HKEY_CLASSES_ROOT, "http\\shell\\open\\command", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
	{
		if(RegQueryValueEx(hKey, NULL, NULL, &lType, NULL, &dwSize) == ERROR_SUCCESS)
		{
			szValue = new unsigned char[dwSize + 1];
			RegQueryValueEx(hKey, NULL, NULL, &lType, szValue, &dwSize);
			sBrowser = (char*) szValue;
			DELETEP(szValue);
		}
		RegCloseKey(hKey);
	}

	/* Now that we have sBrowser from the registry, we need to parse it out.
	 * If the first character is a double-quote, everything up to and including
	 * the next double-quote is the sBrowser command. Everything after the
	 * double-quote is appended to the parameters.
	 * If the first character is NOT a double-quote, we assume
	 * everything up to the first whitespace is the command and anything after
	 * is appended to the parameters.
	 */

	int iDelimiter;
	if (sBrowser.substr(0, 1) == "\"")
		iDelimiter = UT_String_findCh(sBrowser.substr(1, sBrowser.length()-1), '"')+2;
	else
		iDelimiter = UT_String_findCh(sBrowser.substr(0, sBrowser.length()), ' ');

	// Store params into a separate UT_String before we butcher sBrowser
	UT_String sParams = sBrowser.substr(iDelimiter+1, sBrowser.length()-iDelimiter+1);
	// Cut params off of sBrowser so all we're left with is the broweser path & executable
	sBrowser = sBrowser.substr(0, iDelimiter);

	// Check for a %1 passed in from the registry.  If we find it,
	// substitute our URL for %1.  Otherwise, just append sURL to params.
	const char *pdest = strstr(sParams.c_str(), "%1");
	if (pdest != NULL)
	{
		int i = pdest - sParams.c_str() + 1;
		sParams = sParams.substr(0, i-1) + sURL + sParams.substr(i+1, sParams.length()-i+1);
	}
	else
	{
		sParams = sParams + " " + sURL;
	}

	// Win95 doesn't like the Browser command to be quoted, so strip em off.
	if (sBrowser.substr(0, 1) == "\"")
		sBrowser = sBrowser.substr(1, sBrowser.length() - 1);
	if (sBrowser.substr(sBrowser.length()-1, 1) == "\"")
		sBrowser = sBrowser.substr(0, sBrowser.length() - 1);

	XAP_Frame * pFrame = XAP_App::getApp()->getLastFocussedFrame();
	UT_return_val_if_fail(pFrame, false);
	XAP_Win32FrameImpl *pFImp =  (XAP_Win32FrameImpl *) pFrame->getFrameImpl();
	UT_return_val_if_fail(pFImp, false);

	intptr_t res = (intptr_t) ShellExecuteA(pFImp->getTopLevelWindow() /*(HWND)*/,
								 "open", sBrowser.c_str(), sParams.c_str(), NULL, SW_SHOW );

	// TODO: localized error messages
	// added more specific error messages as documented in http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/system_error_codes.asp
	if (res <= 32)
	{
		UT_String errMsg;
		switch (res)
		{
			case ERROR_FILE_NOT_FOUND:
				{
					errMsg = "Error ("; 
					errMsg += UT_String_sprintf("%d", res);
					errMsg += ") displaying URL: The system cannot find the file specified.\n";
					errMsg += " [ ";  errMsg += sURL;  errMsg += " ] ";
					MessageBoxA(pFImp->getTopLevelWindow(), errMsg.c_str(), "Error displaying URL", MB_OK|MB_ICONEXCLAMATION);
				}
				break;

			case ERROR_PATH_NOT_FOUND:
				{
					errMsg = "Error ("; 
					errMsg += UT_String_sprintf("%d", res);
					errMsg += ") displaying URL: The system cannot find the path specified.\n";
					errMsg += " [ ";  errMsg += sURL;  errMsg += " ] ";
					MessageBoxA(pFImp->getTopLevelWindow(), errMsg.c_str(), "Error displaying URL", MB_OK|MB_ICONEXCLAMATION);
				}
				break;

			case SE_ERR_ACCESSDENIED:
				{
					errMsg = "Error ("; 
					errMsg += UT_String_sprintf("%d", res);
					errMsg += ") displaying URL: Access is denied.\n";
					errMsg += " [ ";  errMsg += sURL;  errMsg += " ] ";
					MessageBoxA(pFImp->getTopLevelWindow(), errMsg.c_str(), "Error displaying URL", MB_OK|MB_ICONEXCLAMATION);
				}
				break;

			default:
				{
					errMsg = "Error ("; 
					errMsg += UT_String_sprintf("%d", res);
					errMsg += ") displaying URL: \n";
					errMsg += " [ ";  errMsg += sURL;  errMsg += " ] ";
					MessageBoxA(pFImp->getTopLevelWindow(), errMsg.c_str(), "Error displaying URL", MB_OK|MB_ICONEXCLAMATION);
				}
				break;
		} /* switch (res) */
	} /* if (res <= 32) */

	return (res>32);
}
Esempio n. 29
0
bool pt_PieceTable::_loadBuiltinStyles(void)
{
	/* 	
		!!! if adding or removing properties to the list_fmt, you have to make also changes to
		pt_VarSet.cpp mergeAP()
	*/
	UT_LocaleTransactor t(LC_NUMERIC, "C");

	const char* list_fmt = " list-style:%s; start-value:%s; margin-left:%fin; text-indent:-%fin; "
		"field-color:%s;list-delim:%s; field-font:%s; list-decimal:%s";
	UT_String list_fmt_tmp;
	UT_String stTmp;
	const char* szFmt;
	
	// findNearestFont will do a fuzzy match, and return the nearest font in the
	// system -- use the locale language
	UT_UTF8String s = XAP_EncodingManager::get_instance()->getLanguageISOName();

	const char * pCountry
		= XAP_EncodingManager::get_instance()->getLanguageISOTerritory();
	
	if(pCountry)
	{
		s += "-";
		s += pCountry;
	}
	
	const char* pszFamily = XAP_App::findNearestFont("Times New Roman",
													 "normal", "",
													 "normal", "", "12pt",
													 s.utf8_str());
	
	UT_String_sprintf(stTmp, "font-family:%s; font-size:12pt; font-weight:normal; "
					  "font-style:normal; font-stretch:normal; font-variant:normal; "
					  "margin-top:0pt; margin-bottom:0pt; "
					  "margin-left:0pt; margin-right:0pt; text-decoration:none; "
					  "text-indent:0in; text-position:normal; line-height:1.0; "
					  "color:000000; bgcolor:transparent; widows:2", pszFamily);

	pszFamily = XAP_App::findNearestFont("Arial", "normal", "",
										 "normal", "", "12pt", s.utf8_str());

	// used to set the dom-dir of the style here, but we do not want to do that. The
	// dom-dir property should be inherited from the section or document (the user can, of
	// course, modify the style, but that is up to them).
#	ifdef BIDI_RTL_DOMINANT
	stTmp += "; text-align:right";
#	else
	stTmp += "; text-align:left";
#	endif

	_s("Normal", true,	"P", "",       "Current Settings", stTmp.c_str());
	
	szFmt = "font-family:%s; font-size:%dpt; font-weight:bold; margin-top:22pt; margin-bottom:3pt; keep-with-next:1";
	UT_String_sprintf(stTmp, szFmt, pszFamily, 17);
	_s("Heading 1", true,	"P", "Normal", "Normal", stTmp.c_str());
	UT_String_sprintf(stTmp, szFmt, pszFamily, 14);
	_s("Heading 2", true,	"P", "Normal", "Normal", stTmp.c_str());
	UT_String_sprintf(stTmp, szFmt, pszFamily, 12);
	_s("Heading 3", true,	"P", "Normal", "Normal", stTmp.c_str());
	_s("Heading 4", true,	"P", "Normal", "Normal", stTmp.c_str());
	_s("Plain Text", true,"P", "Normal", "Current Settings", "font-family:Courier New");
	_s("Block Text", true,"P", "Normal", "Current Settings", "margin-left:1in; margin-right:1in; margin-bottom:6pt");

	UT_String_sprintf(stTmp, list_fmt, "Numbered List", "1",LIST_DEFAULT_INDENT, LIST_DEFAULT_INDENT_LABEL, "transparent", "%L.", "NULL", ".");
	_s("Numbered List",true,"P", "", "Current Settings", stTmp.c_str());

	UT_String_sprintf(stTmp, list_fmt, "Lower Case List","1", LIST_DEFAULT_INDENT, LIST_DEFAULT_INDENT_LABEL, "transparent", "%L)", "NULL", ".");
	_s("Lower Case List",true,"P", "Numbered List", "Current Settings", stTmp.c_str());
	UT_String_sprintf(stTmp, list_fmt, "Upper Case List","1", LIST_DEFAULT_INDENT, LIST_DEFAULT_INDENT_LABEL, "transparent", "%L)", "NULL", ".");
	_s("Upper Case List",false,"P", "Numbered List", "Current Settings", stTmp.c_str());

	UT_String_sprintf(stTmp, list_fmt, "Lower Roman List","1", LIST_DEFAULT_INDENT, LIST_DEFAULT_INDENT_LABEL, "transparent", "%L", "NULL", ".");
	_s("Lower Roman List",false,"P", "Normal", "Current Settings", stTmp.c_str());

	UT_String_sprintf(stTmp, list_fmt,"Upper Roman List","1", LIST_DEFAULT_INDENT, LIST_DEFAULT_INDENT_LABEL, "transparent", "%L", "NULL", ".");
	_s("Upper Roman List",false,"P", "Numbered List", "Current Settings", stTmp.c_str());

	UT_String_sprintf(stTmp, list_fmt, "Bullet List","0", LIST_DEFAULT_INDENT, LIST_DEFAULT_INDENT_LABEL, "transparent", "%L", "Symbol", "NULL");

	_s("Bullet List",true, "P", "", "Current Settings", stTmp.c_str());
	UT_String_sprintf(stTmp, list_fmt, "Implies List","0", LIST_DEFAULT_INDENT, LIST_DEFAULT_INDENT_LABEL, "transparent", "%L", "Symbol", "NULL");
	_s("Implies List",false, "P", "", "Current Settings", stTmp.c_str());

	UT_String_sprintf(stTmp, list_fmt, "Dashed List","0", LIST_DEFAULT_INDENT, LIST_DEFAULT_INDENT_LABEL, "transparent", "%L", "NULL", "NULL");
	_s("Dashed List",true, "P", "", "Current Settings", stTmp.c_str());

	UT_String_sprintf(stTmp, list_fmt, "Square List","0", LIST_DEFAULT_INDENT, LIST_DEFAULT_INDENT_LABEL, "transparent", "%L", "Dingbats", "NULL");
	_s("Square List",false, "P", "", "Current Settings", stTmp.c_str());

	UT_String_sprintf(stTmp, list_fmt, "Triangle List","0", LIST_DEFAULT_INDENT, LIST_DEFAULT_INDENT_LABEL, "transparent", "%L", "Dingbats", "NULL");
	_s("Triangle List",false, "P", "", "Current Settings", stTmp.c_str());

	UT_String_sprintf(stTmp, list_fmt, "Diamond List","0", LIST_DEFAULT_INDENT, LIST_DEFAULT_INDENT_LABEL, "transparent", "%L", "Dingbats", "NULL");
	_s("Diamond List",false, "P", "", "Current Settings", stTmp.c_str());

	UT_String_sprintf(stTmp, list_fmt, "Star List","0", LIST_DEFAULT_INDENT, LIST_DEFAULT_INDENT_LABEL, "transparent", "%L", "Dingbats", "NULL");
	_s("Star List",false, "P", "", "Current Settings", stTmp.c_str());

	UT_String_sprintf(stTmp, list_fmt, "Tick List","0", LIST_DEFAULT_INDENT, LIST_DEFAULT_INDENT_LABEL, "transparent", "%L", "Dingbats", "NULL");
	_s("Tick List",false, "P", "", "Current Settings", stTmp.c_str());

	UT_String_sprintf(stTmp, list_fmt, "Box List","0", LIST_DEFAULT_INDENT, LIST_DEFAULT_INDENT_LABEL, "transparent", "%L", "Dingbats", "NULL");
	_s("Box List",false, "P", "", "Current Settings", stTmp.c_str());

	UT_String_sprintf(stTmp, list_fmt, "Hand List","0", LIST_DEFAULT_INDENT, LIST_DEFAULT_INDENT_LABEL, "transparent", "%L", "Dingbats", "NULL");
	_s("Hand List",false, "P", "", "Current Settings", stTmp.c_str());

	UT_String_sprintf(stTmp, list_fmt, "Heart List","0", LIST_DEFAULT_INDENT, LIST_DEFAULT_INDENT_LABEL, "transparent", "%L", "Dingbats", "NULL");
	_s("Heart List",false, "P", "", "Current Settings", stTmp.c_str());

	// pszFamily is the nearest font to Arial found in the system
	UT_String_sprintf(stTmp, "tabstops:0.3in/L0; list-style:Numbered List; "
					  "start-value:1; margin-left:0.0in; text-indent:0.0in; "
					  "field-color:transparent; list-delim:%%L.; field-font:%s; "
					  "list-decimal:", pszFamily);


    _s("Numbered Heading 1",true,"P","Heading 1","Normal", stTmp.c_str());
    _s("Numbered Heading 2",true,"P","Heading 2","Normal", stTmp.c_str());
    _s("Numbered Heading 3",true,"P","Heading 3","Normal", stTmp.c_str());

	// pszFamily is the nearest font to Arial found in the system

	UT_String_sprintf(stTmp, list_fmt, "Numbered List", "1",LIST_DEFAULT_INDENT, LIST_DEFAULT_INDENT_LABEL, "transparent", "%L.", "NULL", ".");

    _s("Contents 1",false,"P","Normal","Normal", stTmp.c_str());

	UT_String_sprintf(stTmp, list_fmt, "Numbered List", "1",2*LIST_DEFAULT_INDENT, LIST_DEFAULT_INDENT_LABEL, "transparent", "%L.", "NULL", ".");
    _s("Contents 2",false,"P","Normal","Normal", stTmp.c_str());
	UT_String_sprintf(stTmp, list_fmt, "Numbered List", "1",3*LIST_DEFAULT_INDENT, LIST_DEFAULT_INDENT_LABEL, "transparent", "%L.", "NULL", ".");
    _s("Contents 3",false,"P","Normal","Normal", stTmp.c_str());
	UT_String_sprintf(stTmp, list_fmt, "Numbered List", "1",4*LIST_DEFAULT_INDENT, LIST_DEFAULT_INDENT_LABEL, "transparent", "%L.", "NULL", ".");
    _s("Contents 4",false,"P","Normal","Normal", stTmp.c_str());

	
	szFmt = "font-family:%s; font-size:%dpt; font-weight:bold; margin-top:12pt; margin-bottom:6pt; text-align:center; keep-with-next:1";
	UT_String_sprintf(stTmp, szFmt, pszFamily, 16);
    _s("Contents Header",false,"P","Normal","Normal", stTmp.c_str());


	szFmt = "tabstops:1.1in/L0; list-style:Numbered List; "
		"start-value:1; margin-left:0.0in; text-indent:0.0in; "
		"field-color:transparent; list-delim:%s %%L.; "
		"field-font:%s; list-decimal:";
	UT_String_sprintf(stTmp, szFmt, "Chapter", pszFamily);

    _s("Chapter Heading",true,"P","Numbered Heading 1","Normal", stTmp.c_str());

	UT_String_sprintf(stTmp, szFmt, "Section", pszFamily);
    _s("Section Heading",true,"P","Numbered Heading 1","Normal", stTmp.c_str());

	_s("Endnote Reference",false,"C", "None", "Current Settings", "text-position:superscript; font-size:10pt");
	_s("Endnote Text",false,"P", "Normal", "Current Settings", "text-position:normal");
	_s("Endnote",false,"P", "Normal", "Current Settings", "text-position:normal;text-indent:-0.2in;margin-left:0.2in");

	_s("Footnote Reference",false,"C", "None", "Current Settings", "text-position:superscript; font-size:10pt");
	_s("Footnote Text",false,"P", "Normal", "Current Settings", "text-position:normal; font-size:10pt");
	_s("Footnote",false,"P", "Normal", "Current Settings", "text-position:normal; font-size:10pt;text-indent:-0.2in;margin-left:0.2in");

	return true;

Failed:
	return false;
}
Esempio n. 30
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;
}