Path: blob/master/thirdparty/graphite/src/inc/Slot.h
10279 views
// SPDX-License-Identifier: MIT OR MPL-2.0 OR LGPL-2.1-or-later OR GPL-2.0-or-later1// Copyright 2010, SIL International, All rights reserved.23#pragma once45#include "graphite2/Types.h"6#include "graphite2/Segment.h"7#include "inc/Main.h"8#include "inc/Font.h"9#include "inc/Position.h"1011namespace graphite2 {1213typedef gr_attrCode attrCode;1415class GlyphFace;16class Segment;1718struct SlotJustify19{20static const int NUMJUSTPARAMS = 5;2122SlotJustify(const SlotJustify &);23SlotJustify & operator = (const SlotJustify &);2425public:26static size_t size_of(size_t levels) { return sizeof(SlotJustify) + ((levels > 1 ? levels : 1)*NUMJUSTPARAMS - 1)*sizeof(int16); }2728void LoadSlot(const Slot *s, const Segment *seg);2930SlotJustify *next;31int16 values[1];32};3334class Slot35{36enum Flag37{38DELETED = 1,39INSERTED = 2,40COPIED = 4,41POSITIONED = 8,42ATTACHED = 1643};4445public:46struct iterator;4748unsigned short gid() const { return m_glyphid; }49Position origin() const { return m_position; }50float advance() const { return m_advance.x; }51void advance(Position &val) { m_advance = val; }52Position advancePos() const { return m_advance; }53int before() const { return m_before; }54int after() const { return m_after; }55uint32 index() const { return m_index; }56void index(uint32 val) { m_index = val; }5758Slot(int16 *m_userAttr = NULL);59void set(const Slot & slot, int charOffset, size_t numUserAttr, size_t justLevels, size_t numChars);60Slot *next() const { return m_next; }61void next(Slot *s) { m_next = s; }62Slot *prev() const { return m_prev; }63void prev(Slot *s) { m_prev = s; }64uint16 glyph() const { return m_realglyphid ? m_realglyphid : m_glyphid; }65void setGlyph(Segment *seg, uint16 glyphid, const GlyphFace * theGlyph = NULL);66void setRealGid(uint16 realGid) { m_realglyphid = realGid; }67void adjKern(const Position &pos) { m_shift = m_shift + pos; m_advance = m_advance + pos; }68void origin(const Position &pos) { m_position = pos + m_shift; }69void originate(int ind) { m_original = ind; }70int original() const { return m_original; }71void before(int ind) { m_before = ind; }72void after(int ind) { m_after = ind; }73bool isBase() const { return (!m_parent); }74void update(int numSlots, int numCharInfo, Position &relpos);75Position finalise(const Segment* seg, const Font* font, Position & base, Rect & bbox, uint8 attrLevel, float & clusterMin, bool rtl, bool isFinal, int depth = 0);76bool isDeleted() const { return (m_flags & DELETED) ? true : false; }77void markDeleted(bool state) { if (state) m_flags |= DELETED; else m_flags &= ~DELETED; }78bool isCopied() const { return (m_flags & COPIED) ? true : false; }79void markCopied(bool state) { if (state) m_flags |= COPIED; else m_flags &= ~COPIED; }80bool isPositioned() const { return (m_flags & POSITIONED) ? true : false; }81void markPositioned(bool state) { if (state) m_flags |= POSITIONED; else m_flags &= ~POSITIONED; }82bool isInsertBefore() const { return !(m_flags & INSERTED); }83uint8 getBidiLevel() const { return m_bidiLevel; }84void setBidiLevel(uint8 level) { m_bidiLevel = level; }85int8 getBidiClass(const Segment *seg);86int8 getBidiClass() const { return m_bidiCls; }87void setBidiClass(int8 cls) { m_bidiCls = cls; }88int16 *userAttrs() const { return m_userAttr; }89void userAttrs(int16 *p) { m_userAttr = p; }90void markInsertBefore(bool state) { if (!state) m_flags |= INSERTED; else m_flags &= ~INSERTED; }91void setAttr(Segment* seg, attrCode ind, uint8 subindex, int16 val, const SlotMap & map);92int getAttr(const Segment *seg, attrCode ind, uint8 subindex) const;93int getJustify(const Segment *seg, uint8 level, uint8 subindex) const;94void setJustify(Segment *seg, uint8 level, uint8 subindex, int16 value);95bool isLocalJustify() const { return m_justs != NULL; };96void attachTo(Slot *ap) { m_parent = ap; }97Slot *attachedTo() const { return m_parent; }98Position attachOffset() const { return m_attach - m_with; }99Slot* firstChild() const { return m_child; }100void firstChild(Slot *ap) { m_child = ap; }101bool child(Slot *ap);102Slot* nextSibling() const { return m_sibling; }103void nextSibling(Slot *ap) { m_sibling = ap; }104bool sibling(Slot *ap);105bool removeChild(Slot *ap);106int32 clusterMetric(const Segment* seg, uint8 metric, uint8 attrLevel, bool rtl);107void positionShift(Position a) { m_position += a; }108void floodShift(Position adj, int depth = 0);109float just() const { return m_just; }110void just(float j) { m_just = j; }111Slot *nextInCluster(const Slot *s) const;112bool isChildOf(const Slot *base) const;113114CLASS_NEW_DELETE115116private:117Slot *m_next; // linked list of slots118Slot *m_prev;119unsigned short m_glyphid; // glyph id120uint16 m_realglyphid;121uint32 m_original; // charinfo that originated this slot (e.g. for feature values)122uint32 m_before; // charinfo index of before association123uint32 m_after; // charinfo index of after association124uint32 m_index; // slot index given to this slot during finalising125Slot *m_parent; // index to parent we are attached to126Slot *m_child; // index to first child slot that attaches to us127Slot *m_sibling; // index to next child that attaches to our parent128Position m_position; // absolute position of glyph129Position m_shift; // .shift slot attribute130Position m_advance; // .advance slot attribute131Position m_attach; // attachment point on us132Position m_with; // attachment point position on parent133float m_just; // Justification inserted space134uint8 m_flags; // holds bit flags135byte m_attLevel; // attachment level136int8 m_bidiCls; // bidirectional class137byte m_bidiLevel; // bidirectional level138int16 *m_userAttr; // pointer to user attributes139SlotJustify *m_justs; // pointer to justification parameters140141friend class Segment;142};143144} // namespace graphite2145146struct gr_slot : public graphite2::Slot {};147148149