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

Side by Side Diff: src/ports/SkFontHost_FreeType.cpp

Issue 1709403003: Check scalar to fixed conversions with axes. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkAdvancedTypefaceMetrics.h" 8 #include "SkAdvancedTypefaceMetrics.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 1732 matching lines...) Expand 10 before | Expand all | Expand 10 after
1743 } 1743 }
1744 1744
1745 /*static*/ void SkTypeface_FreeType::Scanner::computeAxisValues( 1745 /*static*/ void SkTypeface_FreeType::Scanner::computeAxisValues(
1746 AxisDefinitions axisDefinitions, 1746 AxisDefinitions axisDefinitions,
1747 const SkFontMgr::FontParameters::Axis* requestedAxes, int requestedAxisCount , 1747 const SkFontMgr::FontParameters::Axis* requestedAxes, int requestedAxisCount ,
1748 SkFixed* axisValues, 1748 SkFixed* axisValues,
1749 const SkString& name) 1749 const SkString& name)
1750 { 1750 {
1751 for (int i = 0; i < axisDefinitions.count(); ++i) { 1751 for (int i = 0; i < axisDefinitions.count(); ++i) {
1752 const Scanner::AxisDefinition& axisDefinition = axisDefinitions[i]; 1752 const Scanner::AxisDefinition& axisDefinition = axisDefinitions[i];
1753 const SkScalar axisMin = SkFixedToScalar(axisDefinition.fMinimum);
1754 const SkScalar axisMax = SkFixedToScalar(axisDefinition.fMaximum);
1753 axisValues[i] = axisDefinition.fDefault; 1755 axisValues[i] = axisDefinition.fDefault;
1754 for (int j = 0; j < requestedAxisCount; ++j) { 1756 for (int j = 0; j < requestedAxisCount; ++j) {
1755 const SkFontMgr::FontParameters::Axis& axisSpecified = requestedAxes [j]; 1757 const SkFontMgr::FontParameters::Axis& axisSpecified = requestedAxes [j];
1756 if (axisDefinition.fTag == axisSpecified.fTag) { 1758 if (axisDefinition.fTag == axisSpecified.fTag) {
1757 SkFixed axisValue = SkScalarToFixed(axisSpecified.fStyleValue); 1759 const SkScalar axisValue = SkTPin(axisSpecified.fStyleValue, axi sMin, axisMax);
1758 axisValues[i] = SkTPin(axisValue, axisDefinition.fMinimum, axisD efinition.fMaximum); 1760 if (axisSpecified.fStyleValue != axisValue) {
1759 if (axisValues[i] != axisValue) {
1760 SkDEBUGF(("Requested font axis value out of range: " 1761 SkDEBUGF(("Requested font axis value out of range: "
1761 "%s '%c%c%c%c' %f; pinned to %f.\n", 1762 "%s '%c%c%c%c' %f; pinned to %f.\n",
1762 name.c_str(), 1763 name.c_str(),
1763 (axisDefinition.fTag >> 24) & 0xFF, 1764 (axisDefinition.fTag >> 24) & 0xFF,
1764 (axisDefinition.fTag >> 16) & 0xFF, 1765 (axisDefinition.fTag >> 16) & 0xFF,
1765 (axisDefinition.fTag >> 8) & 0xFF, 1766 (axisDefinition.fTag >> 8) & 0xFF,
1766 (axisDefinition.fTag ) & 0xFF, 1767 (axisDefinition.fTag ) & 0xFF,
1767 SkScalarToDouble(axisSpecified.fStyleValue), 1768 SkScalarToDouble(axisSpecified.fStyleValue),
1768 SkFixedToDouble(axisValues[i]))); 1769 SkScalarToDouble(axisValue)));
1769 } 1770 }
1771 axisValues[i] = SkScalarToFixed(axisValue);
1770 break; 1772 break;
1771 } 1773 }
1772 } 1774 }
1773 // TODO: warn on defaulted axis? 1775 // TODO: warn on defaulted axis?
1774 } 1776 }
1775 1777
1776 SkDEBUGCODE( 1778 SkDEBUGCODE(
1777 // Check for axis specified, but not matched in font. 1779 // Check for axis specified, but not matched in font.
1778 for (int i = 0; i < requestedAxisCount; ++i) { 1780 for (int i = 0; i < requestedAxisCount; ++i) {
1779 SkFourByteTag skTag = requestedAxes[i].fTag; 1781 SkFourByteTag skTag = requestedAxes[i].fTag;
1780 bool found = false; 1782 bool found = false;
1781 for (int j = 0; j < axisDefinitions.count(); ++j) { 1783 for (int j = 0; j < axisDefinitions.count(); ++j) {
1782 if (skTag == axisDefinitions[j].fTag) { 1784 if (skTag == axisDefinitions[j].fTag) {
1783 found = true; 1785 found = true;
1784 break; 1786 break;
1785 } 1787 }
1786 } 1788 }
1787 if (!found) { 1789 if (!found) {
1788 SkDEBUGF(("Requested font axis not found: %s '%c%c%c%c'\n", 1790 SkDEBUGF(("Requested font axis not found: %s '%c%c%c%c'\n",
1789 name.c_str(), 1791 name.c_str(),
1790 (skTag >> 24) & 0xFF, 1792 (skTag >> 24) & 0xFF,
1791 (skTag >> 16) & 0xFF, 1793 (skTag >> 16) & 0xFF,
1792 (skTag >> 8) & 0xFF, 1794 (skTag >> 8) & 0xFF,
1793 (skTag) & 0xFF)); 1795 (skTag) & 0xFF));
1794 } 1796 }
1795 } 1797 }
1796 ) 1798 )
1797 } 1799 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698