Example #1
0
static void _css_length (const char *str,GR_Graphics* pG,
			 UT_sint32 *iDisplayLength,UT_sint32 *iLayoutLength)
{
   	UT_sint32 dim = UT_determineDimension(static_cast<const char*>(str), DIM_PX);

   	if (dim != DIM_PX && dim != DIM_none)
	{
		if (pG == 0)
		{
			*iDisplayLength = static_cast<UT_sint32>((UT_convertToInches(str) * 72.0) + 0.05);
		}
		else
		{
			*iDisplayLength = UT_convertToLogicalUnits(str);
		}
		*iLayoutLength = UT_convertToLogicalUnits(str);
	}
	else
	{
		double iImageLength = UT_convertDimensionless(str);

		double fScale = pG ? (pG->getResolution() / 72.0) : 1;
		*iDisplayLength = static_cast<UT_sint32>(iImageLength * fScale);

		fScale = 1440.0 / 72.0;
		*iLayoutLength = static_cast<UT_sint32>(iImageLength * fScale);
	}
}
Example #2
0
/*!
 * This method multiplys a dimenstioned string by the amount given.
\param const char * dimString - string to be incremented.
\param amount to be multiplied.
*/
const char * UT_multiplyDimString(const char * dimString, double mult)
{
    UT_Dimension dim = UT_determineDimension(dimString);
    double val = UT_convertDimensionless(dimString);
    val *= mult;
    const char * retv = UT_formatDimensionString(dim, val);
    return retv;
}
Example #3
0
/*!
 * This method increments a dimenstioned string by the amount given.
\param const char * dimString - string to be incremented.
\param amount of increment.
*/
const char * UT_incrementDimString(const char * dimString, double inc)
{
    UT_Dimension dim = UT_determineDimension(dimString);
    double val = UT_convertDimensionless(dimString);
    val += inc;
    const char * retv = UT_formatDimensionString(dim, val);
    return retv;
}
Example #4
0
static void s_border_properties (const gchar * border_color, const gchar * border_style, const gchar * border_width,
								 const gchar * color, PP_PropertyMap::Line & line)
{
	/* frame-border properties:
	 * 
	 * (1) color      - defaults to value of "color" property
	 * (2) line-style - defaults to solid (in contrast to "none" in CSS)
	 * (3) thickness  - defaults to 1 layout unit (??, vs "medium" in CSS)
	 */
	line.reset ();

	PP_PropertyMap::TypeColor t_border_color = PP_PropertyMap::color_type (border_color);
	if (t_border_color)
		{
			line.m_t_color = t_border_color;
			if (t_border_color == PP_PropertyMap::color_color)
				UT_parseColor (border_color, line.m_color);
		}
	else if (color)
		{
			PP_PropertyMap::TypeColor t_color = PP_PropertyMap::color_type (color);

			line.m_t_color = t_color;
			if (t_color == PP_PropertyMap::color_color)
				UT_parseColor (color, line.m_color);
		}

	line.m_t_linestyle = PP_PropertyMap::linestyle_type (border_style);
	if (!line.m_t_linestyle)
		line.m_t_linestyle = PP_PropertyMap::linestyle_solid;

	line.m_t_thickness = PP_PropertyMap::thickness_type (border_width);
	if (line.m_t_thickness == PP_PropertyMap::thickness_length)
		{
			if (UT_determineDimension (border_width, (UT_Dimension)-1) == DIM_PX)
				{
					double thickness = UT_LAYOUT_RESOLUTION * UT_convertDimensionless (border_width);
					line.m_thickness = static_cast<UT_sint32>(thickness / UT_PAPER_UNITS_PER_INCH);
				}
			else
				line.m_thickness = UT_convertToLogicalUnits (border_width);

			if (!line.m_thickness)
				{
					double thickness = UT_LAYOUT_RESOLUTION;
					line.m_thickness = static_cast<UT_sint32>(thickness / UT_PAPER_UNITS_PER_INCH);
				}
		}
	else // ??
		{
			double thickness = UT_LAYOUT_RESOLUTION;
			line.m_thickness = static_cast<UT_sint32>(thickness / UT_PAPER_UNITS_PER_INCH);
		}
}
Example #5
0
/*!
 * Convert a percentage to a double precision fractional value
 */
