michael@0: /* GRAPHITE2 LICENSING michael@0: michael@0: Copyright 2010, SIL International michael@0: All rights reserved. michael@0: michael@0: This library is free software; you can redistribute it and/or modify michael@0: it under the terms of the GNU Lesser General Public License as published michael@0: by the Free Software Foundation; either version 2.1 of License, or michael@0: (at your option) any later version. michael@0: michael@0: This program is distributed in the hope that it will be useful, michael@0: but WITHOUT ANY WARRANTY; without even the implied warranty of michael@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU michael@0: Lesser General Public License for more details. michael@0: michael@0: You should also have received a copy of the GNU Lesser General Public michael@0: License along with this library in the file named "LICENSE". michael@0: If not, write to the Free Software Foundation, 51 Franklin Street, michael@0: Suite 500, Boston, MA 02110-1335, USA or visit their web page on the michael@0: internet at http://www.fsf.org/licenses/lgpl.html. michael@0: michael@0: Alternatively, the contents of this file may be used under the terms of the michael@0: Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public michael@0: License, as published by the Free Software Foundation, either version 2 michael@0: of the License or (at your option) any later version. michael@0: */ michael@0: #pragma once michael@0: michael@0: #include "graphite2/Types.h" michael@0: #include "graphite2/Segment.h" michael@0: #include "inc/Main.h" michael@0: #include "inc/Font.h" michael@0: #include "inc/Position.h" michael@0: michael@0: michael@0: michael@0: namespace graphite2 { michael@0: michael@0: typedef gr_attrCode attrCode; michael@0: michael@0: class GlyphFace; michael@0: class Segment; michael@0: class SegCacheEntry; michael@0: michael@0: struct SlotJustify michael@0: { michael@0: static const int NUMJUSTPARAMS = 5; michael@0: michael@0: SlotJustify(const SlotJustify &); michael@0: SlotJustify & operator = (const SlotJustify &); michael@0: michael@0: public: michael@0: static size_t size_of(size_t levels) { return sizeof(SlotJustify) + ((levels > 1 ? levels : 1)*NUMJUSTPARAMS - 1)*sizeof(int16); } michael@0: michael@0: void LoadSlot(const Slot *s, const Segment *seg); michael@0: michael@0: SlotJustify *next; michael@0: int16 values[1]; michael@0: }; michael@0: michael@0: class Slot michael@0: { michael@0: enum Flag michael@0: { michael@0: DELETED = 1, michael@0: INSERTED = 2, michael@0: COPIED = 4, michael@0: POSITIONED = 8, michael@0: ATTACHED = 16 michael@0: }; michael@0: michael@0: public: michael@0: struct iterator; michael@0: michael@0: unsigned short gid() const { return m_glyphid; } michael@0: Position origin() const { return m_position; } michael@0: float advance() const { return m_advance.x; } michael@0: Position advancePos() const { return m_advance; } michael@0: int before() const { return m_before; } michael@0: int after() const { return m_after; } michael@0: uint32 index() const { return m_index; } michael@0: void index(uint32 val) { m_index = val; } michael@0: michael@0: Slot(); michael@0: void set(const Slot & slot, int charOffset, size_t numUserAttr, size_t justLevels, size_t numChars); michael@0: Slot *next() const { return m_next; } michael@0: void next(Slot *s) { m_next = s; } michael@0: Slot *prev() const { return m_prev; } michael@0: void prev(Slot *s) { m_prev = s; } michael@0: uint16 glyph() const { return m_realglyphid ? m_realglyphid : m_glyphid; } michael@0: void setGlyph(Segment *seg, uint16 glyphid, const GlyphFace * theGlyph = NULL); michael@0: void setRealGid(uint16 realGid) { m_realglyphid = realGid; } michael@0: void adjKern(const Position &pos) { m_shift = m_shift + pos; m_advance = m_advance + pos; } michael@0: void origin(const Position &pos) { m_position = pos + m_shift; } michael@0: void originate(int ind) { m_original = ind; } michael@0: int original() const { return m_original; } michael@0: void before(int ind) { m_before = ind; } michael@0: void after(int ind) { m_after = ind; } michael@0: bool isBase() const { return (!m_parent); } michael@0: void update(int numSlots, int numCharInfo, Position &relpos); michael@0: Position finalise(const Segment* seg, const Font* font, Position & base, Rect & bbox, uint8 attrLevel, float & clusterMin); michael@0: bool isDeleted() const { return (m_flags & DELETED) ? true : false; } michael@0: void markDeleted(bool state) { if (state) m_flags |= DELETED; else m_flags &= ~DELETED; } michael@0: bool isCopied() const { return (m_flags & COPIED) ? true : false; } michael@0: void markCopied(bool state) { if (state) m_flags |= COPIED; else m_flags &= ~COPIED; } michael@0: bool isPositioned() const { return (m_flags & POSITIONED) ? true : false; } michael@0: void markPositioned(bool state) { if (state) m_flags |= POSITIONED; else m_flags &= ~POSITIONED; } michael@0: bool isInsertBefore() const { return !(m_flags & INSERTED); } michael@0: uint8 getBidiLevel() const { return m_bidiLevel; } michael@0: void setBidiLevel(uint8 level) { m_bidiLevel = level; } michael@0: int8 getBidiClass() const { return m_bidiCls; } michael@0: void setBidiClass(int8 cls) { m_bidiCls = cls; } michael@0: int16 *userAttrs() const { return m_userAttr; } michael@0: void userAttrs(int16 *p) { m_userAttr = p; } michael@0: void markInsertBefore(bool state) { if (!state) m_flags |= INSERTED; else m_flags &= ~INSERTED; } michael@0: void setAttr(Segment* seg, attrCode ind, uint8 subindex, int16 val, const SlotMap & map); michael@0: int getAttr(const Segment *seg, attrCode ind, uint8 subindex) const; michael@0: int getJustify(const Segment *seg, uint8 level, uint8 subindex) const; michael@0: void setJustify(Segment *seg, uint8 level, uint8 subindex, int16 value); michael@0: bool isLocalJustify() const { return m_justs != NULL; }; michael@0: void attachTo(Slot *ap) { m_parent = ap; } michael@0: Slot *attachedTo() const { return m_parent; } michael@0: Position attachOffset() const { return m_attach - m_with; } michael@0: Slot* firstChild() const { return m_child; } michael@0: bool child(Slot *ap); michael@0: Slot* nextSibling() const { return m_sibling; } michael@0: bool sibling(Slot *ap); michael@0: bool removeChild(Slot *ap); michael@0: bool removeSibling(Slot *ap); michael@0: int32 clusterMetric(const Segment* seg, uint8 metric, uint8 attrLevel); michael@0: void positionShift(Position a) { m_position += a; } michael@0: void floodShift(Position adj); michael@0: float just() const { return m_just; } michael@0: void just(float j) { m_just = j; } michael@0: michael@0: CLASS_NEW_DELETE michael@0: michael@0: private: michael@0: Slot *m_next; // linked list of slots michael@0: Slot *m_prev; michael@0: unsigned short m_glyphid; // glyph id michael@0: uint16 m_realglyphid; michael@0: uint32 m_original; // charinfo that originated this slot (e.g. for feature values) michael@0: uint32 m_before; // charinfo index of before association michael@0: uint32 m_after; // charinfo index of after association michael@0: uint32 m_index; // slot index given to this slot during finalising michael@0: Slot *m_parent; // index to parent we are attached to michael@0: Slot *m_child; // index to first child slot that attaches to us michael@0: Slot *m_sibling; // index to next child that attaches to our parent michael@0: Position m_position; // absolute position of glyph michael@0: Position m_shift; // .shift slot attribute michael@0: Position m_advance; // .advance slot attribute michael@0: Position m_attach; // attachment point on us michael@0: Position m_with; // attachment point position on parent michael@0: float m_just; // Justification inserted space michael@0: uint8 m_flags; // holds bit flags michael@0: byte m_attLevel; // attachment level michael@0: int8 m_bidiCls; // bidirectional class michael@0: byte m_bidiLevel; // bidirectional level michael@0: int16 *m_userAttr; // pointer to user attributes michael@0: SlotJustify *m_justs; // pointer to justification parameters michael@0: michael@0: friend class SegCacheEntry; michael@0: friend class Segment; michael@0: }; michael@0: michael@0: } // namespace graphite2 michael@0: michael@0: struct gr_slot : public graphite2::Slot {};