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