gfx/skia/trunk/src/sfnt/SkOTTable_glyf.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/sfnt/SkOTTable_glyf.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,214 @@
     1.4 +/*
     1.5 + * Copyright 2012 Google Inc.
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +#ifndef SkOTTable_glyf_DEFINED
    1.12 +#define SkOTTable_glyf_DEFINED
    1.13 +
    1.14 +#include "SkEndian.h"
    1.15 +#include "SkOTTableTypes.h"
    1.16 +#include "SkOTTable_head.h"
    1.17 +#include "SkOTTable_loca.h"
    1.18 +#include "SkTypedEnum.h"
    1.19 +
    1.20 +#pragma pack(push, 1)
    1.21 +
    1.22 +struct SkOTTableGlyphData;
    1.23 +
    1.24 +extern uint8_t const * const SK_OT_GlyphData_NoOutline;
    1.25 +
    1.26 +struct SkOTTableGlyph {
    1.27 +    static const SK_OT_CHAR TAG0 = 'g';
    1.28 +    static const SK_OT_CHAR TAG1 = 'l';
    1.29 +    static const SK_OT_CHAR TAG2 = 'y';
    1.30 +    static const SK_OT_CHAR TAG3 = 'f';
    1.31 +    static const SK_OT_ULONG TAG = SkOTTableTAG<SkOTTableGlyph>::value;
    1.32 +
    1.33 +    class Iterator {
    1.34 +    public:
    1.35 +        Iterator(const SkOTTableGlyph& glyf,
    1.36 +                 const SkOTTableIndexToLocation& loca,
    1.37 +                 SkOTTableHead::IndexToLocFormat locaFormat)
    1.38 +        : fGlyf(glyf)
    1.39 +        , fLocaFormat(SkOTTableHead::IndexToLocFormat::ShortOffsets == locaFormat.value ? 0 : 1)
    1.40 +        , fCurrentGlyphOffset(0)
    1.41 +        { fLocaPtr.shortOffset = reinterpret_cast<const SK_OT_USHORT*>(&loca); }
    1.42 +
    1.43 +        void advance(uint16_t num) {
    1.44 +            fLocaPtr.shortOffset += num << fLocaFormat;
    1.45 +            fCurrentGlyphOffset = fLocaFormat ? SkEndian_SwapBE32(*fLocaPtr.longOffset)
    1.46 +                                              : uint32_t(SkEndian_SwapBE16(*fLocaPtr.shortOffset) << 1);
    1.47 +        }
    1.48 +        const SkOTTableGlyphData* next() {
    1.49 +            uint32_t previousGlyphOffset = fCurrentGlyphOffset;
    1.50 +            advance(1);
    1.51 +            if (previousGlyphOffset == fCurrentGlyphOffset) {
    1.52 +                return reinterpret_cast<const SkOTTableGlyphData*>(&SK_OT_GlyphData_NoOutline);
    1.53 +            } else {
    1.54 +                return reinterpret_cast<const SkOTTableGlyphData*>(
    1.55 +                    reinterpret_cast<const SK_OT_BYTE*>(&fGlyf) + previousGlyphOffset
    1.56 +                );
    1.57 +            }
    1.58 +        }
    1.59 +    private:
    1.60 +        const SkOTTableGlyph& fGlyf;
    1.61 +        uint16_t fLocaFormat; //0 or 1
    1.62 +        uint32_t fCurrentGlyphOffset;
    1.63 +        union LocaPtr {
    1.64 +            const SK_OT_USHORT* shortOffset;
    1.65 +            const SK_OT_ULONG* longOffset;
    1.66 +        } fLocaPtr;
    1.67 +    };
    1.68 +};
    1.69 +
    1.70 +struct SkOTTableGlyphData {
    1.71 +    SK_OT_SHORT numberOfContours; //== -1 Composite, > 0 Simple
    1.72 +    SK_OT_FWORD xMin;
    1.73 +    SK_OT_FWORD yMin;
    1.74 +    SK_OT_FWORD xMax;
    1.75 +    SK_OT_FWORD yMax;
    1.76 +
    1.77 +    struct Simple {
    1.78 +        SK_OT_USHORT endPtsOfContours[1/*numberOfContours*/];
    1.79 +
    1.80 +        struct Instructions {
    1.81 +            SK_OT_USHORT length;
    1.82 +            SK_OT_BYTE data[1/*length*/];
    1.83 +        };
    1.84 +
    1.85 +        union Flags {
    1.86 +            struct Field {
    1.87 +                SK_OT_BYTE_BITFIELD(
    1.88 +                    OnCurve,
    1.89 +                    xShortVector,
    1.90 +                    yShortVector,
    1.91 +                    Repeat,
    1.92 +                    xIsSame_xShortVectorPositive,
    1.93 +                    yIsSame_yShortVectorPositive,
    1.94 +                    Reserved6,
    1.95 +                    Reserved7)
    1.96 +            } field;
    1.97 +            struct Raw {
    1.98 +                static const SK_OT_USHORT OnCurveMask = SkTEndian_SwapBE16(1 << 0);
    1.99 +                static const SK_OT_USHORT xShortVectorMask = SkTEndian_SwapBE16(1 << 1);
   1.100 +                static const SK_OT_USHORT yShortVectorMask = SkTEndian_SwapBE16(1 << 2);
   1.101 +                static const SK_OT_USHORT RepeatMask = SkTEndian_SwapBE16(1 << 3);
   1.102 +                static const SK_OT_USHORT xIsSame_xShortVectorPositiveMask = SkTEndian_SwapBE16(1 << 4);
   1.103 +                static const SK_OT_USHORT yIsSame_yShortVectorPositiveMask = SkTEndian_SwapBE16(1 << 5);
   1.104 +                SK_OT_BYTE value;
   1.105 +            } raw;
   1.106 +        };
   1.107 +
   1.108 +        //xCoordinates
   1.109 +        //yCoordinates
   1.110 +    };
   1.111 +
   1.112 +    struct Composite {
   1.113 +        struct Component {
   1.114 +            union Flags {
   1.115 +                struct Field {
   1.116 +                    //8-15
   1.117 +                    SK_OT_BYTE_BITFIELD(
   1.118 +                        WE_HAVE_INSTRUCTIONS,
   1.119 +                        USE_MY_METRICS,
   1.120 +                        OVERLAP_COMPOUND,
   1.121 +                        SCALED_COMPONENT_OFFSET,
   1.122 +                        UNSCALED_COMPONENT_OFFSET,
   1.123 +                        Reserved13,
   1.124 +                        Reserved14,
   1.125 +                        Reserved15)
   1.126 +                    //0-7
   1.127 +                    SK_OT_BYTE_BITFIELD(
   1.128 +                        ARG_1_AND_2_ARE_WORDS,
   1.129 +                        ARGS_ARE_XY_VALUES,
   1.130 +                        ROUND_XY_TO_GRID,
   1.131 +                        WE_HAVE_A_SCALE,
   1.132 +                        RESERVED,
   1.133 +                        MORE_COMPONENTS,
   1.134 +                        WE_HAVE_AN_X_AND_Y_SCALE,
   1.135 +                        WE_HAVE_A_TWO_BY_TWO)
   1.136 +                } field;
   1.137 +                struct Raw {
   1.138 +                    static const SK_OT_USHORT ARG_1_AND_2_ARE_WORDS_Mask = SkTEndian_SwapBE16(1 << 0);
   1.139 +                    static const SK_OT_USHORT ARGS_ARE_XY_VALUES_Mask = SkTEndian_SwapBE16(1 << 1);
   1.140 +                    static const SK_OT_USHORT ROUND_XY_TO_GRID_Mask = SkTEndian_SwapBE16(1 << 2);
   1.141 +                    static const SK_OT_USHORT WE_HAVE_A_SCALE_Mask = SkTEndian_SwapBE16(1 << 3);
   1.142 +                    static const SK_OT_USHORT RESERVED_Mask = SkTEndian_SwapBE16(1 << 4);
   1.143 +                    static const SK_OT_USHORT MORE_COMPONENTS_Mask = SkTEndian_SwapBE16(1 << 5);
   1.144 +                    static const SK_OT_USHORT WE_HAVE_AN_X_AND_Y_SCALE_Mask = SkTEndian_SwapBE16(1 << 6);
   1.145 +                    static const SK_OT_USHORT WE_HAVE_A_TWO_BY_TWO_Mask = SkTEndian_SwapBE16(1 << 7);
   1.146 +
   1.147 +                    static const SK_OT_USHORT WE_HAVE_INSTRUCTIONS_Mask = SkTEndian_SwapBE16(1 << 8);
   1.148 +                    static const SK_OT_USHORT USE_MY_METRICS_Mask = SkTEndian_SwapBE16(1 << 9);
   1.149 +                    static const SK_OT_USHORT OVERLAP_COMPOUND_Mask = SkTEndian_SwapBE16(1 << 10);
   1.150 +                    static const SK_OT_USHORT SCALED_COMPONENT_OFFSET_Mask = SkTEndian_SwapBE16(1 << 11);
   1.151 +                    static const SK_OT_USHORT UNSCALED_COMPONENT_OFFSET_mask = SkTEndian_SwapBE16(1 << 12);
   1.152 +                    //Reserved
   1.153 +                    //Reserved
   1.154 +                    //Reserved
   1.155 +                    SK_OT_USHORT value;
   1.156 +                } raw;
   1.157 +            } flags;
   1.158 +            SK_OT_USHORT glyphIndex;
   1.159 +            union Transform {
   1.160 +                union Matrix {
   1.161 +                    /** !WE_HAVE_A_SCALE & !WE_HAVE_AN_X_AND_Y_SCALE & !WE_HAVE_A_TWO_BY_TWO */
   1.162 +                    struct None { } none;
   1.163 +                    /** WE_HAVE_A_SCALE */
   1.164 +                    struct Scale {
   1.165 +                        SK_OT_F2DOT14 a_d;
   1.166 +                    } scale;
   1.167 +                    /** WE_HAVE_AN_X_AND_Y_SCALE */
   1.168 +                    struct ScaleXY {
   1.169 +                        SK_OT_F2DOT14 a;
   1.170 +                        SK_OT_F2DOT14 d;
   1.171 +                    } scaleXY;
   1.172 +                    /** WE_HAVE_A_TWO_BY_TWO */
   1.173 +                    struct TwoByTwo {
   1.174 +                        SK_OT_F2DOT14 a;
   1.175 +                        SK_OT_F2DOT14 b;
   1.176 +                        SK_OT_F2DOT14 c;
   1.177 +                        SK_OT_F2DOT14 d;
   1.178 +                    } twoByTwo;
   1.179 +                };
   1.180 +                /** ARG_1_AND_2_ARE_WORDS & ARGS_ARE_XY_VALUES */
   1.181 +                struct WordValue {
   1.182 +                    SK_OT_FWORD e;
   1.183 +                    SK_OT_FWORD f;
   1.184 +                    SkOTTableGlyphData::Composite::Component::Transform::Matrix matrix;
   1.185 +                } wordValue;
   1.186 +                /** !ARG_1_AND_2_ARE_WORDS & ARGS_ARE_XY_VALUES */
   1.187 +                struct ByteValue {
   1.188 +                    SK_OT_CHAR e;
   1.189 +                    SK_OT_CHAR f;
   1.190 +                    SkOTTableGlyphData::Composite::Component::Transform::Matrix matrix;
   1.191 +                } byteValue;
   1.192 +                /** ARG_1_AND_2_ARE_WORDS & !ARGS_ARE_XY_VALUES */
   1.193 +                struct WordIndex {
   1.194 +                    SK_OT_USHORT compoundPointIndex;
   1.195 +                    SK_OT_USHORT componentPointIndex;
   1.196 +                    SkOTTableGlyphData::Composite::Component::Transform::Matrix matrix;
   1.197 +                } wordIndex;
   1.198 +                /** !ARG_1_AND_2_ARE_WORDS & !ARGS_ARE_XY_VALUES */
   1.199 +                struct ByteIndex {
   1.200 +                    SK_OT_BYTE compoundPointIndex;
   1.201 +                    SK_OT_BYTE componentPointIndex;
   1.202 +                    SkOTTableGlyphData::Composite::Component::Transform::Matrix matrix;
   1.203 +                } byteIndex;
   1.204 +            } transform;
   1.205 +        } component;//[] last element does not set MORE_COMPONENTS
   1.206 +
   1.207 +        /** Comes after the last Component if the last component has WE_HAVE_INSTR. */
   1.208 +        struct Instructions {
   1.209 +            SK_OT_USHORT length;
   1.210 +            SK_OT_BYTE data[1/*length*/];
   1.211 +        };
   1.212 +    };
   1.213 +};
   1.214 +
   1.215 +#pragma pack(pop)
   1.216 +
   1.217 +#endif

mercurial