gfx/graphite2/src/gr_slot.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 #include "graphite2/Segment.h"
michael@0 28 #include "inc/Segment.h"
michael@0 29 #include "inc/Slot.h"
michael@0 30 #include "inc/Font.h"
michael@0 31
michael@0 32
michael@0 33 extern "C" {
michael@0 34
michael@0 35
michael@0 36 const gr_slot* gr_slot_next_in_segment(const gr_slot* p/*not NULL*/)
michael@0 37 {
michael@0 38 assert(p);
michael@0 39 return static_cast<const gr_slot*>(p->next());
michael@0 40 }
michael@0 41
michael@0 42 const gr_slot* gr_slot_prev_in_segment(const gr_slot* p/*not NULL*/)
michael@0 43 {
michael@0 44 assert(p);
michael@0 45 return static_cast<const gr_slot*>(p->prev());
michael@0 46 }
michael@0 47
michael@0 48 const 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 base
michael@0 49 {
michael@0 50 assert(p);
michael@0 51 return static_cast<const gr_slot*>(p->attachedTo());
michael@0 52 }
michael@0 53
michael@0 54
michael@0 55 const gr_slot* gr_slot_first_attachment(const gr_slot* p/*not NULL*/) //returns NULL iff no attachments.
michael@0 56 { //if slot_first_attachment(p) is not NULL, then slot_attached_to(slot_first_attachment(p))==p.
michael@0 57 assert(p);
michael@0 58 return static_cast<const gr_slot*>(p->firstChild());
michael@0 59 }
michael@0 60
michael@0 61
michael@0 62 const gr_slot* gr_slot_next_sibling_attachment(const gr_slot* p/*not NULL*/) //returns NULL iff no more attachments.
michael@0 63 { //if slot_next_sibling_attachment(p) is not NULL, then slot_attached_to(slot_next_sibling_attachment(p))==slot_attached_to(p).
michael@0 64 assert(p);
michael@0 65 return static_cast<const gr_slot*>(p->nextSibling());
michael@0 66 }
michael@0 67
michael@0 68
michael@0 69 unsigned short gr_slot_gid(const gr_slot* p/*not NULL*/)
michael@0 70 {
michael@0 71 assert(p);
michael@0 72 return p->glyph();
michael@0 73 }
michael@0 74
michael@0 75
michael@0 76 float gr_slot_origin_X(const gr_slot* p/*not NULL*/)
michael@0 77 {
michael@0 78 assert(p);
michael@0 79 return p->origin().x;
michael@0 80 }
michael@0 81
michael@0 82
michael@0 83 float gr_slot_origin_Y(const gr_slot* p/*not NULL*/)
michael@0 84 {
michael@0 85 assert(p);
michael@0 86 return p->origin().y;
michael@0 87 }
michael@0 88
michael@0 89
michael@0 90 float gr_slot_advance_X(const gr_slot* p/*not NULL*/, const gr_face *face, const gr_font *font)
michael@0 91 {
michael@0 92 assert(p);
michael@0 93 float scale = 1.0;
michael@0 94 float res = p->advance();
michael@0 95 if (font)
michael@0 96 {
michael@0 97 scale = font->scale();
michael@0 98 if (face && font->isHinted())
michael@0 99 res = (res - face->glyphs().glyph(p->gid())->theAdvance().x) * scale + font->advance(p->gid());
michael@0 100 else
michael@0 101 res = res * scale;
michael@0 102 }
michael@0 103 return res;
michael@0 104 }
michael@0 105
michael@0 106 float gr_slot_advance_Y(const gr_slot *p/*not NULL*/, const gr_face *face, const gr_font *font)
michael@0 107 {
michael@0 108 assert(p);
michael@0 109 float res = p->advancePos().y;
michael@0 110 if (font && (face || !face))
michael@0 111 return res * font->scale();
michael@0 112 else
michael@0 113 return res;
michael@0 114 }
michael@0 115
michael@0 116 int gr_slot_before(const gr_slot* p/*not NULL*/)
michael@0 117 {
michael@0 118 assert(p);
michael@0 119 return p->before();
michael@0 120 }
michael@0 121
michael@0 122
michael@0 123 int gr_slot_after(const gr_slot* p/*not NULL*/)
michael@0 124 {
michael@0 125 assert(p);
michael@0 126 return p->after();
michael@0 127 }
michael@0 128
michael@0 129 unsigned int gr_slot_index(const gr_slot *p/*not NULL*/)
michael@0 130 {
michael@0 131 assert(p);
michael@0 132 return p->index();
michael@0 133 }
michael@0 134
michael@0 135 int gr_slot_attr(const gr_slot* p/*not NULL*/, const gr_segment* pSeg/*not NULL*/, gr_attrCode index, gr_uint8 subindex)
michael@0 136 {
michael@0 137 assert(p);
michael@0 138 return p->getAttr(pSeg, index, subindex);
michael@0 139 }
michael@0 140
michael@0 141
michael@0 142 int gr_slot_can_insert_before(const gr_slot* p/*not NULL*/)
michael@0 143 {
michael@0 144 assert(p);
michael@0 145 return (p->isInsertBefore())? 1 : 0;
michael@0 146 }
michael@0 147
michael@0 148
michael@0 149 int gr_slot_original(const gr_slot* p/*not NULL*/)
michael@0 150 {
michael@0 151 assert(p);
michael@0 152 return p->original();
michael@0 153 }
michael@0 154
michael@0 155 void gr_slot_linebreak_before(gr_slot* p/*not NULL*/)
michael@0 156 {
michael@0 157 assert(p);
michael@0 158 gr_slot *prev = (gr_slot *)p->prev();
michael@0 159 prev->sibling(NULL);
michael@0 160 prev->next(NULL);
michael@0 161 p->prev(NULL);
michael@0 162 }
michael@0 163
michael@0 164 #if 0 //what should this be
michael@0 165 size_t id(const gr_slot* p/*not NULL*/)
michael@0 166 {
michael@0 167 return (size_t)p->id();
michael@0 168 }
michael@0 169 #endif
michael@0 170
michael@0 171
michael@0 172 } // extern "C"
michael@0 173

mercurial