From 4dd78f0fec16ca0d1e0bc49c2a7963cdbe80c630 Mon Sep 17 00:00:00 2001 From: ap Date: Thu, 24 Aug 2006 16:49:19 +0000 Subject: [PATCH] Reviewed by ap. Fixes parts of: http://bugzilla.opendarwin.org/show_bug.cgi?id=10467 WebKit should have Qt platform support * platform/qt/FontCacheQt.cpp: Added. (WebCore::FontCache::platformInit): (WebCore::FontCache::getFontDataForCharacters): (WebCore::FontCache::getSimilarFontPlatformData): (WebCore::FontCache::getLastResortFallbackFont): (WebCore::FontCache::createFontPlatformData): * platform/qt/FontDataQt.cpp: Added. (WebCore::FontData::platformInit): (WebCore::FontData::platformDestroy): (WebCore::FontData::smallCapsFontData): (WebCore::FontData::containsCharacters): (WebCore::FontData::determinePitch): (WebCore::FontData::platformWidthForGlyph): * platform/qt/FontPlatformData.h: Added. * platform/qt/FontPlatformDataQt.cpp: Added. (WebCore::FontPlatformData::FontPlatformData): (WebCore::FontPlatformData::operator=): (WebCore::FontPlatformData::~FontPlatformData): (WebCore::FontPlatformData::isFixedPitch): (WebCore::FontPlatformData::setFont): (WebCore::FontPlatformData::font): (WebCore::FontPlatformData::hash): (WebCore::FontPlatformData::operator==): * platform/qt/FontQt.cpp: Added. (WebCore::Font::operator QFont): (WebCore::Font::drawGlyphs): (WebCore::Font::drawComplexText): (WebCore::Font::floatWidthForComplexText): * platform/qt/GlyphMapQt.cpp: Added. (WebCore::GlyphMap::fillPage): git-svn-id: https://svn.webkit.org/repository/webkit/trunk@16012 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- WebCore/ChangeLog | 38 ++++++++ WebCore/platform/qt/FontCacheQt.cpp | 69 ++++++++++++++ WebCore/platform/qt/FontDataQt.cpp | 82 +++++++++++++++++ WebCore/platform/qt/FontPlatformData.h | 69 ++++++++++++++ WebCore/platform/qt/FontPlatformDataQt.cpp | 102 +++++++++++++++++++++ WebCore/platform/qt/FontQt.cpp | 80 ++++++++++++++++ WebCore/platform/qt/GlyphMapQt.cpp | 48 ++++++++++ 7 files changed, 488 insertions(+) create mode 100644 WebCore/platform/qt/FontCacheQt.cpp create mode 100644 WebCore/platform/qt/FontDataQt.cpp create mode 100644 WebCore/platform/qt/FontPlatformData.h create mode 100644 WebCore/platform/qt/FontPlatformDataQt.cpp create mode 100644 WebCore/platform/qt/FontQt.cpp create mode 100644 WebCore/platform/qt/GlyphMapQt.cpp diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog index 02dfacc6c41d..1633daea5dee 100644 --- a/WebCore/ChangeLog +++ b/WebCore/ChangeLog @@ -1,3 +1,41 @@ +2006-08-24 Nikolas Zimmermann + + Reviewed by ap. + + Fixes parts of: http://bugzilla.opendarwin.org/show_bug.cgi?id=10467 + WebKit should have Qt platform support + + * platform/qt/FontCacheQt.cpp: Added. + (WebCore::FontCache::platformInit): + (WebCore::FontCache::getFontDataForCharacters): + (WebCore::FontCache::getSimilarFontPlatformData): + (WebCore::FontCache::getLastResortFallbackFont): + (WebCore::FontCache::createFontPlatformData): + * platform/qt/FontDataQt.cpp: Added. + (WebCore::FontData::platformInit): + (WebCore::FontData::platformDestroy): + (WebCore::FontData::smallCapsFontData): + (WebCore::FontData::containsCharacters): + (WebCore::FontData::determinePitch): + (WebCore::FontData::platformWidthForGlyph): + * platform/qt/FontPlatformData.h: Added. + * platform/qt/FontPlatformDataQt.cpp: Added. + (WebCore::FontPlatformData::FontPlatformData): + (WebCore::FontPlatformData::operator=): + (WebCore::FontPlatformData::~FontPlatformData): + (WebCore::FontPlatformData::isFixedPitch): + (WebCore::FontPlatformData::setFont): + (WebCore::FontPlatformData::font): + (WebCore::FontPlatformData::hash): + (WebCore::FontPlatformData::operator==): + * platform/qt/FontQt.cpp: Added. + (WebCore::Font::operator QFont): + (WebCore::Font::drawGlyphs): + (WebCore::Font::drawComplexText): + (WebCore::Font::floatWidthForComplexText): + * platform/qt/GlyphMapQt.cpp: Added. + (WebCore::GlyphMap::fillPage): + 2006-08-24 David Harrison Reinstate r15966 because layout test changes are correct. diff --git a/WebCore/platform/qt/FontCacheQt.cpp b/WebCore/platform/qt/FontCacheQt.cpp new file mode 100644 index 000000000000..97227e6dc31c --- /dev/null +++ b/WebCore/platform/qt/FontCacheQt.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2006 Dirk Mueller + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "FontCache.h" + +#include "Font.h" +#include "FontPlatformData.h" + +namespace WebCore { + +void FontCache::platformInit() +{ + // no-op +} + +const FontData* FontCache::getFontDataForCharacters(const Font& font, const UChar* characters, int length) +{ + return new FontData(FontPlatformData(font.fontDescription(), font.family().family())); +} + +FontPlatformData* FontCache::getSimilarFontPlatformData(const Font& font) +{ + return new FontPlatformData(font.fontDescription(), font.family().family()); +} + +FontPlatformData* FontCache::getLastResortFallbackFont(const Font& font) +{ + // FIXME: Would be even better to somehow get the user's default font here. + // For now we'll pick the default that the user would get without changing any prefs. + static AtomicString s_timesStr("Times New Roman"); + return getCachedFontPlatformData(font.fontDescription(), s_timesStr); +} + +FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family) +{ + return 0; +} + +} + +// vim: ts=4 sw=4 et diff --git a/WebCore/platform/qt/FontDataQt.cpp b/WebCore/platform/qt/FontDataQt.cpp new file mode 100644 index 000000000000..9055c6c8d1f8 --- /dev/null +++ b/WebCore/platform/qt/FontDataQt.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2006 Dirk Mueller + * Copyright (C) 2006 Simon Hausmann + * Copyright (C) 2006 George Staikos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "FontData.h" + +#include "Font.h" +#include "FloatRect.h" +#include "FontCache.h" +#include "GlyphBuffer.h" +#include "FontDescription.h" + +#include + +namespace WebCore { + +void FontData::platformInit() +{ + QFontMetrics metrics(m_font.font()); + m_ascent = metrics.ascent(); + m_descent = metrics.descent(); + m_lineSpacing = metrics.lineSpacing(); + m_lineGap = metrics.leading(); + m_xHeight = metrics.xHeight(); + m_lineSpacing = m_ascent + m_descent + m_lineGap; +} + +void FontData::platformDestroy() +{ +} + +FontData* FontData::smallCapsFontData(const FontDescription& fontDescription) const +{ + return 0; +} + +bool FontData::containsCharacters(const UChar* characters, int length) const +{ + return true; +} + +void FontData::determinePitch() +{ +} + +float FontData::platformWidthForGlyph(Glyph glyph) const +{ + return QFontMetricsF(m_font.font()).width(QChar(ushort(glyph))); +} + +} + +// vim: ts=4 sw=4 et diff --git a/WebCore/platform/qt/FontPlatformData.h b/WebCore/platform/qt/FontPlatformData.h new file mode 100644 index 000000000000..ad1cddf5f1a5 --- /dev/null +++ b/WebCore/platform/qt/FontPlatformData.h @@ -0,0 +1,69 @@ +/* + * This file is part of the internal font implementation. It should not be included by anyone other than + * FontMac.cpp, FontWin.cpp and Font.cpp. + * + * Copyright (C) 2006 Apple Computer, Inc. + * Copyright (C) 2006 Zack Rusin + * Copyright (C) 2006 Dirk Mueller + * Copyright (C) 2006 Nikolas Zimmermann + * + * All rights reserved. + * + * 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. + * + */ + +#ifndef FontPlatformData_H +#define FontPlatformData_H + +#include "GlyphBuffer.h" +#include "FontDescription.h" + +#include +#include + +namespace WebCore { + +class FontPlatformData { +public: + FontPlatformData(const FontPlatformData& other); + FontPlatformData& operator=(const FontPlatformData& other); + + class Deleted { }; + FontPlatformData(Deleted); + + FontPlatformData(); + FontPlatformData(const FontDescription&, const AtomicString& family); + ~FontPlatformData(); + + bool isFixedPitch(); + + void setFont(const QFont&); + QFont font() const; + + unsigned hash() const; + + bool operator==(const FontPlatformData& other) const; + +private: + QFont m_font; +}; + +} + +#endif + +// vim: ts=4 sw=4 et diff --git a/WebCore/platform/qt/FontPlatformDataQt.cpp b/WebCore/platform/qt/FontPlatformDataQt.cpp new file mode 100644 index 000000000000..5b6e6d8a0c92 --- /dev/null +++ b/WebCore/platform/qt/FontPlatformDataQt.cpp @@ -0,0 +1,102 @@ +/* + * This file is part of the internal font implementation. It should not be included by anyone other than + * FontMac.cpp, FontWin.cpp and Font.cpp. + * + * Copyright (C) 2006 Apple Computer, Inc. + * Copyright (C) 2006 George Staikos + * Copyright (C) 2006 Dirk Mueller + * Copyright (C) 2006 Zack Rusin + * Copyright (C) 2006 Simon Hausmann + * Copyright (C) 2006 Nikolas Zimmermann + * + * All rights reserved. + * + * 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. + * + */ + +#include "config.h" +#include "FontPlatformData.h" + +#include "DeprecatedString.h" +#include "FontDescription.h" + +#include +#include + +namespace WebCore { + +FontPlatformData::FontPlatformData() +{ +} + +FontPlatformData::FontPlatformData(Deleted) +{ +} + +FontPlatformData::FontPlatformData(const FontDescription& fontDescription, const AtomicString& familyName) +{ + QFont font("Times New Roman", 12); + font.setFamily(familyName.domString()); + font.setPixelSize(fontDescription.computedSize()); + font.setItalic(fontDescription.italic()); + font.setWeight(fontDescription.weight()); + setFont(font); +} + +FontPlatformData::FontPlatformData(const FontPlatformData& other) + : m_font(other.m_font) +{ +} + +FontPlatformData& FontPlatformData::operator=(const FontPlatformData& other) +{ + m_font = other.m_font; + return *this; +} + +FontPlatformData::~FontPlatformData() +{ +} + +bool FontPlatformData::isFixedPitch() +{ + return QFontInfo(m_font).fixedPitch(); +} + +void FontPlatformData::setFont(const QFont& other) +{ + m_font = other; +} + +QFont FontPlatformData::font() const +{ + return m_font; +} + +unsigned FontPlatformData::hash() const +{ + return qHash(&m_font); +} + +bool FontPlatformData::operator==(const FontPlatformData& other) const +{ + return (other.m_font == m_font); +} + +} + +// vim: ts=4 sw=4 et diff --git a/WebCore/platform/qt/FontQt.cpp b/WebCore/platform/qt/FontQt.cpp new file mode 100644 index 000000000000..16098c17e7a8 --- /dev/null +++ b/WebCore/platform/qt/FontQt.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2006 Dirk Mueller + * Copyright (C) 2006 Zack Rusin + * Copyright (C) 2006 Simon Hausmann + * Copyright (C) 2006 Allan Sandfeld Jensen + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "Font.h" + +#include "FontData.h" +#include "GraphicsContext.h" + +#include +#include + +namespace WebCore { + +Font::operator QFont() const +{ + Q_ASSERT(primaryFont() != 0); + return primaryFont()->platformData().font(); +} + +void Font::drawGlyphs(GraphicsContext* graphicsContext, const FontData* font, const GlyphBuffer& glyphBuffer, + int from, int numGlyphs, const FloatPoint& point) const +{ + QPainter& p = *graphicsContext->platformContext(); + + Color color = graphicsContext->pen().color(); + p.setPen(QColor(color.red(), color.green(), color.blue())); + p.setFont(font->platformData().font()); + + QChar* buffer = reinterpret_cast(glyphBuffer.glyphs(from)); + QString str = QString::fromRawData(buffer, numGlyphs); + + p.drawText(QPointF(point.x(),point.y()), str); +} + +void Font::drawComplexText(GraphicsContext* ctx, const TextRun& run, const TextStyle&, const FloatPoint& point) const +{ + // ### style, run.from()/length() cut-off + ctx->platformContext()->drawText(point.x(), + point.y(), + QString::fromRawData(reinterpret_cast(run.characters() + run.from()), run.length())); +} + +float Font::floatWidthForComplexText(const TextRun& run, const TextStyle&) const +{ + // ### style + QFontMetricsF metrics(primaryFont()->m_font.font()); + return metrics.width(QString::fromRawData(reinterpret_cast(run.characters() + run.from()), run.length())); +} + +} + +// vim: ts=4 sw=4 et diff --git a/WebCore/platform/qt/GlyphMapQt.cpp b/WebCore/platform/qt/GlyphMapQt.cpp new file mode 100644 index 000000000000..ad22ab3e1739 --- /dev/null +++ b/WebCore/platform/qt/GlyphMapQt.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2006 George Staikos + * Copyright (C) 2006 Dirk Mueller + * Copyright (C) 2006 Zack Rusin + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "GlyphMap.h" + +#include "FontData.h" + +namespace WebCore { + +bool GlyphMap::fillPage(GlyphPage* page, UChar* buffer, unsigned bufferLength, const FontData* fontData) +{ + for (unsigned i = 0; i < bufferLength; i++) { + page->setGlyphDataForIndex(i, buffer[i], fontData); + } + + return true; +} + +} + +// vim: ts=4 sw=4 et -- 2.36.0