⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 csshelper.cpp

📁 monqueror一个很具有参考价值的源玛
💻 CPP
字号:
/* * This file is part of the CSS implementation for KDE. * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB.  If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * $Id: csshelper.cpp,v 1.1.1.1 2002/01/16 10:39:55 ymwei Exp $ *///#include <qfontmetrics.h>//#include <qfontinfo.h>#include "csshelper.h"#include "render_style.h"#include "css_valueimpl.h"#include "css_value.h"#include "mgrect.h"#include "mgfontinfo.h"#include "kdebug.h"using namespace DOM;using namespace khtml;int khtml::computeLength(DOM::CSSPrimitiveValueImpl *val, RenderStyle *style, MGHTMLPart* part, Metrics m){    unsigned short type = val->primitiveType();    float factor = 1.;    switch(type)    {    case CSSPrimitiveValue::CSS_EMS:    case CSSPrimitiveValue::CSS_EXS:    {        if(type == CSSPrimitiveValue::CSS_EMS)        {#if 0            QFontMetrics fm(style->font());            factor = fm.height();#else            MGFontInfo fi(style->font());            factor = fi.pointSize();#endif            //kdDebug( 6080 ) << "EM = " << factor << endl;        }        else        {            MGFontMetrics fm(style->font(), part);            MGRect b = fm.boundingRect('x');            factor = b.height();        }        break;    }    case CSSPrimitiveValue::CSS_PX:        break;    case CSSPrimitiveValue::CSS_CM:        if(m == MetricScreen)            factor = 72./2.54; //72dpi/(2.54 cm/in)        else            factor = 300./2.54; //300dpi/(2.54 cm/in)        break;    case CSSPrimitiveValue::CSS_MM:        if(m == MetricScreen)            factor = 72./25.4;        else            factor = 300./25.4;        break;    case CSSPrimitiveValue::CSS_IN:        if(m == MetricScreen)            factor = 72.;        else            factor = 300.;        break;    case CSSPrimitiveValue::CSS_PT:        if(m == MetricScreen)            factor = 1.;        else            factor = 300./72.;        break;    case CSSPrimitiveValue::CSS_PC:        // 1 pc == 12 pt        if(m == MetricScreen)            factor = 12.;        else            factor = 300./72.*12.;        break;    default:        return -1;    }    return (int)(val->getFloatValue(type)*factor);}DOMString khtml::parseURL(const DOMString &url){    QString s = url.string().stripWhiteSpace();    if(s.find("url(") == 0 && s[s.length()-1] == ')')        s = s.mid(4, s.length()-5);    s = s.stripWhiteSpace();    if(s[0] == '\"' && s[s.length()-1] == '\"')        s = s.mid(1, s.length()-2);    if(s[0] == '\'' && s[s.length()-1] == '\'')        s = s.mid(1, s.length()-2);    // remove unnecessary newlines etc from beginning/end    // another "just like Netscape" feature    s = s.stripWhiteSpace();    return DOMString(s.unicode(), s.length());}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -