qreal Pointo( qreal unit , const QString unita ) { qreal ri = 0; if (unita == "cm") { ri = POINT_TO_CM( unit ); } else if (unita == "pt" || unita == "px" ) { ri = unit; return ri; } else if (unita == "mm") { ri = POINT_TO_MM( unit ); } else if (unita == "dm") { ri = POINT_TO_DM( unit ); } else if (unita == "inch") { ri = POINT_TO_INCH( unit ); } else if (unita == "pi") { ri = POINT_TO_PI( unit ); } else if (unita == "dd") { ri = POINT_TO_DD( unit ); } else if (unita == "cc") { ri = POINT_TO_CC( unit ); } else { ri = 10; } return ri; }
qreal KoUnit::convertFromUnitToUnit(const qreal value, const KoUnit &fromUnit, const KoUnit &toUnit, qreal factor) { qreal pt; switch (fromUnit.type()) { case Millimeter: pt = MM_TO_POINT(value); break; case Centimeter: pt = CM_TO_POINT(value); break; case Decimeter: pt = DM_TO_POINT(value); break; case Inch: pt = INCH_TO_POINT(value); break; case Pica: pt = PI_TO_POINT(value); break; case Cicero: pt = CC_TO_POINT(value); break; case Pixel: pt = value / factor; break; case Point: default: pt = value; } switch (toUnit.type()) { case Millimeter: return POINT_TO_MM(pt); case Centimeter: return POINT_TO_CM(pt); case Decimeter: return POINT_TO_DM(pt); case Inch: return POINT_TO_INCH(pt); case Pica: return POINT_TO_PI(pt); case Cicero: return POINT_TO_CC(pt); case Pixel: return pt * factor; case Point: default: return pt; } }
qreal KoUnit::ptToUnit(const qreal ptValue, const KoUnit &unit) { switch (unit.m_type) { case Millimeter: return POINT_TO_MM(ptValue); case Centimeter: return POINT_TO_CM(ptValue); case Decimeter: return POINT_TO_DM(ptValue); case Inch: return POINT_TO_INCH(ptValue); case Pica: return POINT_TO_PI(ptValue); case Cicero: return POINT_TO_CC(ptValue); case Pixel: return ptValue * unit.m_pixelConversion; case Point: default: return ptValue; } }
void KoPageLayout::loadOdf(const KoXmlElement &style) { KoXmlElement properties(KoXml::namedItemNS(style, KoXmlNS::style, "page-layout-properties")); if (!properties.isNull()) { KoPageLayout standard; // Page dimension -- width / height width = KoUnit::parseValue(properties.attributeNS(KoXmlNS::fo, "page-width"), standard.width); height = KoUnit::parseValue(properties.attributeNS(KoXmlNS::fo, "page-height"), standard.height); // Page orientation if (properties.attributeNS(KoXmlNS::style, "print-orientation", QString()) == "portrait") orientation = KoPageFormat::Portrait; else orientation = KoPageFormat::Landscape; // Margins. Check if there is one "margin" attribute and use it for all // margins if there is. Otherwise load the individual margins. if (properties.hasAttributeNS(KoXmlNS::fo, "margin")) { leftMargin = KoUnit::parseValue(properties.attributeNS(KoXmlNS::fo, "margin")); topMargin = leftMargin; rightMargin = leftMargin; bottomMargin = leftMargin; } else { /* If one of the individual margins is specified then the default for the others is zero. Otherwise all of them are set to 20mm. */ qreal defaultValue = 0; if (!(properties.hasAttributeNS(KoXmlNS::fo, "margin-left") || properties.hasAttributeNS(KoXmlNS::fo, "margin-top") || properties.hasAttributeNS(KoXmlNS::fo, "margin-right") || properties.hasAttributeNS(KoXmlNS::fo, "margin-bottom"))) defaultValue = MM_TO_POINT(20.0); // no margin specified at all, lets make it 20mm leftMargin = KoUnit::parseValue(properties.attributeNS(KoXmlNS::fo, "margin-left"), defaultValue); topMargin = KoUnit::parseValue(properties.attributeNS(KoXmlNS::fo, "margin-top"), defaultValue); rightMargin = KoUnit::parseValue(properties.attributeNS(KoXmlNS::fo, "margin-right"), defaultValue); bottomMargin = KoUnit::parseValue(properties.attributeNS(KoXmlNS::fo, "margin-bottom"), defaultValue); } // Padding. Same reasoning as for margins if (properties.hasAttributeNS(KoXmlNS::fo, "padding")) { leftPadding = KoUnit::parseValue(properties.attributeNS(KoXmlNS::fo, "padding")); topPadding = leftPadding; rightPadding = leftPadding; bottomPadding = leftPadding; } else { leftPadding = KoUnit::parseValue(properties.attributeNS(KoXmlNS::fo, "padding-left")); topPadding = KoUnit::parseValue(properties.attributeNS(KoXmlNS::fo, "padding-top")); rightPadding = KoUnit::parseValue(properties.attributeNS(KoXmlNS::fo, "padding-right")); bottomPadding = KoUnit::parseValue(properties.attributeNS(KoXmlNS::fo, "padding-bottom")); } // Parse border properties if there are any. border.loadOdf(properties); // guessFormat takes millimeters if (orientation == KoPageFormat::Landscape) format = KoPageFormat::guessFormat(POINT_TO_MM(height), POINT_TO_MM(width)); else format = KoPageFormat::guessFormat(POINT_TO_MM(width), POINT_TO_MM(height)); } }