Commit 0fef6992 authored by Andrea Iacovitti's avatar Andrea Iacovitti

Support 'ch' font-relative length unit type.

parent ac3b045f
......@@ -1089,12 +1089,21 @@ double CSSPrimitiveValueImpl::computeLengthFloat( khtml::RenderStyle *style, int
case CSSPrimitiveValue::CSS_EMS:
factor = style->font().pixelSize();
break;
case CSSPrimitiveValue::CSS_EXS:
{
QFontMetrics fm = style->fontMetrics();
case CSSPrimitiveValue::CSS_EXS: {
const QFontMetrics fm = style->fontMetrics();
factor = fm.xHeight();
break;
}
}
case CSSPrimitiveValue::CSS_CHS: {
const int zw = style->htmlFont().zeroCharWidth();
if (zw != -1) {
factor = zw;
} else {
// assume 0.5em
return ((double)0.5 * style->font().pixelSize());
}
break;
}
case CSSPrimitiveValue::CSS_PX:
break;
case CSSPrimitiveValue::CSS_CM:
......@@ -1214,6 +1223,9 @@ DOM::DOMString CSSPrimitiveValueImpl::cssText() const
case CSSPrimitiveValue::CSS_EXS:
text = DOMString(QString::number( m_value.num ) + "ex");
break;
case CSSPrimitiveValue::CSS_CHS:
text = DOMString(QString::number( m_value.num ) + "ch");
break;
case CSSPrimitiveValue::CSS_PX:
text = DOMString(QString::number( m_value.num ) + "px");
break;
......
......@@ -449,6 +449,7 @@ bool CSSParser::validUnit( Value *value, int unitflags, bool strict )
case Value::Q_EMS:
case CSSPrimitiveValue::CSS_EMS:
case CSSPrimitiveValue::CSS_EXS:
case CSSPrimitiveValue::CSS_CHS:
case CSSPrimitiveValue::CSS_PX:
case CSSPrimitiveValue::CSS_CM:
case CSSPrimitiveValue::CSS_MM:
......@@ -2928,6 +2929,7 @@ int DOM::CSSParser::lex( void *_yylval )
case HERZ:
case EMS:
case EXS:
case CHS:
case PXS:
case CMS:
case MMS:
......
......@@ -3475,8 +3475,9 @@ void CSSStyleSelector::applyRule( int id, DOM::CSSValueImpl *value )
} else {
int type = primitiveValue->primitiveType();
if (type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG) {
if (!khtml::printpainter && type != CSSPrimitiveValue::CSS_EMS && type != CSSPrimitiveValue::CSS_EXS &&
view && view->part()) {
// Scale for the font zoom factor only for types other than "em", "ex", "ch", since those are
// already based on the font size.
if (!khtml::printpainter && !(type >= CSSPrimitiveValue::CSS_EMS && type <= CSSPrimitiveValue::CSS_CHS) && view && view->part()) {
size = qRound(primitiveValue->computeLengthFloat(parentStyle, logicalDpiY) * view->part()->fontScaleFactor() / 100.0);
} else {
size = qRound(primitiveValue->computeLengthFloat(parentStyle, logicalDpiY));
......@@ -3561,14 +3562,13 @@ void CSSStyleSelector::applyRule( int id, DOM::CSSValueImpl *value )
if (primitiveValue->getIdent() == CSS_VAL_NORMAL)
lineHeight = Length( -100.0, Percent );
else if (type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG) {
// Scale for the font zoom factor only for types other than "em" and "ex", since those are
// Scale for the font zoom factor only for types other than "em", "ex", "ch", since those are
// already based on the font size.
if ( !khtml::printpainter && type != CSSPrimitiveValue::CSS_EMS && type != CSSPrimitiveValue::CSS_EXS &&
view && view->part())
lineHeight = Length(primitiveValue->computeLength(style, logicalDpiY) *
view->part()->fontScaleFactor()/100, Fixed );
else
lineHeight = Length(primitiveValue->computeLength(style, logicalDpiY), Fixed );
if (!khtml::printpainter && !(type >= CSSPrimitiveValue::CSS_EMS && type <= CSSPrimitiveValue::CSS_CHS) && view && view->part()) {
lineHeight = Length(primitiveValue->computeLength(style, logicalDpiY) * view->part()->fontScaleFactor() / 100, Fixed);
} else {
lineHeight = Length(primitiveValue->computeLength(style, logicalDpiY), Fixed);
}
} else if (type == CSSPrimitiveValue::CSS_PERCENTAGE)
lineHeight = Length( ( style->font().pixelSize() * int(primitiveValue->floatValue(CSSPrimitiveValue::CSS_PERCENTAGE)) ) / 100, Fixed );
else if (type == CSSPrimitiveValue::CSS_NUMBER)
......
This diff is collapsed.
......@@ -68,29 +68,30 @@
QEMS = 286,
EMS = 287,
EXS = 288,
PXS = 289,
CMS = 290,
MMS = 291,
INS = 292,
PTS = 293,
PCS = 294,
DEGS = 295,
RADS = 296,
GRADS = 297,
MSECS = 298,
SECS = 299,
HERZ = 300,
KHERZ = 301,
DPI = 302,
DPCM = 303,
DIMEN = 304,
PERCENTAGE = 305,
FLOAT = 306,
INTEGER = 307,
URI = 308,
FUNCTION = 309,
NOTFUNCTION = 310,
UNICODERANGE = 311
CHS = 289,
PXS = 290,
CMS = 291,
MMS = 292,
INS = 293,
PTS = 294,
PCS = 295,
DEGS = 296,
RADS = 297,
GRADS = 298,
MSECS = 299,
SECS = 300,
HERZ = 301,
KHERZ = 302,
DPI = 303,
DPCM = 304,
DIMEN = 305,
PERCENTAGE = 306,
FLOAT = 307,
INTEGER = 308,
URI = 309,
FUNCTION = 310,
NOTFUNCTION = 311,
UNICODERANGE = 312
};
#endif
......
......@@ -108,7 +108,7 @@ int DOM::getValueID(const char *tagStr, int len)
#define YYLTYPE_IS_TRIVIAL 1
%}
%expect 39
%expect 40
%pure_parser
......@@ -214,6 +214,7 @@ static int cssyylex( YYSTYPE *yylval ) {
%token <val> QEMS
%token <val> EMS
%token <val> EXS
%token <val> CHS
%token <val> PXS
%token <val> CMS
%token <val> MMS
......@@ -1231,6 +1232,7 @@ unary_term:
| EMS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_EMS; }
| QEMS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = Value::Q_EMS; }
| EXS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_EXS; }
| CHS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_CHS; }
| DPI maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_DPI; }
| DPCM maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_DPCM; }
;
......
This diff is collapsed.
......@@ -67,6 +67,7 @@ nth ([\+-]?[0-9]*n[ \t\r\n\f]*[\+-][ \t\r\n\f]*[0-9]+)|([\+-]?[0-9]*
{num}em {yyTok = EMS; return yyTok;}
{num}__qem {yyTok = QEMS; return yyTok;} /* quirky ems */
{num}ex {yyTok = EXS; return yyTok;}
{num}ch {yyTok = CHS; return yyTok;}
{num}px {yyTok = PXS; return yyTok;}
{num}cm {yyTok = CMS; return yyTok;}
{num}mm {yyTok = MMS; return yyTok;}
......
......@@ -392,29 +392,30 @@ public:
CSS_PERCENTAGE = 2,
CSS_EMS = 3,
CSS_EXS = 4,
CSS_PX = 5,
CSS_CM = 6,
CSS_MM = 7,
CSS_IN = 8,
CSS_PT = 9,
CSS_PC = 10,
CSS_DEG = 11,
CSS_RAD = 12,
CSS_GRAD = 13,
CSS_MS = 14,
CSS_S = 15,
CSS_HZ = 16,
CSS_KHZ = 17,
CSS_DIMENSION = 18,
CSS_STRING = 19,
CSS_URI = 20,
CSS_IDENT = 21,
CSS_ATTR = 22,
CSS_COUNTER = 23,
CSS_RECT = 24,
CSS_RGBCOLOR = 25,
CSS_DPI = 26,
CSS_DPCM = 27,
CSS_CHS = 5,
CSS_PX = 6,
CSS_CM = 7,
CSS_MM = 8,
CSS_IN = 9,
CSS_PT = 10,
CSS_PC = 11,
CSS_DEG = 12,
CSS_RAD = 13,
CSS_GRAD = 14,
CSS_MS = 15,
CSS_S = 16,
CSS_HZ = 17,
CSS_KHZ = 18,
CSS_DIMENSION = 19,
CSS_STRING = 20,
CSS_URI = 21,
CSS_IDENT = 22,
CSS_ATTR = 23,
CSS_COUNTER = 24,
CSS_RECT = 25,
CSS_RGBCOLOR = 26,
CSS_DPI = 27,
CSS_DPCM = 28,
CSS_PAIR = 100, // We envision this being exposed as a means of getting computed style values for pairs
CSS_HTML_RELATIVE = 255
};
......
......@@ -1212,6 +1212,7 @@ const ClassInfo CSSPrimitiveValueConstructor::info = { "CSSPrimitiveValueConstru
CSS_PERCENTAGE DOM::CSSPrimitiveValue::CSS_PERCENTAGE DontDelete|ReadOnly
CSS_EMS DOM::CSSPrimitiveValue::CSS_EMS DontDelete|ReadOnly
CSS_EXS DOM::CSSPrimitiveValue::CSS_EXS DontDelete|ReadOnly
CSS_CHS DOM::CSSPrimitiveValue::CSS_CHS DontDelete|ReadOnly
CSS_PX DOM::CSSPrimitiveValue::CSS_PX DontDelete|ReadOnly
CSS_CM DOM::CSSPrimitiveValue::CSS_CM DontDelete|ReadOnly
CSS_MM DOM::CSSPrimitiveValue::CSS_MM DontDelete|ReadOnly
......
......@@ -580,6 +580,13 @@ CachedFontInstance::CachedFontInstance(CachedFontFamily* p, int sz):
descent = fm.descent();
height = fm.height();
lineSpacing = fm.lineSpacing();
const QChar zeroChar((ushort)48);
if (!fm.inFont(zeroChar)) {
m_zeroCharWidth = -1;
} else {
m_zeroCharWidth = (int)cachedCharWidth(zeroChar);
}
}
void CachedFontInstance::invalidate()
......@@ -602,6 +609,13 @@ void CachedFontInstance::invalidate()
descent = fm.descent();
height = fm.height();
lineSpacing = fm.lineSpacing();
const QChar zeroChar((ushort)48);
if (!fm.inFont(zeroChar)) {
m_zeroCharWidth = -1;
} else {
m_zeroCharWidth = (int)cachedCharWidth(zeroChar);
}
}
CachedFontInstance::~CachedFontInstance()
......
......@@ -82,6 +82,7 @@ public:
int descent;
int height;
int lineSpacing;
int m_zeroCharWidth;
mutable bool invalidated;
~CachedFontInstance();
......@@ -241,6 +242,9 @@ public:
int height() const { return cfi->height; }
int lineSpacing() const { return cfi->lineSpacing; }
float xHeight() const { return cfi->fm.xHeight(); }
// return -1 if '0' char glyph not in font
int zeroCharWidth() const { return cfi->m_zeroCharWidth; }
//FIXME: IMPLEMENT ME
unsigned unitsPerEm() const { return 0; }
int spaceWidth() const { return 0; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment