Path: blob/master/thirdparty/graphite/src/gr_slot.cpp
9903 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#include "graphite2/Segment.h"4#include "inc/Segment.h"5#include "inc/Slot.h"6#include "inc/Font.h"789extern "C" {101112const gr_slot* gr_slot_next_in_segment(const gr_slot* p/*not NULL*/)13{14assert(p);15return static_cast<const gr_slot*>(p->next());16}1718const gr_slot* gr_slot_prev_in_segment(const gr_slot* p/*not NULL*/)19{20assert(p);21return static_cast<const gr_slot*>(p->prev());22}2324const gr_slot* gr_slot_attached_to(const gr_slot* p/*not NULL*/) //returns NULL iff base. If called repeatedly on result, will get to a base25{26assert(p);27return static_cast<const gr_slot*>(p->attachedTo());28}293031const gr_slot* gr_slot_first_attachment(const gr_slot* p/*not NULL*/) //returns NULL iff no attachments.32{ //if slot_first_attachment(p) is not NULL, then slot_attached_to(slot_first_attachment(p))==p.33assert(p);34return static_cast<const gr_slot*>(p->firstChild());35}363738const gr_slot* gr_slot_next_sibling_attachment(const gr_slot* p/*not NULL*/) //returns NULL iff no more attachments.39{ //if slot_next_sibling_attachment(p) is not NULL, then slot_attached_to(slot_next_sibling_attachment(p))==slot_attached_to(p).40assert(p);41return static_cast<const gr_slot*>(p->nextSibling());42}434445unsigned short gr_slot_gid(const gr_slot* p/*not NULL*/)46{47assert(p);48return p->glyph();49}505152float gr_slot_origin_X(const gr_slot* p/*not NULL*/)53{54assert(p);55return p->origin().x;56}575859float gr_slot_origin_Y(const gr_slot* p/*not NULL*/)60{61assert(p);62return p->origin().y;63}646566float gr_slot_advance_X(const gr_slot* p/*not NULL*/, const gr_face *face, const gr_font *font)67{68assert(p);69float scale = 1.0;70float res = p->advance();71if (font)72{73scale = font->scale();74int gid = p->glyph();75if (face && font->isHinted() && gid < face->glyphs().numGlyphs())76res = (res - face->glyphs().glyph(gid)->theAdvance().x) * scale + font->advance(gid);77else78res = res * scale;79}80return res;81}8283float gr_slot_advance_Y(const gr_slot *p/*not NULL*/, GR_MAYBE_UNUSED const gr_face *face, const gr_font *font)84{85assert(p);86float res = p->advancePos().y;87if (font)88return res * font->scale();89else90return res;91}9293int gr_slot_before(const gr_slot* p/*not NULL*/)94{95assert(p);96return p->before();97}9899100int gr_slot_after(const gr_slot* p/*not NULL*/)101{102assert(p);103return p->after();104}105106unsigned int gr_slot_index(const gr_slot *p/*not NULL*/)107{108assert(p);109return p->index();110}111112int gr_slot_attr(const gr_slot* p/*not NULL*/, const gr_segment* pSeg/*not NULL*/, gr_attrCode index, gr_uint8 subindex)113{114assert(p);115return p->getAttr(pSeg, index, subindex);116}117118119int gr_slot_can_insert_before(const gr_slot* p/*not NULL*/)120{121assert(p);122return (p->isInsertBefore())? 1 : 0;123}124125126int gr_slot_original(const gr_slot* p/*not NULL*/)127{128assert(p);129return p->original();130}131132void gr_slot_linebreak_before(gr_slot* p/*not NULL*/)133{134assert(p);135gr_slot *prev = (gr_slot *)p->prev();136prev->sibling(NULL);137prev->next(NULL);138p->prev(NULL);139}140141#if 0 //what should this be142size_t id(const gr_slot* p/*not NULL*/)143{144return (size_t)p->id();145}146#endif147148149} // extern "C"150151152