gfx/graphite2/src/inc/Slot.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/graphite2/src/inc/Slot.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,169 @@
     1.4 +/*  GRAPHITE2 LICENSING
     1.5 +
     1.6 +    Copyright 2010, SIL International
     1.7 +    All rights reserved.
     1.8 +
     1.9 +    This library is free software; you can redistribute it and/or modify
    1.10 +    it under the terms of the GNU Lesser General Public License as published
    1.11 +    by the Free Software Foundation; either version 2.1 of License, or
    1.12 +    (at your option) any later version.
    1.13 +
    1.14 +    This program is distributed in the hope that it will be useful,
    1.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.17 +    Lesser General Public License for more details.
    1.18 +
    1.19 +    You should also have received a copy of the GNU Lesser General Public
    1.20 +    License along with this library in the file named "LICENSE".
    1.21 +    If not, write to the Free Software Foundation, 51 Franklin Street, 
    1.22 +    Suite 500, Boston, MA 02110-1335, USA or visit their web page on the 
    1.23 +    internet at http://www.fsf.org/licenses/lgpl.html.
    1.24 +
    1.25 +Alternatively, the contents of this file may be used under the terms of the
    1.26 +Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
    1.27 +License, as published by the Free Software Foundation, either version 2
    1.28 +of the License or (at your option) any later version.
    1.29 +*/
    1.30 +#pragma once
    1.31 +
    1.32 +#include "graphite2/Types.h"
    1.33 +#include "graphite2/Segment.h"
    1.34 +#include "inc/Main.h"
    1.35 +#include "inc/Font.h"
    1.36 +#include "inc/Position.h"
    1.37 +
    1.38 +
    1.39 +
    1.40 +namespace graphite2 {
    1.41 +
    1.42 +typedef gr_attrCode attrCode;
    1.43 +
    1.44 +class GlyphFace;
    1.45 +class Segment;
    1.46 +class SegCacheEntry;
    1.47 +
    1.48 +struct SlotJustify
    1.49 +{
    1.50 +    static const int NUMJUSTPARAMS = 5;
    1.51 +
    1.52 +    SlotJustify(const SlotJustify &);
    1.53 +    SlotJustify & operator = (const SlotJustify &);
    1.54 +
    1.55 +public:
    1.56 +    static size_t size_of(size_t levels) { return sizeof(SlotJustify) + ((levels > 1 ? levels : 1)*NUMJUSTPARAMS - 1)*sizeof(int16); }
    1.57 +
    1.58 +    void LoadSlot(const Slot *s, const Segment *seg);
    1.59 +
    1.60 +    SlotJustify *next;
    1.61 +    int16 values[1];
    1.62 +};
    1.63 +
    1.64 +class Slot
    1.65 +{
    1.66 +    enum Flag
    1.67 +    {
    1.68 +        DELETED     = 1,
    1.69 +        INSERTED    = 2,
    1.70 +        COPIED      = 4,
    1.71 +        POSITIONED  = 8,
    1.72 +        ATTACHED    = 16
    1.73 +    };
    1.74 +
    1.75 +public:
    1.76 +    struct iterator;
    1.77 +
    1.78 +    unsigned short gid() const { return m_glyphid; }
    1.79 +    Position origin() const { return m_position; }
    1.80 +    float advance() const { return m_advance.x; }
    1.81 +    Position advancePos() const { return m_advance; }
    1.82 +    int before() const { return m_before; }
    1.83 +    int after() const { return m_after; }
    1.84 +    uint32 index() const { return m_index; }
    1.85 +    void index(uint32 val) { m_index = val; }
    1.86 +
    1.87 +    Slot();
    1.88 +    void set(const Slot & slot, int charOffset, size_t numUserAttr, size_t justLevels, size_t numChars);
    1.89 +    Slot *next() const { return m_next; }
    1.90 +    void next(Slot *s) { m_next = s; }
    1.91 +    Slot *prev() const { return m_prev; }
    1.92 +    void prev(Slot *s) { m_prev = s; }
    1.93 +    uint16 glyph() const { return m_realglyphid ? m_realglyphid : m_glyphid; }
    1.94 +    void setGlyph(Segment *seg, uint16 glyphid, const GlyphFace * theGlyph = NULL);
    1.95 +    void setRealGid(uint16 realGid) { m_realglyphid = realGid; }
    1.96 +    void adjKern(const Position &pos) { m_shift = m_shift + pos; m_advance = m_advance + pos; }
    1.97 +    void origin(const Position &pos) { m_position = pos + m_shift; }
    1.98 +    void originate(int ind) { m_original = ind; }
    1.99 +    int original() const { return m_original; }
   1.100 +    void before(int ind) { m_before = ind; }
   1.101 +    void after(int ind) { m_after = ind; }
   1.102 +    bool isBase() const { return (!m_parent); }
   1.103 +    void update(int numSlots, int numCharInfo, Position &relpos);
   1.104 +    Position finalise(const Segment* seg, const Font* font, Position & base, Rect & bbox, uint8 attrLevel, float & clusterMin);
   1.105 +    bool isDeleted() const { return (m_flags & DELETED) ? true : false; }
   1.106 +    void markDeleted(bool state) { if (state) m_flags |= DELETED; else m_flags &= ~DELETED; }
   1.107 +    bool isCopied() const { return (m_flags & COPIED) ? true : false; }
   1.108 +    void markCopied(bool state) { if (state) m_flags |= COPIED; else m_flags &= ~COPIED; }
   1.109 +    bool isPositioned() const { return (m_flags & POSITIONED) ? true : false; }
   1.110 +    void markPositioned(bool state) { if (state) m_flags |= POSITIONED; else m_flags &= ~POSITIONED; }
   1.111 +    bool isInsertBefore() const { return !(m_flags & INSERTED); }
   1.112 +    uint8 getBidiLevel() const { return m_bidiLevel; }
   1.113 +    void setBidiLevel(uint8 level) { m_bidiLevel = level; }
   1.114 +    int8 getBidiClass() const { return m_bidiCls; }
   1.115 +    void setBidiClass(int8 cls) { m_bidiCls = cls; }
   1.116 +    int16 *userAttrs() const { return m_userAttr; }
   1.117 +    void userAttrs(int16 *p) { m_userAttr = p; }
   1.118 +    void markInsertBefore(bool state) { if (!state) m_flags |= INSERTED; else m_flags &= ~INSERTED; }
   1.119 +    void setAttr(Segment* seg, attrCode ind, uint8 subindex, int16 val, const SlotMap & map);
   1.120 +    int getAttr(const Segment *seg, attrCode ind, uint8 subindex) const;
   1.121 +    int getJustify(const Segment *seg, uint8 level, uint8 subindex) const;
   1.122 +    void setJustify(Segment *seg, uint8 level, uint8 subindex, int16 value);
   1.123 +    bool isLocalJustify() const { return m_justs != NULL; };
   1.124 +    void attachTo(Slot *ap) { m_parent = ap; }
   1.125 +    Slot *attachedTo() const { return m_parent; }
   1.126 +    Position attachOffset() const { return m_attach - m_with; }
   1.127 +    Slot* firstChild() const { return m_child; }
   1.128 +    bool child(Slot *ap);
   1.129 +    Slot* nextSibling() const { return m_sibling; }
   1.130 +    bool sibling(Slot *ap);
   1.131 +    bool removeChild(Slot *ap);
   1.132 +    bool removeSibling(Slot *ap);
   1.133 +    int32 clusterMetric(const Segment* seg, uint8 metric, uint8 attrLevel);
   1.134 +    void positionShift(Position a) { m_position += a; }
   1.135 +    void floodShift(Position adj);
   1.136 +    float just() const { return m_just; }
   1.137 +    void just(float j) { m_just = j; }
   1.138 +
   1.139 +    CLASS_NEW_DELETE
   1.140 +
   1.141 +private:
   1.142 +    Slot *m_next;           // linked list of slots
   1.143 +    Slot *m_prev;
   1.144 +    unsigned short m_glyphid;        // glyph id
   1.145 +    uint16 m_realglyphid;
   1.146 +    uint32 m_original;      // charinfo that originated this slot (e.g. for feature values)
   1.147 +    uint32 m_before;        // charinfo index of before association
   1.148 +    uint32 m_after;         // charinfo index of after association
   1.149 +    uint32 m_index;         // slot index given to this slot during finalising
   1.150 +    Slot *m_parent;         // index to parent we are attached to
   1.151 +    Slot *m_child;          // index to first child slot that attaches to us
   1.152 +    Slot *m_sibling;        // index to next child that attaches to our parent
   1.153 +    Position m_position;    // absolute position of glyph
   1.154 +    Position m_shift;       // .shift slot attribute
   1.155 +    Position m_advance;     // .advance slot attribute
   1.156 +    Position m_attach;      // attachment point on us
   1.157 +    Position m_with;        // attachment point position on parent
   1.158 +    float    m_just;        // Justification inserted space
   1.159 +    uint8    m_flags;       // holds bit flags
   1.160 +    byte     m_attLevel;    // attachment level
   1.161 +    int8     m_bidiCls;     // bidirectional class
   1.162 +    byte     m_bidiLevel;   // bidirectional level
   1.163 +    int16   *m_userAttr;    // pointer to user attributes
   1.164 +    SlotJustify *m_justs;   // pointer to justification parameters
   1.165 +
   1.166 +    friend class SegCacheEntry;
   1.167 +    friend class Segment;
   1.168 +};
   1.169 +
   1.170 +} // namespace graphite2
   1.171 +
   1.172 +struct gr_slot : public graphite2::Slot {};

mercurial