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; }
UT_sint32 UT_convertSizeToLayoutUnits(double Value, UT_Dimension dim) { return static_cast<UT_sint32>(UT_convertDimToInches(Value, dim) * UT_LAYOUT_RESOLUTION); }
double UT_convertDimensions(double f, UT_Dimension from, UT_Dimension to) { double valueScaled = UT_convertDimToInches(f, from); return UT_convertInchesToDimension(valueScaled, to); }