| Index: third_party/WebKit/Source/platform/fonts/opentype/OpenTypeOS2Table.cpp
|
| diff --git a/third_party/WebKit/Source/platform/fonts/opentype/OpenTypeOS2Table.cpp b/third_party/WebKit/Source/platform/fonts/opentype/OpenTypeOS2Table.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..6a9bcbd90ac42f4595cf615cd2b5dd164d6d55e3
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/platform/fonts/opentype/OpenTypeOS2Table.cpp
|
| @@ -0,0 +1,83 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "config.h"
|
| +#include "platform/fonts/opentype/OpenTypeOS2Table.h"
|
| +
|
| +#include "SkTypeface.h"
|
| +#include "platform/fonts/opentype/OpenTypeTypes.h"
|
| +
|
| +namespace blink {
|
| +namespace OpenType {
|
| +
|
| +#pragma pack(1)
|
| +
|
| +// https://www.microsoft.com/typography/otspec/os2.htm
|
| +
|
| +enum class FontSelectionFlag1 : uint8_t {
|
| + USE_TYPO_METRICS = 1 << 7,
|
| +};
|
| +
|
| +inline bool operator&(FontSelectionFlag1 lhs, FontSelectionFlag1 rhs)
|
| +{
|
| + return static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs);
|
| +}
|
| +
|
| +struct OS2TableV3 {
|
| + OpenType::UInt16 version;
|
| + OpenType::Int16 xAvgCharWidth;
|
| + OpenType::UInt16 usWeightClass;
|
| + OpenType::UInt16 usWidthClass;
|
| + OpenType::UInt16 fsType;
|
| + OpenType::Int16 ySubscriptXSize;
|
| + OpenType::Int16 ySubscriptYSize;
|
| + OpenType::Int16 ySubscriptXOffset;
|
| + OpenType::Int16 ySubscriptYOffset;
|
| + OpenType::Int16 ySuperscriptXSize;
|
| + OpenType::Int16 ySuperscriptYSize;
|
| + OpenType::Int16 ySuperscriptXOffset;
|
| + OpenType::Int16 ySuperscriptYOffset;
|
| + OpenType::Int16 yStrikeoutSize;
|
| + OpenType::Int16 yStrikeoutPosition;
|
| + OpenType::Int16 sFamilyClass;
|
| + uint8_t panose[10];
|
| + OpenType::UInt32 ulUnicodeRange[4];
|
| + int8_t achVendID[4];
|
| + uint8_t fsSelection0;
|
| + FontSelectionFlag1 fsSelection1;
|
| + OpenType::UInt16 usFirstCharIndex;
|
| + OpenType::UInt16 usLastCharIndex;
|
| + OpenType::Int16 sTypoAscender;
|
| + OpenType::Int16 sTypoDescender;
|
| + OpenType::Int16 sTypoLineGap;
|
| + OpenType::UInt16 usWinAscent;
|
| + OpenType::UInt16 usWinDescent;
|
| + OpenType::UInt32 ulCodePageRange[2];
|
| + OpenType::Int16 sxHeight;
|
| + OpenType::Int16 sCapHeight;
|
| + OpenType::UInt16 usDefaultChar;
|
| + OpenType::UInt16 usBreakChar;
|
| + OpenType::UInt16 usMaxContext;
|
| +
|
| + OS2Table() { }
|
| +};
|
| +
|
| +#pragma pack()
|
| +
|
| +} // namespace OpenType
|
| +
|
| +bool getAscentDescentFromOS2Table(SkTypeface* face, short& ascentInUnits, short& descentInUnits)
|
| +{
|
| + static const uint32_t os2Tag = SkSetFourByteTag('O', 'S', '/', '2');
|
| + OpenType::OS2TableV3 os2Table;
|
| + if (face->getTableData(os2Tag, 0, sizeof(os2Table), &os2Table) != sizeof(os2Table))
|
| + return false;
|
| + if (!(os2Table.fsSelection1 & OpenType::FontSelectionFlag1::USE_TYPO_METRICS))
|
| + return false;
|
| + ascentInUnits = os2Table.sTypoAscender;
|
| + descentInUnits = os2Table.sTypoDescender;
|
| + return true;
|
| +}
|
| +
|
| +} // namespace blink
|
|
|