gfx/graphite2/src/inc/Slot.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* GRAPHITE2 LICENSING
michael@0 2
michael@0 3 Copyright 2010, SIL International
michael@0 4 All rights reserved.
michael@0 5
michael@0 6 This library is free software; you can redistribute it and/or modify
michael@0 7 it under the terms of the GNU Lesser General Public License as published
michael@0 8 by the Free Software Foundation; either version 2.1 of License, or
michael@0 9 (at your option) any later version.
michael@0 10
michael@0 11 This program is distributed in the hope that it will be useful,
michael@0 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
michael@0 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
michael@0 14 Lesser General Public License for more details.
michael@0 15
michael@0 16 You should also have received a copy of the GNU Lesser General Public
michael@0 17 License along with this library in the file named "LICENSE".
michael@0 18 If not, write to the Free Software Foundation, 51 Franklin Street,
michael@0 19 Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
michael@0 20 internet at http://www.fsf.org/licenses/lgpl.html.
michael@0 21
michael@0 22 Alternatively, the contents of this file may be used under the terms of the
michael@0 23 Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
michael@0 24 License, as published by the Free Software Foundation, either version 2
michael@0 25 of the License or (at your option) any later version.
michael@0 26 */
michael@0 27 #pragma once
michael@0 28
michael@0 29 #include "graphite2/Types.h"
michael@0 30 #include "graphite2/Segment.h"
michael@0 31 #include "inc/Main.h"
michael@0 32 #include "inc/Font.h"
michael@0 33 #include "inc/Position.h"
michael@0 34
michael@0 35
michael@0 36
michael@0 37 namespace graphite2 {
michael@0 38
michael@0 39 typedef gr_attrCode attrCode;
michael@0 40
michael@0 41 class GlyphFace;
michael@0 42 class Segment;
michael@0 43 class SegCacheEntry;
michael@0 44
michael@0 45 struct SlotJustify
michael@0 46 {
michael@0 47 static const int NUMJUSTPARAMS = 5;
michael@0 48
michael@0 49 SlotJustify(const SlotJustify &);
michael@0 50 SlotJustify & operator = (const SlotJustify &);
michael@0 51
michael@0 52 public:
michael@0 53 static size_t size_of(size_t levels) { return sizeof(SlotJustify) + ((levels > 1 ? levels : 1)*NUMJUSTPARAMS - 1)*sizeof(int16); }
michael@0 54
michael@0 55 void LoadSlot(const Slot *s, const Segment *seg);
michael@0 56
michael@0 57 SlotJustify *next;
michael@0 58 int16 values[1];
michael@0 59 };
michael@0 60
michael@0 61 class Slot
michael@0 62 {
michael@0 63 enum Flag
michael@0 64 {
michael@0 65 DELETED = 1,
michael@0 66 INSERTED = 2,
michael@0 67 COPIED = 4,
michael@0 68 POSITIONED = 8,
michael@0 69 ATTACHED = 16
michael@0 70 };
michael@0 71
michael@0 72 public:
michael@0 73 struct iterator;
michael@0 74
michael@0 75 unsigned short gid() const { return m_glyphid; }
michael@0 76 Position origin() const { return m_position; }
michael@0 77 float advance() const { return m_advance.x; }
michael@0 78 Position advancePos() const { return m_advance; }
michael@0 79 int before() const { return m_before; }
michael@0 80 int after() const { return m_after; }
michael@0 81 uint32 index() const { return m_index; }
michael@0 82 void index(uint32 val) { m_index = val; }
michael@0 83
michael@0 84 Slot();
michael@0 85 void set(const Slot & slot, int charOffset, size_t numUserAttr, size_t justLevels, size_t numChars);
michael@0 86 Slot *next() const { return m_next; }
michael@0 87 void next(Slot *s) { m_next = s; }
michael@0 88 Slot *prev() const { return m_prev; }
michael@0 89 void prev(Slot *s) { m_prev = s; }
michael@0 90 uint16 glyph() const { return m_realglyphid ? m_realglyphid : m_glyphid; }
michael@0 91 void setGlyph(Segment *seg, uint16 glyphid, const GlyphFace * theGlyph = NULL);
michael@0 92 void setRealGid(uint16 realGid) { m_realglyphid = realGid; }
michael@0 93 void adjKern(const Position &pos) { m_shift = m_shift + pos; m_advance = m_advance + pos; }
michael@0 94 void origin(const Position &pos) { m_position = pos + m_shift; }
michael@0 95 void originate(int ind) { m_original = ind; }
michael@0 96 int original() const { return m_original; }
michael@0 97 void before(int ind) { m_before = ind; }
michael@0 98 void after(int ind) { m_after = ind; }
michael@0 99 bool isBase() const { return (!m_parent); }
michael@0 100 void update(int numSlots, int numCharInfo, Position &relpos);
michael@0 101 Position finalise(const Segment* seg, const Font* font, Position & base, Rect & bbox, uint8 attrLevel, float & clusterMin);
michael@0 102 bool isDeleted() const { return (m_flags & DELETED) ? true : false; }
michael@0 103 void markDeleted(bool state) { if (state) m_flags |= DELETED; else m_flags &= ~DELETED; }
michael@0 104 bool isCopied() const { return (m_flags & COPIED) ? true : false; }
michael@0 105 void markCopied(bool state) { if (state) m_flags |= COPIED; else m_flags &= ~COPIED; }
michael@0 106 bool isPositioned() const { return (m_flags & POSITIONED) ? true : false; }
michael@0 107 void markPositioned(bool state) { if (state) m_flags |= POSITIONED; else m_flags &= ~POSITIONED; }
michael@0 108 bool isInsertBefore() const { return !(m_flags & INSERTED); }
michael@0 109 uint8 getBidiLevel() const { return m_bidiLevel; }
michael@0 110 void setBidiLevel(uint8 level) { m_bidiLevel = level; }
michael@0 111 int8 getBidiClass() const { return m_bidiCls; }
michael@0 112 void setBidiClass(int8 cls) { m_bidiCls = cls; }
michael@0 113 int16 *userAttrs() const { return m_userAttr; }
michael@0 114 void userAttrs(int16 *p) { m_userAttr = p; }
michael@0 115 void markInsertBefore(bool state) { if (!state) m_flags |= INSERTED; else m_flags &= ~INSERTED; }
michael@0 116 void setAttr(Segment* seg, attrCode ind, uint8 subindex, int16 val, const SlotMap & map);
michael@0 117 int getAttr(const Segment *seg, attrCode ind, uint8 subindex) const;
michael@0 118 int getJustify(const Segment *seg, uint8 level, uint8 subindex) const;
michael@0 119 void setJustify(Segment *seg, uint8 level, uint8 subindex, int16 value);
michael@0 120 bool isLocalJustify() const { return m_justs != NULL; };
michael@0 121 void attachTo(Slot *ap) { m_parent = ap; }
michael@0 122 Slot *attachedTo() const { return m_parent; }
michael@0 123 Position attachOffset() const { return m_attach - m_with; }
michael@0 124 Slot* firstChild() const { return m_child; }
michael@0 125 bool child(Slot *ap);
michael@0 126 Slot* nextSibling() const { return m_sibling; }
michael@0 127 bool sibling(Slot *ap);
michael@0 128 bool removeChild(Slot *ap);
michael@0 129 bool removeSibling(Slot *ap);
michael@0 130 int32 clusterMetric(const Segment* seg, uint8 metric, uint8 attrLevel);
michael@0 131 void positionShift(Position a) { m_position += a; }
michael@0 132 void floodShift(Position adj);
michael@0 133 float just() const { return m_just; }
michael@0 134 void just(float j) { m_just = j; }
michael@0 135
michael@0 136 CLASS_NEW_DELETE
michael@0 137
michael@0 138 private:
michael@0 139 Slot *m_next; // linked list of slots
michael@0 140 Slot *m_prev;
michael@0 141 unsigned short m_glyphid; // glyph id
michael@0 142 uint16 m_realglyphid;
michael@0 143 uint32 m_original; // charinfo that originated this slot (e.g. for feature values)
michael@0 144 uint32 m_before; // charinfo index of before association
michael@0 145 uint32 m_after; // charinfo index of after association
michael@0 146 uint32 m_index; // slot index given to this slot during finalising
michael@0 147 Slot *m_parent; // index to parent we are attached to
michael@0 148 Slot *m_child; // index to first child slot that attaches to us
michael@0 149 Slot *m_sibling; // index to next child that attaches to our parent
michael@0 150 Position m_position; // absolute position of glyph
michael@0 151 Position m_shift; // .shift slot attribute
michael@0 152 Position m_advance; // .advance slot attribute
michael@0 153 Position m_attach; // attachment point on us
michael@0 154 Position m_with; // attachment point position on parent
michael@0 155 float m_just; // Justification inserted space
michael@0 156 uint8 m_flags; // holds bit flags
michael@0 157 byte m_attLevel; // attachment level
michael@0 158 int8 m_bidiCls; // bidirectional class
michael@0 159 byte m_bidiLevel; // bidirectional level
michael@0 160 int16 *m_userAttr; // pointer to user attributes
michael@0 161 SlotJustify *m_justs; // pointer to justification parameters
michael@0 162
michael@0 163 friend class SegCacheEntry;
michael@0 164 friend class Segment;
michael@0 165 };
michael@0 166
michael@0 167 } // namespace graphite2
michael@0 168
michael@0 169 struct gr_slot : public graphite2::Slot {};

mercurial