2 * Copyright (C) 2003 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #import "KWQExceptions.h"
30 #import "KWQFoundationExtras.h"
31 #import "WebCoreTextRendererFactory.h"
36 , _isPrinterFont(false)
46 QFont::QFont(const QFont &other)
47 : _family(other._family)
48 , _trait(other._trait)
50 , _isPrinterFont(other._isPrinterFont)
51 , _NSFont(KWQRetain(other._NSFont))
55 QFont &QFont::operator=(const QFont &other)
57 _family = other._family;
58 _trait = other._trait;
60 _isPrinterFont = other._isPrinterFont;
61 KWQRetain(other._NSFont);
63 _NSFont = other._NSFont;
67 QString QFont::family() const
69 return _family.family().string();
72 void QFont::setFamily(const QString &qfamilyName)
74 _family.setFamily(qfamilyName);
79 void QFont::setFirstFamily(const KWQFontFamily& family)
86 void QFont::setPixelSize(float s)
95 void QFont::setWeight(int weight)
98 if (!(_trait & NSBoldFontMask)){
102 _trait |= NSBoldFontMask;
103 } else if (weight == Normal) {
104 if ((_trait & NSBoldFontMask)){
108 _trait &= ~NSBoldFontMask;
112 void QFont::setPrinterFont(bool isPrinterFont)
114 _isPrinterFont = isPrinterFont;
117 int QFont::weight() const
119 return bold() ? Bold : Normal;
122 void QFont::setItalic(bool flag)
125 if (!(_trait & NSItalicFontMask)){
129 _trait |= NSItalicFontMask;
131 if ((_trait & NSItalicFontMask)){
135 _trait &= ~NSItalicFontMask;
139 bool QFont::italic() const
141 return _trait & NSItalicFontMask;
144 bool QFont::bold() const
146 return _trait & NSBoldFontMask;
149 bool QFont::isFixedPitch() const
151 // Special case Osaka-Mono. Do it here rather than in WebKit
152 // for performance reaason. See <rdar://problem/3999467> for
154 if (family() == "Osaka-Mono")
157 KWQ_BLOCK_EXCEPTIONS;
158 return [[WebCoreTextRendererFactory sharedFactory] isFontFixedPitch: getNSFont()];
159 KWQ_UNBLOCK_EXCEPTIONS;
164 bool QFont::operator==(const QFont &compareFont) const
166 return _family == compareFont._family
167 && _trait == compareFont._trait
168 && _size == compareFont._size
169 && _isPrinterFont == compareFont._isPrinterFont;
172 NSFont *QFont::getNSFont() const
175 CREATE_FAMILY_ARRAY(*this, families);
176 KWQ_BLOCK_EXCEPTIONS;
177 _NSFont = KWQRetain([[WebCoreTextRendererFactory sharedFactory]
178 fontWithFamilies:families
181 KWQ_UNBLOCK_EXCEPTIONS;