gfx/skia/trunk/src/core/SkGlyph.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Copyright 2006 The Android Open Source Project
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 #ifndef SkGlyph_DEFINED
michael@0 9 #define SkGlyph_DEFINED
michael@0 10
michael@0 11 #include "SkTypes.h"
michael@0 12 #include "SkFixed.h"
michael@0 13 #include "SkMask.h"
michael@0 14
michael@0 15 class SkPath;
michael@0 16
michael@0 17 // needs to be != to any valid SkMask::Format
michael@0 18 #define MASK_FORMAT_UNKNOWN (0xFF)
michael@0 19 #define MASK_FORMAT_JUST_ADVANCE MASK_FORMAT_UNKNOWN
michael@0 20
michael@0 21 #define kMaxGlyphWidth (1<<13)
michael@0 22
michael@0 23 struct SkGlyph {
michael@0 24 void* fImage;
michael@0 25 SkPath* fPath;
michael@0 26 SkFixed fAdvanceX, fAdvanceY;
michael@0 27
michael@0 28 uint32_t fID;
michael@0 29 uint16_t fWidth, fHeight;
michael@0 30 int16_t fTop, fLeft;
michael@0 31
michael@0 32 uint8_t fMaskFormat;
michael@0 33 int8_t fRsbDelta, fLsbDelta; // used by auto-kerning
michael@0 34
michael@0 35 void init(uint32_t id) {
michael@0 36 fID = id;
michael@0 37 fImage = NULL;
michael@0 38 fPath = NULL;
michael@0 39 fMaskFormat = MASK_FORMAT_UNKNOWN;
michael@0 40 }
michael@0 41
michael@0 42 /**
michael@0 43 * Compute the rowbytes for the specified width and mask-format.
michael@0 44 */
michael@0 45 static unsigned ComputeRowBytes(unsigned width, SkMask::Format format) {
michael@0 46 unsigned rb = width;
michael@0 47 if (SkMask::kBW_Format == format) {
michael@0 48 rb = (rb + 7) >> 3;
michael@0 49 } else if (SkMask::kARGB32_Format == format ||
michael@0 50 SkMask::kLCD32_Format == format)
michael@0 51 {
michael@0 52 rb <<= 2;
michael@0 53 } else if (SkMask::kLCD16_Format == format) {
michael@0 54 rb = SkAlign4(rb << 1);
michael@0 55 } else {
michael@0 56 rb = SkAlign4(rb);
michael@0 57 }
michael@0 58 return rb;
michael@0 59 }
michael@0 60
michael@0 61 unsigned rowBytes() const {
michael@0 62 return ComputeRowBytes(fWidth, (SkMask::Format)fMaskFormat);
michael@0 63 }
michael@0 64
michael@0 65 bool isJustAdvance() const {
michael@0 66 return MASK_FORMAT_JUST_ADVANCE == fMaskFormat;
michael@0 67 }
michael@0 68
michael@0 69 bool isFullMetrics() const {
michael@0 70 return MASK_FORMAT_JUST_ADVANCE != fMaskFormat;
michael@0 71 }
michael@0 72
michael@0 73 uint16_t getGlyphID() const {
michael@0 74 return ID2Code(fID);
michael@0 75 }
michael@0 76
michael@0 77 unsigned getGlyphID(unsigned baseGlyphCount) const {
michael@0 78 unsigned code = ID2Code(fID);
michael@0 79 SkASSERT(code >= baseGlyphCount);
michael@0 80 return code - baseGlyphCount;
michael@0 81 }
michael@0 82
michael@0 83 unsigned getSubX() const {
michael@0 84 return ID2SubX(fID);
michael@0 85 }
michael@0 86
michael@0 87 SkFixed getSubXFixed() const {
michael@0 88 return SubToFixed(ID2SubX(fID));
michael@0 89 }
michael@0 90
michael@0 91 SkFixed getSubYFixed() const {
michael@0 92 return SubToFixed(ID2SubY(fID));
michael@0 93 }
michael@0 94
michael@0 95 size_t computeImageSize() const;
michael@0 96
michael@0 97 /** Call this to set all of the metrics fields to 0 (e.g. if the scaler
michael@0 98 encounters an error measuring a glyph). Note: this does not alter the
michael@0 99 fImage, fPath, fID, fMaskFormat fields.
michael@0 100 */
michael@0 101 void zeroMetrics();
michael@0 102
michael@0 103 enum {
michael@0 104 kSubBits = 2,
michael@0 105 kSubMask = ((1 << kSubBits) - 1),
michael@0 106 kSubShift = 24, // must be large enough for glyphs and unichars
michael@0 107 kCodeMask = ((1 << kSubShift) - 1),
michael@0 108 // relative offsets for X and Y subpixel bits
michael@0 109 kSubShiftX = kSubBits,
michael@0 110 kSubShiftY = 0
michael@0 111 };
michael@0 112
michael@0 113 static unsigned ID2Code(uint32_t id) {
michael@0 114 return id & kCodeMask;
michael@0 115 }
michael@0 116
michael@0 117 static unsigned ID2SubX(uint32_t id) {
michael@0 118 return id >> (kSubShift + kSubShiftX);
michael@0 119 }
michael@0 120
michael@0 121 static unsigned ID2SubY(uint32_t id) {
michael@0 122 return (id >> (kSubShift + kSubShiftY)) & kSubMask;
michael@0 123 }
michael@0 124
michael@0 125 static unsigned FixedToSub(SkFixed n) {
michael@0 126 return (n >> (16 - kSubBits)) & kSubMask;
michael@0 127 }
michael@0 128
michael@0 129 static SkFixed SubToFixed(unsigned sub) {
michael@0 130 SkASSERT(sub <= kSubMask);
michael@0 131 return sub << (16 - kSubBits);
michael@0 132 }
michael@0 133
michael@0 134 static uint32_t MakeID(unsigned code) {
michael@0 135 return code;
michael@0 136 }
michael@0 137
michael@0 138 static uint32_t MakeID(unsigned code, SkFixed x, SkFixed y) {
michael@0 139 SkASSERT(code <= kCodeMask);
michael@0 140 x = FixedToSub(x);
michael@0 141 y = FixedToSub(y);
michael@0 142 return (x << (kSubShift + kSubShiftX)) |
michael@0 143 (y << (kSubShift + kSubShiftY)) |
michael@0 144 code;
michael@0 145 }
michael@0 146
michael@0 147 void toMask(SkMask* mask) const;
michael@0 148 };
michael@0 149
michael@0 150 #endif

mercurial