Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(748)

Side by Side Diff: Source/core/css/resolver/FontBuilder.cpp

Issue 943463002: Initial implementation of font-size-adjust (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 set(PropertySetFlag::Weight); 116 set(PropertySetFlag::Weight);
117 117
118 m_fontDescription.setWeight(fontWeight); 118 m_fontDescription.setWeight(fontWeight);
119 } 119 }
120 120
121 void FontBuilder::setSize(const FontDescription::Size& size) 121 void FontBuilder::setSize(const FontDescription::Size& size)
122 { 122 {
123 setSize(m_fontDescription, size); 123 setSize(m_fontDescription, size);
124 } 124 }
125 125
126 void FontBuilder::setSizeAdjust(float aspectValue)
127 {
128 set(PropertySetFlag::SizeAdjust);
129
130 m_fontDescription.setSizeAdjust(aspectValue);
131 }
132
126 void FontBuilder::setStretch(FontStretch fontStretch) 133 void FontBuilder::setStretch(FontStretch fontStretch)
127 { 134 {
128 set(PropertySetFlag::Stretch); 135 set(PropertySetFlag::Stretch);
129 136
130 m_fontDescription.setStretch(fontStretch); 137 m_fontDescription.setStretch(fontStretch);
131 } 138 }
132 139
133 void FontBuilder::setScript(const String& locale) 140 void FontBuilder::setScript(const String& locale)
134 { 141 {
135 set(PropertySetFlag::Script); 142 set(PropertySetFlag::Script);
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 float specifiedSize = fontDescription.specifiedSize(); 319 float specifiedSize = fontDescription.specifiedSize();
313 320
314 if (!specifiedSize && fontDescription.keywordSize()) 321 if (!specifiedSize && fontDescription.keywordSize())
315 specifiedSize = FontSize::fontSizeForKeyword(&m_document, fontDescriptio n.keywordSize(), fontDescription.fixedPitchFontType()); 322 specifiedSize = FontSize::fontSizeForKeyword(&m_document, fontDescriptio n.keywordSize(), fontDescription.fixedPitchFontType());
316 323
317 fontDescription.setSpecifiedSize(specifiedSize); 324 fontDescription.setSpecifiedSize(specifiedSize);
318 325
319 checkForGenericFamilyChange(style.fontDescription(), fontDescription); 326 checkForGenericFamilyChange(style.fontDescription(), fontDescription);
320 } 327 }
321 328
329 void FontBuilder::updateAdjustedSize(FontDescription& fontDescription, const Lay outStyle& style)
330 {
331 const float sizeAdjust = fontDescription.sizeAdjust();
332 const float specifiedSize = fontDescription.specifiedSize();
333 if (!sizeAdjust || !specifiedSize)
334 return;
335
336 // We need to create a temporal Font to get xHeight of a primary font.
337 Font font(fontDescription);
338 font.update(nullptr);
339 if (!font.fontMetrics().hasXHeight())
340 return;
341
342 const float aspectValue = font.fontMetrics().xHeight() / specifiedSize;
343 float adjustedSize = (sizeAdjust / aspectValue) * specifiedSize;
344 adjustedSize = getComputedSizeFromSpecifiedSize(fontDescription, style.effec tiveZoom(), adjustedSize);
345
346 float multiplier = style.textAutosizingMultiplier();
347 if (multiplier > 1)
348 adjustedSize = TextAutosizer::computeAutosizedFontSize(adjustedSize, mul tiplier);
349 fontDescription.setAdjustedSize(adjustedSize);
350 }
351
322 void FontBuilder::updateComputedSize(FontDescription& fontDescription, const Lay outStyle& style) 352 void FontBuilder::updateComputedSize(FontDescription& fontDescription, const Lay outStyle& style)
323 { 353 {
324 float computedSize = getComputedSizeFromSpecifiedSize(fontDescription, style .effectiveZoom(), fontDescription.specifiedSize()); 354 float computedSize = getComputedSizeFromSpecifiedSize(fontDescription, style .effectiveZoom(), fontDescription.specifiedSize());
325 float multiplier = style.textAutosizingMultiplier(); 355 float multiplier = style.textAutosizingMultiplier();
326 if (multiplier > 1) 356 if (multiplier > 1)
327 computedSize = TextAutosizer::computeAutosizedFontSize(computedSize, mul tiplier); 357 computedSize = TextAutosizer::computeAutosizedFontSize(computedSize, mul tiplier);
328 fontDescription.setComputedSize(computedSize); 358 fontDescription.setComputedSize(computedSize);
329 } 359 }
330 360
331 void FontBuilder::createFont(PassRefPtrWillBeRawPtr<FontSelector> fontSelector, LayoutStyle& style) 361 void FontBuilder::createFont(PassRefPtrWillBeRawPtr<FontSelector> fontSelector, LayoutStyle& style)
332 { 362 {
333 if (!m_flags) 363 if (!m_flags)
334 return; 364 return;
335 365
336 FontDescription description = style.fontDescription(); 366 FontDescription description = style.fontDescription();
337 367
338 if (isSet(PropertySetFlag::Family)) { 368 if (isSet(PropertySetFlag::Family)) {
339 description.setGenericFamily(m_fontDescription.genericFamily()); 369 description.setGenericFamily(m_fontDescription.genericFamily());
340 description.setFamily(m_fontDescription.family()); 370 description.setFamily(m_fontDescription.family());
341 } 371 }
342 if (isSet(PropertySetFlag::Size)) { 372 if (isSet(PropertySetFlag::Size)) {
343 description.setKeywordSize(m_fontDescription.keywordSize()); 373 description.setKeywordSize(m_fontDescription.keywordSize());
344 description.setSpecifiedSize(m_fontDescription.specifiedSize()); 374 description.setSpecifiedSize(m_fontDescription.specifiedSize());
345 description.setIsAbsoluteSize(m_fontDescription.isAbsoluteSize()); 375 description.setIsAbsoluteSize(m_fontDescription.isAbsoluteSize());
346 } 376 }
377 if (isSet(PropertySetFlag::SizeAdjust))
378 description.setSizeAdjust(m_fontDescription.sizeAdjust());
347 if (isSet(PropertySetFlag::Weight)) 379 if (isSet(PropertySetFlag::Weight))
348 description.setWeight(m_fontDescription.weight()); 380 description.setWeight(m_fontDescription.weight());
349 if (isSet(PropertySetFlag::Stretch)) 381 if (isSet(PropertySetFlag::Stretch))
350 description.setStretch(m_fontDescription.stretch()); 382 description.setStretch(m_fontDescription.stretch());
351 if (isSet(PropertySetFlag::FeatureSettings)) 383 if (isSet(PropertySetFlag::FeatureSettings))
352 description.setFeatureSettings(m_fontDescription.featureSettings()); 384 description.setFeatureSettings(m_fontDescription.featureSettings());
353 if (isSet(PropertySetFlag::Script)) { 385 if (isSet(PropertySetFlag::Script)) {
354 description.setLocale(m_fontDescription.locale()); 386 description.setLocale(m_fontDescription.locale());
355 description.setScript(m_fontDescription.script()); 387 description.setScript(m_fontDescription.script());
356 } 388 }
357 if (isSet(PropertySetFlag::Style)) 389 if (isSet(PropertySetFlag::Style))
358 description.setStyle(m_fontDescription.style()); 390 description.setStyle(m_fontDescription.style());
359 if (isSet(PropertySetFlag::Variant)) 391 if (isSet(PropertySetFlag::Variant))
360 description.setVariant(m_fontDescription.variant()); 392 description.setVariant(m_fontDescription.variant());
361 if (isSet(PropertySetFlag::VariantLigatures)) 393 if (isSet(PropertySetFlag::VariantLigatures))
362 description.setVariantLigatures(m_fontDescription.variantLigatures()); 394 description.setVariantLigatures(m_fontDescription.variantLigatures());
363 if (isSet(PropertySetFlag::TextRendering)) 395 if (isSet(PropertySetFlag::TextRendering))
364 description.setTextRendering(m_fontDescription.textRendering()); 396 description.setTextRendering(m_fontDescription.textRendering());
365 if (isSet(PropertySetFlag::Kerning)) 397 if (isSet(PropertySetFlag::Kerning))
366 description.setKerning(m_fontDescription.kerning()); 398 description.setKerning(m_fontDescription.kerning());
367 if (isSet(PropertySetFlag::FontSmoothing)) 399 if (isSet(PropertySetFlag::FontSmoothing))
368 description.setFontSmoothing(m_fontDescription.fontSmoothing()); 400 description.setFontSmoothing(m_fontDescription.fontSmoothing());
369 if (isSet(PropertySetFlag::TextOrientation) || isSet(PropertySetFlag::Writin gMode)) 401 if (isSet(PropertySetFlag::TextOrientation) || isSet(PropertySetFlag::Writin gMode))
370 updateOrientation(description, style); 402 updateOrientation(description, style);
371 403
372 updateSpecifiedSize(description, style); 404 updateSpecifiedSize(description, style);
373 updateComputedSize(description, style); 405 updateComputedSize(description, style);
406 updateAdjustedSize(description, style);
374 407
375 style.setFontDescription(description); 408 style.setFontDescription(description);
376 style.font().update(fontSelector); 409 style.font().update(fontSelector);
377 m_flags = 0; 410 m_flags = 0;
378 } 411 }
379 412
380 void FontBuilder::createFontForDocument(PassRefPtrWillBeRawPtr<FontSelector> fon tSelector, LayoutStyle& documentStyle) 413 void FontBuilder::createFontForDocument(PassRefPtrWillBeRawPtr<FontSelector> fon tSelector, LayoutStyle& documentStyle)
381 { 414 {
382 FontDescription fontDescription = FontDescription(); 415 FontDescription fontDescription = FontDescription();
383 fontDescription.setLocale(documentStyle.locale()); 416 fontDescription.setLocale(documentStyle.locale());
384 fontDescription.setScript(localeToScriptCodeForFontSelection(documentStyle.l ocale())); 417 fontDescription.setScript(localeToScriptCodeForFontSelection(documentStyle.l ocale()));
385 418
386 setFamilyDescription(fontDescription, FontBuilder::initialFamilyDescription( )); 419 setFamilyDescription(fontDescription, FontBuilder::initialFamilyDescription( ));
387 setSize(fontDescription, FontDescription::Size(FontSize::initialKeywordSize( ), 0.0f, false)); 420 setSize(fontDescription, FontDescription::Size(FontSize::initialKeywordSize( ), 0.0f, false));
388 updateSpecifiedSize(fontDescription, documentStyle); 421 updateSpecifiedSize(fontDescription, documentStyle);
389 updateComputedSize(fontDescription, documentStyle); 422 updateComputedSize(fontDescription, documentStyle);
390 423
391 FontOrientation fontOrientation; 424 FontOrientation fontOrientation;
392 NonCJKGlyphOrientation glyphOrientation; 425 NonCJKGlyphOrientation glyphOrientation;
393 getFontAndGlyphOrientation(documentStyle, fontOrientation, glyphOrientation) ; 426 getFontAndGlyphOrientation(documentStyle, fontOrientation, glyphOrientation) ;
394 fontDescription.setOrientation(fontOrientation); 427 fontDescription.setOrientation(fontOrientation);
395 fontDescription.setNonCJKGlyphOrientation(glyphOrientation); 428 fontDescription.setNonCJKGlyphOrientation(glyphOrientation);
396 documentStyle.setFontDescription(fontDescription); 429 documentStyle.setFontDescription(fontDescription);
397 documentStyle.font().update(fontSelector); 430 documentStyle.font().update(fontSelector);
398 } 431 }
399 432
400 } 433 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698