PDA

View Full Version : Strange Unit em - same as inch? on XSLT-Fo format


patrik08
13th July 2007, 22:29
I work on XSL-FO (to play exact invoice print) format http://xmlgraphics.apache.org/fop/ to parse all on
QTextDocument && dispay on QTextBrowser or QGraphicsScene .

i found em unit nummer is this same as inch? or how is the faktor to convert on point?



<fo:block>
<fo:block font-size="16pt" font-weight="bold" space-before.minimum="1em" space-before.optimum="1.5em" space-before.maximum="2em">Sized</fo:block>
<fo:block>
The image
(<fo:external-graphic width="150pt" height="50pt" src="images/fop.jpg"/>)
has the width and height set.
</fo:block>
</fo:block>



is the faktor here correct or mistake?


double FopFormat::ConvertUnit( const QString &data )
{
#define MM_TO_POINT(mm) ((mm)*2.83465058)
#define CM_TO_POINT(cm) ((cm)*28.3465058)
#define DM_TO_POINT(dm) ((dm)*283.465058)
#define INCH_TO_POINT(inch) ((inch)*72.0)
#define PI_TO_POINT(pi) ((pi)*12)
#define DD_TO_POINT(dd) ((dd)*154.08124)
#define CC_TO_POINT(cc) ((cc)*12.840103)
#define EM_TO_POINT(em) ((em)*25.02)

double points = 0;
if ( data.endsWith( "pt" ) ) {
points = data.left( data.length() - 2 ).toDouble();
} else if ( data.endsWith( "cm" ) ) {
double value = data.left( data.length() - 2 ).toDouble();
points = CM_TO_POINT( value );
} else if ( data.endsWith( "em" ) ) {
double value = data.left( data.length() - 2 ).toDouble();
points = EM_TO_POINT( value );
} else if ( data.endsWith( "mm" ) ) {
double value = data.left( data.length() - 2 ).toDouble();
points = MM_TO_POINT( value );
} else if ( data.endsWith( "dm" ) ) {
double value = data.left( data.length() - 2 ).toDouble();
points = DM_TO_POINT( value );
} else if ( data.endsWith( "in" ) ) {
double value = data.left( data.length() - 2 ).toDouble();
points = INCH_TO_POINT( value );
} else if ( data.endsWith( "inch" ) ) {
double value = data.left( data.length() - 4 ).toDouble();
points = INCH_TO_POINT( value );
} else if ( data.endsWith( "pi" ) ) {
double value = data.left( data.length() - 4 ).toDouble();
points = PI_TO_POINT( value );
} else if ( data.endsWith( "dd" ) ) {
double value = data.left( data.length() - 4 ).toDouble();
points = DD_TO_POINT( value );
} else if ( data.endsWith( "cc" ) ) {
double value = data.left( data.length() - 4 ).toDouble();
points = CC_TO_POINT( value );
} else {
points = 12;
qDebug( "unknown unit %s", qPrintable( data ) );
}

return points;
}

jacek
13th July 2007, 23:05
1 em represents the width of "m" and its exact value in points depends on the font you choose.

There's also 1 ex, which is equal to height of "x".

patrik08
13th July 2007, 23:09
1 em represents the width of "m" and its exact value in points depends on the font you choose.
There's also 1 ex, which is equal to height of "x".

Ahh... 10em = 10pt depends on the font? i hope true type stay same.... tanks..

wysota
16th July 2007, 00:46
No, it's like Jacek said. It'll be easier to explain it with ex - if you have a font that is 12pt high then 1ex will be about 8pt. As "m" is the widest character for proportional fonts, the width of "m" will have a larger value (in points) than the width of "i", so you can't just say that your font is "8 points wide" (unless the font is monospaced, like Courier), but you can say that its "m" glyph is 12 points wide.