double  UT_convertFraction(const char * pszFrac)
{
    double res = 0.0;
    UT_Dimension dim =  UT_determineDimension(pszFrac);
    if(dim == DIM_PERCENT)
    {
        res = UT_convertDimensionless(pszFrac)/100.;
    }
    else
    {
        res = UT_convertDimensionless(pszFrac);
    }
    return res;
}
Example #6
0
double UT_convertToDimension(const char* s, UT_Dimension dim)
{
    double d;

    // if needed, switch unit systems and round off

    if (UT_determineDimension(s, dim) != dim)
    {
        double dInches = UT_convertToInches(s);
        d = UT_convertInchesToDimension(dInches, dim);
    }
    else
    {
        d = UT_convertDimensionless(s);
    }

    return d;
}
Example #7
0
double UT_convertToPoints(const char* s)
{
    if (!s || !*s)
        return 0.;

    double result = 0.;
    double f = UT_convertDimensionless(s);
    UT_Dimension dim = UT_determineDimension(s, (UT_Dimension)-1);

    switch(dim)
    {
    case DIM_PT:
        result = f;
        break;
    case DIM_PI:
        result = f * 12;
        break; // ie, 72 / 6
    case DIM_IN:
        result = f * 72;
        break;
    case DIM_CM:
        result = f * 72 / 2.54;
        break;
    case DIM_MM:
        result = f * 72 / 25.4;
        break;
    case DIM_PX:
        result = f ;
        break;
    default:
        UT_DEBUGMSG(("Unknown dimension type for: %s", s));
        UT_ASSERT_NOT_REACHED();
        if(f > 0.9)
        {
            result = f;
        }
        else
        {
            result = 12.; // default for a font-size
        }
    }

    return result;
}
void XAP_UnixDialog_Image::doWidthEntry(void)
{
	const char * szWidth = gtk_entry_get_text(GTK_ENTRY(m_wWidthEntry));
	if(UT_determineDimension(szWidth,DIM_none) != DIM_none)
	{
		setWidth(szWidth);
		
		g_signal_handler_block(G_OBJECT(m_wWidthEntry), m_iWidthID);
		int pos = gtk_editable_get_position(GTK_EDITABLE(m_wWidthEntry));
		gtk_entry_set_text( GTK_ENTRY(m_wWidthEntry),getWidthString() );
		gtk_editable_set_position(GTK_EDITABLE(m_wWidthEntry), pos);
		g_signal_handler_unblock(G_OBJECT(m_wWidthEntry), m_iWidthID);
	}
	else
	  {
	    gtk_entry_set_text( GTK_ENTRY(m_wWidthEntry),getWidthString() );
	  }
	adjustHeightForAspect();
}
Example #9
0
const char * UT_reformatDimensionString(UT_Dimension dim, const char *sz, const char * szPrecision)
{
    UT_ASSERT(sz);  // this function segfaults if it gets a null
    if (!sz)	// if we really need to give it a null, we make it = 0in
    {
        sz = "0.0in";
        UT_DEBUGMSG(("UT_reformatDimensionString just made the assumption null = 0.0in\n"));
    }
    double d = UT_convertDimensionless(sz);

    // if needed, switch unit systems and round off
    UT_Dimension dimOld = UT_determineDimension(sz, dim);

    if (dimOld != dim)
    {
        double dInches = UT_convertToInches(sz);
        d = UT_convertInchesToDimension(dInches, dim);
    }

    return UT_formatDimensionString(dim, d, szPrecision);
}
static bool _convertBorderThickness(const char* szIncoming, UT_UTF8String& sConverted)
{
    UT_return_val_if_fail(szIncoming && *szIncoming, false);

    double d = 0.0f;
    UT_Dimension units = UT_determineDimension (szIncoming, DIM_none);

    if (units == DIM_none) {
        // no (valid) dimension specified, we'll assume inches
        d = UT_convertToInches(szIncoming);
        d = UT_convertInchesToDimension(d, DIM_PT);

    } else {
        d = UT_convertToPoints(szIncoming);
    }

    UT_LocaleTransactor t(LC_NUMERIC, "C");
    sConverted = UT_UTF8String_sprintf("%.2fpt", d);

    return true;
}
AP_Dialog_Paragraph::AP_Dialog_Paragraph(XAP_DialogFactory* pDlgFactory, XAP_Dialog_Id id)
	: XAP_Dialog_NonPersistent(pDlgFactory,id, "interface/dialogparagraph")
{
	m_answer = a_OK;
	m_paragraphPreview = NULL;
	m_pFrame = NULL;

	// determine unit system to use in this dialog
	const gchar * szRulerUnits;
	UT_return_if_fail (m_pApp);

	XAP_Prefs* pPrefs = m_pApp->getPrefs();
	UT_return_if_fail (pPrefs);

	const bool bHasRulerUnits =
		pPrefs->getPrefsValue((gchar*)AP_PREF_KEY_RulerUnits, &szRulerUnits);

	m_dim = bHasRulerUnits ? UT_determineDimension(szRulerUnits) : DIM_IN;

	m_pageLeftMargin = NULL;
	m_pageRightMargin = NULL;

	_addPropertyItem (id_MENU_ALIGNMENT,		sControlData(align_UNDEF));
	_addPropertyItem (id_SPIN_LEFT_INDENT,		sControlData());
	_addPropertyItem (id_SPIN_RIGHT_INDENT,		sControlData());
	_addPropertyItem (id_MENU_SPECIAL_INDENT,	sControlData(indent_UNDEF));
	_addPropertyItem (id_SPIN_SPECIAL_INDENT,	sControlData());
	_addPropertyItem (id_SPIN_BEFORE_SPACING,	sControlData());
	_addPropertyItem (id_SPIN_AFTER_SPACING,	sControlData());
	_addPropertyItem (id_MENU_SPECIAL_SPACING,	sControlData(spacing_UNDEF));
	_addPropertyItem (id_SPIN_SPECIAL_SPACING,	sControlData());
	_addPropertyItem (id_CHECK_WIDOW_ORPHAN,	sControlData(check_INDETERMINATE));
	_addPropertyItem (id_CHECK_KEEP_LINES,		sControlData(check_INDETERMINATE));
	_addPropertyItem (id_CHECK_PAGE_BREAK,		sControlData(check_INDETERMINATE));
	_addPropertyItem (id_CHECK_SUPPRESS,		sControlData(check_INDETERMINATE));
	_addPropertyItem (id_CHECK_NO_HYPHENATE,	sControlData(check_INDETERMINATE));
	_addPropertyItem (id_CHECK_KEEP_NEXT,		sControlData(check_INDETERMINATE));
	_addPropertyItem (id_CHECK_DOMDIRECTION,	sControlData(check_INDETERMINATE));
}
Example #12
0
double UT_convertToInches(const char* s)
{
    // NOTE: we explicitly use a period '.' as a decimal place
    // NOTE: and assume that the locale is set to english.
    // NOTE: all other places where we deal with these values
    // NOTE: are wrapped with locale code.

    double result = 0;

    if (!s || !*s)
        return 0;

    double f = UT_convertDimensionless(s);

    if (f == 0.)
        return 0.;

    UT_Dimension dim = UT_determineDimension(s, (UT_Dimension)-1);
    result = UT_convertDimToInches (f, dim);

    return result;
}
bool AP_Dialog_Paragraph::getDialogData(const gchar **& pProps)
{
	UT_Vector v;

	struct propPair
	{
		gchar * prop;
		gchar * val;
	};

	propPair * p;

	// only do this if the control has a proper value
	if (_wasChanged(id_MENU_ALIGNMENT)  && _getMenuItemValue(id_MENU_ALIGNMENT))
	{
		ALLOC_PROP_PAIR(p);
		p->prop = g_strdup("text-align");

		switch (_getMenuItemValue(id_MENU_ALIGNMENT))
		{
			case align_LEFT:
				p->val = g_strdup("left");
				break;
			case align_CENTERED:
				p->val = g_strdup("center");
				break;
			case align_RIGHT:
				p->val = g_strdup("right");
				break;
			case align_JUSTIFIED:
				p->val = g_strdup("justify");
				break;
			default:
				UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
		}
		v.addItem(p);
	}


	if (_wasChanged(id_CHECK_DOMDIRECTION))
	{
		ALLOC_PROP_PAIR(p);
		p->prop = g_strdup("dom-dir");

		if (_getCheckItemValue(id_CHECK_DOMDIRECTION) == check_TRUE)
			p->val = g_strdup("rtl");
		else
			p->val = g_strdup("ltr");

		v.addItem(p);

	}


	if (_wasChanged(id_SPIN_LEFT_INDENT))
	{
		ALLOC_PROP_PAIR(p);
		p->prop = g_strdup("margin-left");
		p->val = g_strdup(_getSpinItemValue(id_SPIN_LEFT_INDENT));

		v.addItem(p);
	}

	if (_wasChanged(id_SPIN_RIGHT_INDENT))
	{
		ALLOC_PROP_PAIR(p);
		p->prop = g_strdup("margin-right");
		p->val = g_strdup(_getSpinItemValue(id_SPIN_RIGHT_INDENT));

		v.addItem(p);
	}

	// TODO : The logic here might not be bulletproof.  If the user triggers
	// TODO : a change in the TYPE of special indent (hanging, first line,
	// TODO : none), we will always save what's in the box as a property.
	// TODO : One could make it smarter with a stronger contract with
	// TODO : the platform interfaces.

	if (_getMenuItemValue(id_MENU_SPECIAL_INDENT) &&
		(_wasChanged(id_MENU_SPECIAL_INDENT) || _wasChanged(id_SPIN_SPECIAL_INDENT)))
	{
		ALLOC_PROP_PAIR(p);
		p->prop = g_strdup("text-indent");

		tIndentState i = (tIndentState) _getMenuItemValue(id_MENU_SPECIAL_INDENT);

		if (i == indent_NONE)
			p->val = g_strdup(UT_convertInchesToDimensionString(m_dim, 0));
		else if (i == indent_FIRSTLINE)
			p->val = g_strdup(_getSpinItemValue(id_SPIN_SPECIAL_INDENT));
		else if (i == indent_HANGING)
		{
			// we have to flip the sign for "hanging" indents to a negative quantity for
			// storage in the document as a text-indent

			// get with no dimension
			UT_Dimension dim = UT_determineDimension(_getSpinItemValue(id_SPIN_SPECIAL_INDENT));
			double val = UT_convertDimensionless(_getSpinItemValue(id_SPIN_SPECIAL_INDENT));
			// Convert to inches
			val = UT_convertDimToInches(val, dim);

			// flip sign
			val = val * (double) -1;

			// store the reconstructed
			p->val = g_strdup(UT_convertInchesToDimensionString(dim, val));
		}

		v.addItem(p);
	}

	if (_wasChanged(id_SPIN_BEFORE_SPACING))
	{
		ALLOC_PROP_PAIR(p);
		p->prop = g_strdup("margin-top");
		p->val = g_strdup(_getSpinItemValue(id_SPIN_BEFORE_SPACING));

		v.addItem(p);
	}

	if (_wasChanged(id_SPIN_AFTER_SPACING))
	{
		ALLOC_PROP_PAIR(p);
		p->prop = g_strdup("margin-bottom");
		p->val = g_strdup(_getSpinItemValue(id_SPIN_AFTER_SPACING));

		v.addItem(p);
	}

	// TODO : The logic here might not be bulletproof.  If the user triggers
	// TODO : a change in the TYPE of special indent (single, double, etc.)
	// TODO : we will always save what's in the box as a property.
	// TODO : One could make it smarter with a stronger contract with
	// TODO : the platform interfaces.

	if(_getMenuItemValue(id_MENU_SPECIAL_SPACING) &&
		 (_wasChanged(id_MENU_SPECIAL_SPACING) || _wasChanged(id_SPIN_SPECIAL_SPACING)))
	{
		ALLOC_PROP_PAIR(p);
		p->prop = g_strdup("line-height");

		// normal spacings (single, 1.5, double) are just simple numbers.
		// "at least" needs a "+" at the end of the number (no units).
		// "exactly" simply has units.
		// "multiple" has no units.

		gchar * pTmp = NULL;
		const gchar * pString = _getSpinItemValue(id_SPIN_SPECIAL_SPACING);
		UT_uint32 nSize = 0;

		switch(_getMenuItemValue(id_MENU_SPECIAL_SPACING))
		{
		case spacing_SINGLE:
			p->val = g_strdup("1.0");
			break;
		case spacing_ONEANDHALF:
			p->val = g_strdup("1.5");
			break;
		case spacing_DOUBLE:
			p->val = g_strdup("2.0");
			break;
		case spacing_ATLEAST:
			nSize = strlen(pString);
			pTmp = (gchar *) UT_calloc(nSize + 2, sizeof(gchar));
			UT_return_val_if_fail (pTmp, false);

			strncpy(pTmp, pString, nSize);
			// stick a '+' at the end
			pTmp[nSize] = '+';
			p->val = g_strdup(pTmp);
			FREEP(pTmp);
			break;

		case spacing_EXACTLY:
			// fallthrough
		case spacing_MULTIPLE:
			// both these cases either do or don't have units associated with them.
			// the platform dialog code takes care of that.
			p->val = g_strdup(pString);
			break;
		default:
			UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
		}
		v.addItem(p);
	}

	// NOTE : "orphans" and "widows" hold a number specifying the number
	// NOTE : of lines to consider an orphaned or widowed piece of text.
	// NOTE : If they're both 0 they're off.  If either is greater than
	// NOTE : 0, then some form of control is in effect.  If the property
	// NOTE : is not set, they're indeterminate.

	if (_wasChanged(id_CHECK_WIDOW_ORPHAN))
	{
		// TODO : fix this!  we stomp on both properties (setting them
		// TODO : to "2"s or "0"s) if the one check box was ever
		// TODO : changed

		{
			ALLOC_PROP_PAIR(p);
			p->prop = g_strdup("orphans");

			if (_getCheckItemValue(id_CHECK_WIDOW_ORPHAN) == check_TRUE)
				p->val = g_strdup("2");
			else
				p->val = g_strdup("0");

			v.addItem(p);
		}

		{
			ALLOC_PROP_PAIR(p);
			p->prop = g_strdup("widows");

			if (_getCheckItemValue(id_CHECK_WIDOW_ORPHAN) == check_TRUE)
				p->val = g_strdup("2");
			else
				p->val = g_strdup("0");

			v.addItem(p);
		}
	}

	if (_wasChanged(id_CHECK_KEEP_LINES))
	{
		ALLOC_PROP_PAIR(p);
		p->prop = g_strdup("keep-together");

		if (_getCheckItemValue(id_CHECK_KEEP_LINES) == check_TRUE)
			p->val = g_strdup("yes");
		else
			p->val = g_strdup("no");

		v.addItem(p);
	}

	if (_wasChanged(id_CHECK_KEEP_NEXT))
	{
		ALLOC_PROP_PAIR(p);
		p->prop = g_strdup("keep-with-next");

		if (_getCheckItemValue(id_CHECK_KEEP_NEXT) == check_TRUE)
			p->val = g_strdup("yes");
		else
			p->val = g_strdup("no");

		v.addItem(p);
	}

	// TODO : add these to PP_Property (pp_Property.cpp) !!!
	/*
	  m_pageBreakBefore;
	  m_suppressLineNumbers;
	  m_noHyphenate;
	*/

	// export everything in the array
	UT_uint32 count = v.getItemCount()*2 + 1;

	const gchar ** newprops = (const gchar **) UT_calloc(count, sizeof(gchar *));
	if (!newprops)
		return false;

	const gchar ** newitem = newprops;

	UT_uint32 i = v.getItemCount();

	while (i > 0)
	{
		p = (propPair *) v.getNthItem(i-1);
		i--;

		newitem[0] = p->prop;
		newitem[1] = p->val;
		newitem += 2;
	}

	// DO purge the vector's CONTENTS, which are just propPair structs
	UT_VECTOR_FREEALL(propPair *, v);

	// DO NOT purge the propPair's CONTENTS, because they will be pointed to
	// by the pointers we just copied into memory typed (gchar **)

	pProps = newprops;

	return true;
}
bool ODi_Frame_ListenerState::_getFrameProperties(UT_UTF8String& rProps,
                                                   const gchar** ppAtts) {

    const gchar* pStyleName;
    const ODi_Style_Style* pGraphicStyle;
    const UT_UTF8String* pWrap;
    const UT_UTF8String* pBackgroundColor;
    const gchar* pVal = NULL;
    
    pStyleName = m_rElementStack.getStartTag(0)->getAttributeValue("draw:style-name");
    UT_ASSERT(pStyleName);
    
    pGraphicStyle = m_pStyles->getGraphicStyle(pStyleName, m_bOnContentStream);
    UT_return_val_if_fail(pGraphicStyle, false);
    
    pWrap = pGraphicStyle->getWrap(false);
                                                    
    if ( !strcmp(pWrap->utf8_str(), "run-through")) {
        // Floating wrapping.
        rProps += "; wrap-mode:above-text";
        
    } else if ( !strcmp(pWrap->utf8_str(), "left")) {
        rProps += "; wrap-mode:wrapped-to-left";
        
    } else if ( !strcmp(pWrap->utf8_str(), "right")) {
        rProps += "; wrap-mode:wrapped-to-right";
        
    } else if ( !strcmp(pWrap->utf8_str(), "parallel")) {
        rProps += "; wrap-mode:wrapped-both";
        
    } else {
        // Unsupported.        
        // Let's put an arbitrary wrap mode to avoid an error.
        rProps += "; wrap-mode:wrapped-both";
    }


    pBackgroundColor = pGraphicStyle->getBackgroundColor();
    if(pBackgroundColor && pBackgroundColor->length()) {
        rProps += "; background-color:";
        rProps += pBackgroundColor->utf8_str();
    }

    
    pVal = m_rElementStack.getStartTag(0)->getAttributeValue("text:anchor-type");

    if (pVal && !strcmp(pVal, "paragraph")) {
        rProps += "; position-to:block-above-text";
        
        pVal = m_rElementStack.getStartTag(0)->getAttributeValue("svg:x");
        if (pVal) {
            rProps += "; xpos:";
            rProps += pVal;
        }
        
        pVal = m_rElementStack.getStartTag(0)->getAttributeValue("svg:y");
        if (pVal) {
            rProps += "; ypos:";
            rProps += pVal;
        }
        
    } else if (pVal && !strcmp(pVal, "page")) {
        rProps += "; position-to:page-above-text";
        
        pVal = m_rElementStack.getStartTag(0)->getAttributeValue("svg:x");
        if (pVal && *pVal) {
            rProps += "; frame-page-xpos:";
            rProps += pVal;
        }
        
        pVal = m_rElementStack.getStartTag(0)->getAttributeValue("svg:y");
        if (pVal && *pVal) {
            rProps += "; frame-page-ypos:";
            rProps += pVal;
        }
        
    } else if (pVal && (!strcmp(pVal, "char") || !strcmp(pVal, "as-char"))) {
		// AbiWord does not support anchoring frames/texboxes to chars; 
		// let's just convert it to paragraph anchoring, so we don't lose the 
		// entire frame
		// FIXME: "char" means an inline thing in AbiWord terms, NOT a positioned thing
		rProps += "; position-to:block-above-text";

	    pVal = m_rElementStack.getStartTag(0)->getAttributeValue("svg:x");
        if (pVal && *pVal) {
            rProps += "; xpos:";
            rProps += pVal;
        }
        
        pVal = m_rElementStack.getStartTag(0)->getAttributeValue("svg:y");
        if (pVal && *pVal) {
            rProps += "; ypos:";
            rProps += pVal;
        }
	} else {	
		UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
        return false;
    }
    
    // From the OpenDocument standard v1.0, about text boxes properties:
    //
    // "The fo:min-height and fo:min-width attributes specify a minimum height
    // or width for a text box. If they are existing, they overwrite the height
    // or width of a text box specified by the svg:height and svg:width
    // attributes of the surrounding <draw:frame> element."
    
    // TODO: make a robust support for the relation between fo:min-width/height
    //       and svg:width/height on both <draw:frame> and <draw:text-box>
    
    pVal = UT_getAttribute("fo:min-width", ppAtts);
    if (pVal == NULL) {
        pVal = m_rElementStack.getStartTag(0)->getAttributeValue("svg:width");
        if (pVal == NULL) {
            pVal = m_rElementStack.getStartTag(0)->getAttributeValue("fo:min-width");
            if (UT_determineDimension(pVal, DIM_none) == DIM_PERCENT) {
                // TODO: Do the conversion from percentage to a real
                //       unit (ie: "cm" or "in").
                UT_ASSERT_HARMLESS(UT_NOT_IMPLEMENTED);
            }
        }
    } else {
        if (UT_determineDimension(pVal, DIM_none) == DIM_PERCENT) {
            // TODO: Do the conversion from percentage to a real
            //       unit (ie: "cm" or "in").
            UT_ASSERT_HARMLESS(UT_NOT_IMPLEMENTED);
        }
    }
    UT_ASSERT_HARMLESS(pVal); // Is it really ok to not have a defined width?
    if (pVal) 
    {
        rProps += "; frame-width:";
        rProps += pVal;
    }
    
    pVal = UT_getAttribute("style:rel-width", ppAtts);
    if(pVal)
    {
        rProps += "; frame-rel-width:";
        rProps += pVal;
    }
    else
    {
         pVal = m_rElementStack.getStartTag(0)->getAttributeValue("style:rel-width");
	 if(pVal)
	 {
	      rProps += "; frame-rel-width:";
	      rProps += pVal;
	 }
    }

    pVal = UT_getAttribute("fo:min-height", ppAtts);
    if (pVal == NULL) 
    {
        pVal = m_rElementStack.getStartTag(0)->getAttributeValue("svg:height");
        if (pVal == NULL) {
            pVal = m_rElementStack.getStartTag(0)->getAttributeValue("fo:min-height");
            if (UT_determineDimension(pVal, DIM_none) == DIM_PERCENT) {
                // TODO: Do the conversion from percentage to a real
                //       unit (ie: "cm" or "in").
                UT_ASSERT_HARMLESS(UT_NOT_IMPLEMENTED);
            }
        }
    } 
    else 
    {
        if (UT_determineDimension(pVal, DIM_none) == DIM_PERCENT) 
	{
            // TODO: Do the conversion from percentage to a real
            //       unit (ie: "cm" or "in").
            UT_ASSERT_HARMLESS(UT_NOT_IMPLEMENTED);
        }
	rProps += "; frame-min-height:";
	rProps += pVal;
    }
    if (pVal) {
        rProps += "; frame-height:";
        rProps += pVal;
    }
    
    return true;
}
Example #15
0
PP_PropertyTypeSize::PP_PropertyTypeSize(const gchar *p_init)
{
	Value = UT_convertDimensionless(p_init);
	Dim = UT_determineDimension(p_init);
}
void AP_Dialog_Paragraph::_doSpin(tControl edit, UT_sint32 amt)
{
	UT_ASSERT_HARMLESS(amt); // zero makes no sense

	// get current value from member
	const gchar* szOld = _getSpinItemValue(edit);
	double d = UT_convertDimensionless(szOld);

	// figure out which dimension and units to spin in
	UT_Dimension dimSpin = m_dim;
	double dSpinUnit = SPIN_INCR_PT;
	double dMin = 0.0;
	bool bMin = false;

	switch (edit)
	{
	case id_SPIN_SPECIAL_INDENT:
		dMin = 0.0;
		bMin = true;
		// fall through
	case id_SPIN_LEFT_INDENT:
	case id_SPIN_RIGHT_INDENT:
		dimSpin = m_dim;
		switch (dimSpin)
		{
		case DIM_IN:	dSpinUnit = SPIN_INCR_IN;	break;
		case DIM_CM:	dSpinUnit = SPIN_INCR_CM;	break;
		case DIM_PI:	dSpinUnit = SPIN_INCR_PI;	break;
		case DIM_PT:	dSpinUnit = SPIN_INCR_PT;	break;
		default:
			UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
			break;
		}
		break;

	case id_SPIN_BEFORE_SPACING:
	case id_SPIN_AFTER_SPACING:
		dimSpin = DIM_PT;
		dSpinUnit = 6.0;
		dMin = 0.0;
		bMin = true;
		break;

	case id_SPIN_SPECIAL_SPACING:
		switch(_getMenuItemValue(id_MENU_SPECIAL_SPACING))
		{
		case spacing_SINGLE:
		case spacing_ONEANDHALF:
		case spacing_DOUBLE:
			_setMenuItemValue(id_MENU_SPECIAL_SPACING, spacing_MULTIPLE);
			// fall through
		case spacing_MULTIPLE:
			dimSpin = DIM_none;
			dSpinUnit = 0.1;
			dMin = 0.5;
			bMin = true;
			break;

		case spacing_EXACTLY:
			dMin = 1;
			// fall through
		case spacing_ATLEAST:
			dimSpin = DIM_PT;
			dSpinUnit = SPIN_INCR_PT;
			bMin = true;
			break;

		default:
			UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
			break;
		}
		break;

	default:
		UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
		break;
	}

	// figure out spin precision, too
	const char * szPrecision = ".1";
	if ((dimSpin == DIM_PT) ||
		(dimSpin == DIM_PI))
		szPrecision = ".0";



	// if needed, switch unit systems and round off
	UT_Dimension dimOld = UT_determineDimension(szOld, dimSpin);

	if (dimOld != dimSpin)
	{
		double dInches = UT_convertToInches(szOld);
		d = UT_convertInchesToDimension(dInches, dimSpin);
	}

	// value is now in desired units, so change it
	d += (dSpinUnit * amt);
	if (bMin)
	{
		// some spinners clamp at bottom of range
		if (d < dMin)
			d = dMin;
	}
	const gchar* szNew = UT_formatDimensionString(dimSpin, d, szPrecision);

	_setSpinItemValue(edit, szNew);
}
void AP_Dialog_Paragraph::_syncControls(tControl changed, bool /*bAll  = false */)
{
	if(changed == id_SPIN_LEFT_INDENT)
	{
		// need to check the limits
		// cannot go past left page margin.
		// TODO : is there a minimum text width?

		double leftPageMargin = UT_convertToDimension(m_pageLeftMargin, m_dim);
		double rightIndent = UT_convertToDimension(_getSpinItemValue(id_SPIN_RIGHT_INDENT), m_dim);

		if(-UT_convertToDimension(_getSpinItemValue(id_SPIN_LEFT_INDENT), m_dim) >
					leftPageMargin)
		{
			_setSpinItemValue(id_SPIN_LEFT_INDENT,
									(const gchar *)UT_formatDimensionString(m_dim, -leftPageMargin),
									op_SYNC);
		}

		// nor past pagesize - rightIndent on right.
  		if(UT_convertDimensionless(_getSpinItemValue(id_SPIN_LEFT_INDENT)) >
						UT_convertInchesToDimension(m_iMaxWidth, m_dim) - rightIndent)
  		{
  			_setSpinItemValue(id_SPIN_LEFT_INDENT,
  									(const gchar *)UT_convertInchesToDimensionString(m_dim, m_iMaxWidth - rightIndent),
  									op_SYNC);
  		}
	}

	if(changed == id_SPIN_RIGHT_INDENT)
	{
		// need to check the limits
		// cannot go past right page margin.

		double rightPageMargin = UT_convertToDimension(m_pageRightMargin, m_dim);
		double leftIndent = UT_convertToDimension(_getSpinItemValue(id_SPIN_LEFT_INDENT), m_dim);

		if(-UT_convertToDimension(_getSpinItemValue(id_SPIN_RIGHT_INDENT), m_dim) >
					rightPageMargin)
		{
			_setSpinItemValue(id_SPIN_RIGHT_INDENT,
									(const gchar *)UT_formatDimensionString(m_dim, -rightPageMargin),
									op_SYNC);
		}

		// nor can we force text left past pagesize, minus left margin
  		if(UT_convertDimensionless(_getSpinItemValue(id_SPIN_RIGHT_INDENT)) >
						UT_convertInchesToDimension(m_iMaxWidth, m_dim) - leftIndent)
  		{
  			_setSpinItemValue(id_SPIN_RIGHT_INDENT,
  									(const gchar *)UT_convertInchesToDimensionString(m_dim, m_iMaxWidth - leftIndent),
  									op_SYNC);
  		}
	}

	if (changed == id_MENU_SPECIAL_INDENT || changed == id_SPIN_SPECIAL_INDENT)
	{
		double dDefault = 0.0;
		bool bDefault = true;

		double sign = -1.0;
		if (_getMenuItemValue(id_MENU_SPECIAL_INDENT) == indent_FIRSTLINE)
		  sign = +1.0;

		if (changed == id_MENU_SPECIAL_INDENT)
		{
			switch(_getMenuItemValue(id_MENU_SPECIAL_INDENT))
			{
			case indent_NONE:
				dDefault = 0.0;
				break;

			case indent_FIRSTLINE:
			case indent_HANGING:
				// only change to default if existing value is zero
				dDefault = UT_convertDimensionless(_getSpinItemValue(id_SPIN_SPECIAL_INDENT));
				if (dDefault == 0)
				{
					bDefault = false;
				}
				else
				{
					dDefault = 0.5;
				}
				break;

			default:
				UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
				break;
			}

			if (bDefault)
			{
				if (m_dim != DIM_IN)
					dDefault = UT_convertInchesToDimension(dDefault, m_dim);

				const gchar* szNew = UT_convertInchesToDimensionString(m_dim, dDefault, ".1");

				_setSpinItemValue(id_SPIN_SPECIAL_INDENT, szNew, op_SYNC);
			}
		}
		else /* (changed == id_SPIN_SPECIAL_INDENT) */
		{
			switch(_getMenuItemValue(id_MENU_SPECIAL_INDENT))
			{
			case indent_NONE:
				_setMenuItemValue(id_MENU_SPECIAL_INDENT, indent_FIRSTLINE, op_SYNC);
				break;

			default:
				break;
			}
		}

		// if spin contains a negative number, we flip the direction of the indent.
		double val = UT_convertDimensionless(_getSpinItemValue(id_SPIN_SPECIAL_INDENT));
		if (val < 0)
		{
			sign = -sign;

			// sometimes this appears to have no effect. why?
			if (_getMenuItemValue(id_MENU_SPECIAL_INDENT) == indent_FIRSTLINE)
				_setMenuItemValue(id_MENU_SPECIAL_INDENT, indent_HANGING, op_SYNC);
			else if (_getMenuItemValue(id_MENU_SPECIAL_INDENT) == indent_HANGING)
				_setMenuItemValue(id_MENU_SPECIAL_INDENT, indent_FIRSTLINE, op_SYNC);

			const gchar* szNew = UT_convertInchesToDimensionString(m_dim, -val, ".1");
			_setSpinItemValue(id_SPIN_SPECIAL_INDENT, szNew, op_SYNC);
		}

		// sanity check.

		double leftIndent =
		UT_convertToDimension(_getSpinItemValue(id_SPIN_LEFT_INDENT), m_dim);

		double effectiveLeftMargin = leftIndent + (UT_convertToDimension
		  (_getSpinItemValue(id_SPIN_SPECIAL_INDENT), m_dim) * sign);

		double leftPageMargin = UT_convertToDimension(m_pageLeftMargin, m_dim);
		double rightIndent = UT_convertToDimension(_getSpinItemValue(id_SPIN_RIGHT_INDENT), m_dim);

		if(-effectiveLeftMargin > leftPageMargin)
		{
			_setSpinItemValue(id_SPIN_SPECIAL_INDENT,
									(const gchar *)UT_formatDimensionString(m_dim, -leftPageMargin),
									op_SYNC);
		} 

  		if(effectiveLeftMargin >
			UT_convertInchesToDimension(m_iMaxWidth, m_dim) - rightIndent)
  		{
  			_setSpinItemValue(id_SPIN_SPECIAL_INDENT,
  									(const gchar *)UT_convertInchesToDimensionString(m_dim, m_iMaxWidth - rightIndent),
  									op_SYNC);
  		}
	}

	if (changed == id_SPIN_SPECIAL_SPACING)
	{
		switch(_getMenuItemValue(id_MENU_SPECIAL_SPACING))
		{
		case spacing_SINGLE:
		case spacing_ONEANDHALF:
		case spacing_DOUBLE:
			_setMenuItemValue(id_MENU_SPECIAL_SPACING, spacing_MULTIPLE, op_SYNC);
			break;

		default:
			break;
		}
	}

	if (changed == id_MENU_SPECIAL_SPACING)
	{
		UT_Dimension dimOld = UT_determineDimension(_getSpinItemValue(id_SPIN_SPECIAL_SPACING), DIM_none);

		switch(_getMenuItemValue(id_MENU_SPECIAL_SPACING))
		{
		case spacing_SINGLE:
			_setSpinItemValue(id_SPIN_SPECIAL_SPACING, "1.0", op_SYNC);
			break;

		case spacing_ONEANDHALF:
			_setSpinItemValue(id_SPIN_SPECIAL_SPACING, "1.5", op_SYNC);
			break;

		case spacing_DOUBLE:
			_setSpinItemValue(id_SPIN_SPECIAL_SPACING, "2.0", op_SYNC);
			break;

		case spacing_ATLEAST:
		case spacing_EXACTLY:
			// only change to default if not dimensioned
			if (dimOld == DIM_none)
				_setSpinItemValue(id_SPIN_SPECIAL_SPACING, "12pt", op_SYNC);
			break;

		case spacing_MULTIPLE:
			// only change to default if dimensioned
			if (dimOld != DIM_none)
				_setSpinItemValue(id_SPIN_SPECIAL_SPACING, "1.0", op_SYNC);
			break;

		default:
			UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
			break;
		}
	}

	// the preview needs to suck in the changed data (to cache it
	// for subsequent draws)
	UT_BidiCharType iDir;
	if(_getCheckItemValue(id_CHECK_DOMDIRECTION) == check_TRUE)
		iDir = UT_BIDI_RTL;
	else if(_getCheckItemValue(id_CHECK_DOMDIRECTION) == check_FALSE)
		iDir = UT_BIDI_LTR;
	else
	{
		// nothing given -- default to LTR
		UT_DEBUGMSG(("AP_Dialog_Paragraph::_syncControls: no value of dom-dir,"
					 " defaulting to LTR\n"));
		iDir = UT_BIDI_LTR;
	}
	
		
	m_paragraphPreview->setFormat(m_pageLeftMargin,
									m_pageRightMargin,
									(AP_Dialog_Paragraph::tAlignState) _getMenuItemValue(id_MENU_ALIGNMENT),
									_getSpinItemValue(id_SPIN_SPECIAL_INDENT),
									(AP_Dialog_Paragraph::tIndentState) _getMenuItemValue(id_MENU_SPECIAL_INDENT),
									_getSpinItemValue(id_SPIN_LEFT_INDENT),
									_getSpinItemValue(id_SPIN_RIGHT_INDENT),
									_getSpinItemValue(id_SPIN_BEFORE_SPACING),
									_getSpinItemValue(id_SPIN_AFTER_SPACING),
									_getSpinItemValue(id_SPIN_SPECIAL_SPACING),
									(AP_Dialog_Paragraph::tSpacingState) _getMenuItemValue(id_MENU_SPECIAL_SPACING),
								  iDir);

	m_paragraphPreview->queueDraw();
}
void AP_Dialog_Options::_populateWindowData(void)
{
	bool			b;
	gint			n = 0;
	XAP_Prefs		*pPrefs = 0;
	const gchar	*pszBuffer = 0;
	m_bInitialPop = true;
	// TODO: move this logic when we get a PrefsListener API and turn this
	//		 dialog into an app-specific

	pPrefs = m_pApp->getPrefs();
	UT_return_if_fail ( pPrefs );

	// ------------ Spell
	if (pPrefs->getPrefsValueBool((gchar*)AP_PREF_KEY_AutoSpellCheck,&b))
		_setSpellCheckAsType (b);

	if (pPrefs->getPrefsValueBool((gchar*)AP_PREF_KEY_SpellCheckCaps,&b))
		_setSpellUppercase (b);

	if (pPrefs->getPrefsValueBool((gchar*)AP_PREF_KEY_SpellCheckNumbers,&b))
		_setSpellNumbers (b);

	if (pPrefs->getPrefsValueBool((gchar*)AP_PREF_KEY_AutoGrammarCheck,&b))
		_setGrammarCheck (b);

	// ------------ Smart Quotes
	if (pPrefs->getPrefsValueBool((gchar*)XAP_PREF_KEY_SmartQuotesEnable,&b))
		_setSmartQuotes (b);

	if (pPrefs->getPrefsValueBool((gchar*)XAP_PREF_KEY_CustomSmartQuotes,&b))
		_setCustomSmartQuotes (b);
		
	if (pPrefs->getPrefsValueInt((gchar*)XAP_PREF_KEY_OuterQuoteStyle, n))
		_setOuterQuoteStyle(n);
		
	if (pPrefs->getPrefsValueInt((gchar*)XAP_PREF_KEY_InnerQuoteStyle, n))
		_setInnerQuoteStyle(n);

	// ------------ Prefs
	_setPrefsAutoSave( pPrefs->getAutoSavePrefs() );

	// ------------ View
	if (pPrefs->getPrefsValue((gchar*)AP_PREF_KEY_RulerUnits,&pszBuffer))
		_setViewRulerUnits (UT_determineDimension(pszBuffer));


#if !defined(TOOLKIT_GTK) && !defined(TOOLKIT_COCOA) && !defined (TOOLKIT_WIN) 
	if (pPrefs->getPrefsValueBool((gchar*)AP_PREF_KEY_RulerVisible,&b))
		_setViewShowRuler (b);
	UT_uint32 i;
	for (i = 0; i < m_pApp->getToolbarFactory()->countToolbars(); i++) {
		if (pPrefs->getPrefsValueBool((gchar*)m_pApp->getToolbarFactory()->prefKeyForToolbar(i),&b)) {
			_setViewShowToolbar (i, b);
		}
	}

	if (pPrefs->getPrefsValueBool((gchar*)AP_PREF_KEY_StatusBarVisible,&b))
		_setViewShowStatusBar (b);
#endif	


	if (pPrefs->getPrefsValueBool((gchar*)AP_PREF_KEY_InsertModeToggle,&b))
		_setEnableOverwrite (b);

	if (pPrefs->getPrefsValueBool((gchar*)AP_PREF_KEY_ParaVisible,&b))
		_setViewUnprintable (b);

	if (pPrefs->getPrefsValueBool((gchar*)AP_PREF_KEY_CursorBlink,&b))
		_setViewCursorBlink (b);

#if defined(TOOLKIT_GTK)
	if (pPrefs->getPrefsValueBool((gchar*)XAP_PREF_KEY_EnableSmoothScrolling,&b))
		_setEnableSmoothScrolling(b);
#endif
	if (pPrefs->getPrefsValueBool((gchar*)XAP_PREF_KEY_AutoLoadPlugins,&b))
		_setAutoLoadPlugins(b);

	// TODO: JOAQUIN FIX THIS
	if (pPrefs->getPrefsValueBool((gchar*)XAP_PREF_KEY_AutoSaveFile,&b))
		_setAutoSaveFile (b);

	UT_String stBuffer;
	if (pPrefs->getPrefsValue(XAP_PREF_KEY_AutoSaveFileExt, stBuffer))
		_setAutoSaveFileExt(stBuffer);

	if (pPrefs->getPrefsValue(XAP_PREF_KEY_AutoSaveFilePeriod, stBuffer))
		_setAutoSaveFilePeriod(stBuffer);
		
	//Just for win32 
	if (pPrefs->getPrefsValue(AP_PREF_KEY_StringSet, stBuffer))
		_setUILanguage(stBuffer);
		
	// ------------ Screen Color

	const gchar * pszColorForTransparent = NULL;
	if (pPrefs->getPrefsValue(XAP_PREF_KEY_ColorForTransparent, &pszColorForTransparent))
		_setColorForTransparent(pszColorForTransparent);


	// ------------ the page tab number
	int which = getInitialPageNum ();
	if ((which == -1) && pPrefs->getPrefsValue((gchar*)AP_PREF_KEY_OptionsTabNumber,&pszBuffer))
		_setNotebookPageNum (atoi(pszBuffer));
	else
	  _setNotebookPageNum(which);

	//------------- other
	if (pPrefs->getPrefsValueBool(AP_PREF_KEY_DefaultDirectionRtl,&b))
		_setOtherDirectionRtl (b);

	if (pPrefs->getPrefsValueBool(XAP_PREF_KEY_ChangeLanguageWithKeyboard,&b))
		_setLanguageWithKeyboard (b);

	if (pPrefs->getPrefsValueBool(XAP_PREF_KEY_DirMarkerAfterClosingParenthesis,&b))
		_setDirMarkerAfterClosingParenthesis (b);
	
	// enable/disable controls
	_initEnableControls();
	m_bInitialPop = false;
}