OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
All rights reserved. | 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
All rights reserved. |
4 * Copyright (C) 2013 Google Inc. All rights reserved. | 4 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 5 * Copyright (C) 2015 Collabora Ltd. All rights reserved. |
5 * | 6 * |
6 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
10 * | 11 * |
11 * This library is distributed in the hope that it will be useful, | 12 * This library is distributed in the hope that it will be useful, |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 * Library General Public License for more details. | 15 * Library General Public License for more details. |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 set(PropertySetFlag::Weight); | 117 set(PropertySetFlag::Weight); |
117 | 118 |
118 m_fontDescription.setWeight(fontWeight); | 119 m_fontDescription.setWeight(fontWeight); |
119 } | 120 } |
120 | 121 |
121 void FontBuilder::setSize(const FontDescription::Size& size) | 122 void FontBuilder::setSize(const FontDescription::Size& size) |
122 { | 123 { |
123 setSize(m_fontDescription, size); | 124 setSize(m_fontDescription, size); |
124 } | 125 } |
125 | 126 |
| 127 void FontBuilder::setSizeAdjust(float aspectValue) |
| 128 { |
| 129 set(PropertySetFlag::SizeAdjust); |
| 130 |
| 131 m_fontDescription.setSizeAdjust(aspectValue); |
| 132 } |
| 133 |
126 void FontBuilder::setStretch(FontStretch fontStretch) | 134 void FontBuilder::setStretch(FontStretch fontStretch) |
127 { | 135 { |
128 set(PropertySetFlag::Stretch); | 136 set(PropertySetFlag::Stretch); |
129 | 137 |
130 m_fontDescription.setStretch(fontStretch); | 138 m_fontDescription.setStretch(fontStretch); |
131 } | 139 } |
132 | 140 |
133 void FontBuilder::setScript(const AtomicString& locale) | 141 void FontBuilder::setScript(const AtomicString& locale) |
134 { | 142 { |
135 set(PropertySetFlag::Script); | 143 set(PropertySetFlag::Script); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 float specifiedSize = fontDescription.specifiedSize(); | 320 float specifiedSize = fontDescription.specifiedSize(); |
313 | 321 |
314 if (!specifiedSize && fontDescription.keywordSize()) | 322 if (!specifiedSize && fontDescription.keywordSize()) |
315 specifiedSize = FontSize::fontSizeForKeyword(&m_document, fontDescriptio
n.keywordSize(), fontDescription.fixedPitchFontType()); | 323 specifiedSize = FontSize::fontSizeForKeyword(&m_document, fontDescriptio
n.keywordSize(), fontDescription.fixedPitchFontType()); |
316 | 324 |
317 fontDescription.setSpecifiedSize(specifiedSize); | 325 fontDescription.setSpecifiedSize(specifiedSize); |
318 | 326 |
319 checkForGenericFamilyChange(style.fontDescription(), fontDescription); | 327 checkForGenericFamilyChange(style.fontDescription(), fontDescription); |
320 } | 328 } |
321 | 329 |
| 330 void FontBuilder::updateAdjustedSize(FontDescription& fontDescription, const Lay
outStyle& style, FontSelector* fontSelector) |
| 331 { |
| 332 const float sizeAdjust = fontDescription.sizeAdjust(); |
| 333 const float specifiedSize = fontDescription.specifiedSize(); |
| 334 if (!sizeAdjust || !specifiedSize) |
| 335 return; |
| 336 |
| 337 // We need to create a temporal Font to get xHeight of a primary font. |
| 338 Font font(fontDescription); |
| 339 font.update(fontSelector); |
| 340 if (!font.fontMetrics().hasXHeight()) |
| 341 return; |
| 342 |
| 343 float aspectValue = font.fontMetrics().xHeight() / specifiedSize; |
| 344 float adjustedSize = (sizeAdjust / aspectValue) * specifiedSize; |
| 345 adjustedSize = getComputedSizeFromSpecifiedSize(fontDescription, style.effec
tiveZoom(), adjustedSize); |
| 346 |
| 347 float multiplier = style.textAutosizingMultiplier(); |
| 348 if (multiplier > 1) |
| 349 adjustedSize = TextAutosizer::computeAutosizedFontSize(adjustedSize, mul
tiplier); |
| 350 fontDescription.setAdjustedSize(adjustedSize); |
| 351 } |
| 352 |
322 void FontBuilder::updateComputedSize(FontDescription& fontDescription, const Lay
outStyle& style) | 353 void FontBuilder::updateComputedSize(FontDescription& fontDescription, const Lay
outStyle& style) |
323 { | 354 { |
324 float computedSize = getComputedSizeFromSpecifiedSize(fontDescription, style
.effectiveZoom(), fontDescription.specifiedSize()); | 355 float computedSize = getComputedSizeFromSpecifiedSize(fontDescription, style
.effectiveZoom(), fontDescription.specifiedSize()); |
325 float multiplier = style.textAutosizingMultiplier(); | 356 float multiplier = style.textAutosizingMultiplier(); |
326 if (multiplier > 1) | 357 if (multiplier > 1) |
327 computedSize = TextAutosizer::computeAutosizedFontSize(computedSize, mul
tiplier); | 358 computedSize = TextAutosizer::computeAutosizedFontSize(computedSize, mul
tiplier); |
328 fontDescription.setComputedSize(computedSize); | 359 fontDescription.setComputedSize(computedSize); |
329 } | 360 } |
330 | 361 |
331 void FontBuilder::createFont(PassRefPtrWillBeRawPtr<FontSelector> fontSelector,
LayoutStyle& style) | 362 void FontBuilder::createFont(PassRefPtrWillBeRawPtr<FontSelector> fontSelector,
LayoutStyle& style) |
332 { | 363 { |
333 if (!m_flags) | 364 if (!m_flags) |
334 return; | 365 return; |
335 | 366 |
336 FontDescription description = style.fontDescription(); | 367 FontDescription description = style.fontDescription(); |
337 | 368 |
338 if (isSet(PropertySetFlag::Family)) { | 369 if (isSet(PropertySetFlag::Family)) { |
339 description.setGenericFamily(m_fontDescription.genericFamily()); | 370 description.setGenericFamily(m_fontDescription.genericFamily()); |
340 description.setFamily(m_fontDescription.family()); | 371 description.setFamily(m_fontDescription.family()); |
341 } | 372 } |
342 if (isSet(PropertySetFlag::Size)) { | 373 if (isSet(PropertySetFlag::Size)) { |
343 description.setKeywordSize(m_fontDescription.keywordSize()); | 374 description.setKeywordSize(m_fontDescription.keywordSize()); |
344 description.setSpecifiedSize(m_fontDescription.specifiedSize()); | 375 description.setSpecifiedSize(m_fontDescription.specifiedSize()); |
345 description.setIsAbsoluteSize(m_fontDescription.isAbsoluteSize()); | 376 description.setIsAbsoluteSize(m_fontDescription.isAbsoluteSize()); |
346 } | 377 } |
| 378 if (isSet(PropertySetFlag::SizeAdjust)) |
| 379 description.setSizeAdjust(m_fontDescription.sizeAdjust()); |
347 if (isSet(PropertySetFlag::Weight)) | 380 if (isSet(PropertySetFlag::Weight)) |
348 description.setWeight(m_fontDescription.weight()); | 381 description.setWeight(m_fontDescription.weight()); |
349 if (isSet(PropertySetFlag::Stretch)) | 382 if (isSet(PropertySetFlag::Stretch)) |
350 description.setStretch(m_fontDescription.stretch()); | 383 description.setStretch(m_fontDescription.stretch()); |
351 if (isSet(PropertySetFlag::FeatureSettings)) | 384 if (isSet(PropertySetFlag::FeatureSettings)) |
352 description.setFeatureSettings(m_fontDescription.featureSettings()); | 385 description.setFeatureSettings(m_fontDescription.featureSettings()); |
353 if (isSet(PropertySetFlag::Script)) { | 386 if (isSet(PropertySetFlag::Script)) { |
354 description.setLocale(m_fontDescription.locale()); | 387 description.setLocale(m_fontDescription.locale()); |
355 description.setScript(m_fontDescription.script()); | 388 description.setScript(m_fontDescription.script()); |
356 } | 389 } |
357 if (isSet(PropertySetFlag::Style)) | 390 if (isSet(PropertySetFlag::Style)) |
358 description.setStyle(m_fontDescription.style()); | 391 description.setStyle(m_fontDescription.style()); |
359 if (isSet(PropertySetFlag::Variant)) | 392 if (isSet(PropertySetFlag::Variant)) |
360 description.setVariant(m_fontDescription.variant()); | 393 description.setVariant(m_fontDescription.variant()); |
361 if (isSet(PropertySetFlag::VariantLigatures)) | 394 if (isSet(PropertySetFlag::VariantLigatures)) |
362 description.setVariantLigatures(m_fontDescription.variantLigatures()); | 395 description.setVariantLigatures(m_fontDescription.variantLigatures()); |
363 if (isSet(PropertySetFlag::TextRendering)) | 396 if (isSet(PropertySetFlag::TextRendering)) |
364 description.setTextRendering(m_fontDescription.textRendering()); | 397 description.setTextRendering(m_fontDescription.textRendering()); |
365 if (isSet(PropertySetFlag::Kerning)) | 398 if (isSet(PropertySetFlag::Kerning)) |
366 description.setKerning(m_fontDescription.kerning()); | 399 description.setKerning(m_fontDescription.kerning()); |
367 if (isSet(PropertySetFlag::FontSmoothing)) | 400 if (isSet(PropertySetFlag::FontSmoothing)) |
368 description.setFontSmoothing(m_fontDescription.fontSmoothing()); | 401 description.setFontSmoothing(m_fontDescription.fontSmoothing()); |
369 if (isSet(PropertySetFlag::TextOrientation) || isSet(PropertySetFlag::Writin
gMode)) | 402 if (isSet(PropertySetFlag::TextOrientation) || isSet(PropertySetFlag::Writin
gMode)) |
370 updateOrientation(description, style); | 403 updateOrientation(description, style); |
371 | 404 |
372 updateSpecifiedSize(description, style); | 405 updateSpecifiedSize(description, style); |
373 updateComputedSize(description, style); | 406 updateComputedSize(description, style); |
| 407 updateAdjustedSize(description, style, fontSelector.get()); |
374 | 408 |
375 style.setFontDescription(description); | 409 style.setFontDescription(description); |
376 style.font().update(fontSelector); | 410 style.font().update(fontSelector); |
377 m_flags = 0; | 411 m_flags = 0; |
378 } | 412 } |
379 | 413 |
380 void FontBuilder::createFontForDocument(PassRefPtrWillBeRawPtr<FontSelector> fon
tSelector, LayoutStyle& documentStyle) | 414 void FontBuilder::createFontForDocument(PassRefPtrWillBeRawPtr<FontSelector> fon
tSelector, LayoutStyle& documentStyle) |
381 { | 415 { |
382 FontDescription fontDescription = FontDescription(); | 416 FontDescription fontDescription = FontDescription(); |
383 fontDescription.setLocale(documentStyle.locale()); | 417 fontDescription.setLocale(documentStyle.locale()); |
384 fontDescription.setScript(localeToScriptCodeForFontSelection(documentStyle.l
ocale())); | 418 fontDescription.setScript(localeToScriptCodeForFontSelection(documentStyle.l
ocale())); |
385 | 419 |
386 setFamilyDescription(fontDescription, FontBuilder::initialFamilyDescription(
)); | 420 setFamilyDescription(fontDescription, FontBuilder::initialFamilyDescription(
)); |
387 setSize(fontDescription, FontDescription::Size(FontSize::initialKeywordSize(
), 0.0f, false)); | 421 setSize(fontDescription, FontDescription::Size(FontSize::initialKeywordSize(
), 0.0f, false)); |
388 updateSpecifiedSize(fontDescription, documentStyle); | 422 updateSpecifiedSize(fontDescription, documentStyle); |
389 updateComputedSize(fontDescription, documentStyle); | 423 updateComputedSize(fontDescription, documentStyle); |
390 | 424 |
391 FontOrientation fontOrientation; | 425 FontOrientation fontOrientation; |
392 NonCJKGlyphOrientation glyphOrientation; | 426 NonCJKGlyphOrientation glyphOrientation; |
393 getFontAndGlyphOrientation(documentStyle, fontOrientation, glyphOrientation)
; | 427 getFontAndGlyphOrientation(documentStyle, fontOrientation, glyphOrientation)
; |
394 fontDescription.setOrientation(fontOrientation); | 428 fontDescription.setOrientation(fontOrientation); |
395 fontDescription.setNonCJKGlyphOrientation(glyphOrientation); | 429 fontDescription.setNonCJKGlyphOrientation(glyphOrientation); |
396 documentStyle.setFontDescription(fontDescription); | 430 documentStyle.setFontDescription(fontDescription); |
397 documentStyle.font().update(fontSelector); | 431 documentStyle.font().update(fontSelector); |
398 } | 432 } |
399 | 433 |
400 } | 434 } |
OLD | NEW |