w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Segment.h
Go to the documentation of this file.
1 /* GRAPHITE2 LICENSING
2 
3  Copyright 2010, SIL International
4  All rights reserved.
5 
6  This library is free software; you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation; either version 2.1 of License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should also have received a copy of the GNU Lesser General Public
17  License along with this library in the file named "LICENSE".
18  If not, write to the Free Software Foundation, 51 Franklin Street,
19  Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
20  internet at http://www.fsf.org/licenses/lgpl.html.
21 
22 Alternatively, the contents of this file may be used under the terms of the
23 Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
24 License, as published by the Free Software Foundation, either version 2
25 of the License or (at your option) any later version.
26 */
27 #pragma once
28 
29 #include "inc/Main.h"
30 
31 #include <cassert>
32 
33 #include "inc/CharInfo.h"
34 #include "inc/Face.h"
35 #include "inc/FeatureVal.h"
36 #include "inc/GlyphCache.h"
37 #include "inc/GlyphFace.h"
38 #include "inc/Slot.h"
39 #include "inc/Position.h"
40 #include "inc/List.h"
41 #include "inc/Collider.h"
42 
43 #define MAX_SEG_GROWTH_FACTOR 64
44 
45 namespace graphite2 {
46 
48 typedef Vector<Slot *> SlotRope;
51 
52 class Font;
53 class Segment;
54 class Silf;
55 
57 /** sub-Segments longer than this are not cached
58  * (in Unicode code points) */
59  eMaxSpliceSize = 96
60 };
61 
62 enum justFlags {
65 };
66 
67 class SegmentScopeState
68 {
69 private:
70  friend class Segment;
71  Slot * realFirstSlot;
72  Slot * slotBeforeScope;
73  Slot * slotAfterScope;
74  Slot * realLastSlot;
75  size_t numGlyphsOutsideScope;
76 };
77 
78 class Segment
79 {
80  // Prevent copying of any kind.
81  Segment(const Segment&);
83 
84 public:
85 
86  enum {
89  };
90 
91  size_t slotCount() const { return m_numGlyphs; } //one slot per glyph
93  Position advance() const { return m_advance; }
94  bool runGraphite() { if (m_silf) return m_face->runGraphite(this, m_silf); else return true;};
96  const Silf *silf() const { return m_silf; }
97  size_t charInfoCount() const { return m_numCharinfo; }
98  const CharInfo *charinfo(unsigned int index) const { return index < m_numCharinfo ? m_charinfo + index : NULL; }
99  CharInfo *charinfo(unsigned int index) { return index < m_numCharinfo ? m_charinfo + index : NULL; }
100 
101  Segment(size_t numchars, const Face* face, uint32 script, int dir);
103  uint8 flags() const { return m_flags; }
104  void flags(uint8 f) { m_flags = f; }
105  Slot *first() { return m_first; }
106  void first(Slot *p) { m_first = p; }
107  Slot *last() { return m_last; }
108  void last(Slot *p) { m_last = p; }
109  void appendSlot(int i, int cid, int gid, int fid, size_t coffset);
111  void freeSlot(Slot *);
113  void freeJustify(SlotJustify *aJustify);
114  Position positionSlots(const Font *font=0, Slot *first=0, Slot *last=0, bool isRtl = false, bool isFinal = true);
115  void associateChars(int offset, size_t num);
118  uint16 findClassIndex(uint16 cid, uint16 gid) const { return m_silf->findClassIndex(cid, gid); }
119  int addFeatures(const Features& feats) { m_feats.push_back(feats); return int(m_feats.size()) - 1; }
120  uint32 getFeature(int index, uint8 findex) const { const FeatureRef* pFR=m_face->theSill().theFeatureMap().featureRef(findex); if (!pFR) return 0; else return pFR->getFeatureVal(m_feats[index]); }
121  void setFeature(int index, uint8 findex, uint32 val) {
122  const FeatureRef* pFR=m_face->theSill().theFeatureMap().featureRef(findex);
123  if (pFR)
124  {
125  if (val > pFR->maxVal()) val = pFR->maxVal();
127  } }
128  int8 dir() const { return m_dir; }
129  void dir(int8 val) { m_dir = val; }
130  bool currdir() const { return ((m_dir >> 6) ^ m_dir) & 1; }
131  uint8 passBits() const { return m_passBits; }
132  void mergePassBits(const uint8 val) { m_passBits &= val; }
133  int16 glyphAttr(uint16 gid, uint16 gattr) const { const GlyphFace * p = m_face->glyphs().glyphSafe(gid); return p ? p->attrs()[gattr] : 0; }
134  int32 getGlyphMetric(Slot *iSlot, uint8 metric, uint8 attrLevel, bool rtl) const;
135  float glyphAdvance(uint16 gid) const { return m_face->glyphs().glyph(gid)->theAdvance().x; }
136  const Rect &theGlyphBBoxTemporary(uint16 gid) const { return m_face->glyphs().glyph(gid)->theBBox(); } //warning value may become invalid when another glyph is accessed
137  Slot *findRoot(Slot *is) const { return is->attachedTo() ? findRoot(is->attachedTo()) : is; }
138  int numAttrs() const { return m_silf->numUser(); }
139  int defaultOriginal() const { return m_defaultOriginal; }
140  const Face * getFace() const { return m_face; }
141  const Features & getFeatures(unsigned int /*charIndex*/) { assert(m_feats.size() == 1); return m_feats[0]; }
142  void bidiPass(int paradir, uint8 aMirror);
144  void doMirror(uint16 aMirror);
145  Slot *addLineEnd(Slot *nSlot);
146  void delLineEnd(Slot *s);
147  bool hasJustification() const { return m_justifies.size() != 0; }
148  void reverseSlots();
149 
150  bool isWhitespace(const int cid) const;
151  bool hasCollisionInfo() const { return (m_flags & SEG_HASCOLLISIONS) && m_collisions; }
152  SlotCollision *collisionInfo(const Slot *s) const { return m_collisions ? m_collisions + s->index() : 0; }
154 
155 public: //only used by: GrSegment* makeAndInitialize(const GrFont *font, const GrFace *face, uint32 script, const FeaturesHandle& pFeats/*must not be IsNull*/, encform enc, const void* pStart, size_t nChars, int dir);
156  bool read_text(const Face *face, const Features* pFeats/*must not be NULL*/, gr_encform enc, const void*pStart, size_t nChars);
157  void finalise(const Font *font, bool reverse=false);
158  float justify(Slot *pSlot, const Font *font, float width, enum justFlags flags, Slot *pFirst, Slot *pLast);
160 
161 private:
162  Position m_advance; // whole segment advance
163  SlotRope m_slots; // Vector of slot buffers
164  AttributeRope m_userAttrs; // Vector of userAttrs buffers
165  JustifyRope m_justifies; // Slot justification info buffers
166  FeatureList m_feats; // feature settings referenced by charinfos in this segment
167  Slot * m_freeSlots; // linked list of free slots
168  SlotJustify * m_freeJustifies; // Slot justification blocks free list
169  CharInfo * m_charinfo; // character info, one per input character
171  const Face * m_face; // GrFace
172  const Silf * m_silf;
173  Slot * m_first; // first slot in segment
174  Slot * m_last; // last slot in segment
175  size_t m_bufSize, // how big a buffer to create when need more slots
176  m_numGlyphs,
177  m_numCharinfo; // size of the array and number of input characters
178  int m_defaultOriginal; // number of whitespace chars in the string
179  int8 m_dir;
180  uint8 m_flags, // General purpose flags
181  m_passBits; // if bit set then skip pass
182 };
183 
184 inline
186 {
187  int8 res = s->getBidiClass();
188  if (res != -1) return res;
189  res = int8(glyphAttr(s->gid(), m_silf->aBidi()));
190  s->setBidiClass(res);
191  return res;
192 }
193 
194 inline
195 void Segment::finalise(const Font *font, bool reverse)
196 {
197  if (!m_first || !m_last) return;
198 
200  //associateChars(0, m_numCharinfo);
201  if (reverse && currdir() != (m_dir & 1))
202  reverseSlots();
204 }
205 
206 inline
207 int32 Segment::getGlyphMetric(Slot *iSlot, uint8 metric, uint8 attrLevel, bool rtl) const {
208  if (attrLevel > 0)
209  {
210  Slot *is = findRoot(iSlot);
211  return is->clusterMetric(this, metric, attrLevel, rtl);
212  }
213  else
214  return m_face->getGlyphMetric(iSlot->gid(), metric);
215 }
216 
217 inline
218 bool Segment::isWhitespace(const int cid) const
219 {
220  return ((cid >= 0x0009) * (cid <= 0x000D)
221  + (cid == 0x0020)
222  + (cid == 0x0085)
223  + (cid == 0x00A0)
224  + (cid == 0x1680)
225  + (cid == 0x180E)
226  + (cid >= 0x2000) * (cid <= 0x200A)
227  + (cid == 0x2028)
228  + (cid == 0x2029)
229  + (cid == 0x202F)
230  + (cid == 0x205F)
231  + (cid == 0x3000)) != 0;
232 }
233 
234 } // namespace graphite2
235 
236 struct gr_segment : public graphite2::Segment {};
int ptrdiff_t
Definition: CPAL.d:3845
#define width(a)
Definition: aptex-macros.h:198
Definition: Font.hpp:55
Definition: vector.hh:17
int32 getGlyphMetric(uint16 gid, uint8 metric) const
Definition: Face.cpp:235
virtual bool runGraphite(Segment *seg, const Silf *silf) const
Definition: Face.cpp:163
const SillMap & theSill() const
Definition: Face.h:126
const Silf * chooseSilf(uint32 script) const
Definition: Face.cpp:220
const GlyphCache & glyphs() const
Definition: Face.h:150
const FeatureRef * featureRef(byte index) const
Definition: FeatureMap.h:142
uint32 maxVal() const
Definition: FeatureMap.h:82
bool applyValToFeature(uint32 val, Features &pDest) const
Definition: FeatureMap.cpp:270
uint32 getFeatureVal(const Features &feats) const
Definition: FeatureMap.cpp:286
const GlyphFace * glyphSafe(unsigned short glyphid) const
Definition: GlyphCache.h:154
const GlyphFace * glyph(unsigned short glyphid) const
Definition: GlyphCache.cpp:216
const Position & theAdvance() const
Definition: GlyphFace.h:79
const Rect & theBBox() const
Definition: GlyphFace.h:52
Segment & operator=(const Segment &)
Slot * last()
Definition: Segment.h:107
SlotCollision * m_collisions
Definition: Segment.h:170
void linkClusters(Slot *first, Slot *last)
Definition: Segment.cpp:259
Position positionSlots(const Font *font=0, Slot *first=0, Slot *last=0, bool isRtl=false, bool isFinal=true)
void extendLength(ptrdiff_t num)
Definition: Segment.h:92
int8 getSlotBidiClass(Slot *s) const
Definition: Segment.h:185
int numAttrs() const
Definition: Segment.h:138
size_t m_bufSize
Definition: Segment.h:175
CharInfo * charinfo(unsigned int index)
Definition: Segment.h:99
AttributeRope m_userAttrs
Definition: Segment.h:164
void associateChars(int offset, size_t num)
void setFeature(int index, uint8 findex, uint32 val)
Definition: Segment.h:121
bool hasJustification() const
Definition: Segment.h:147
SlotRope m_slots
Definition: Segment.h:163
uint32 getFeature(int index, uint8 findex) const
Definition: Segment.h:120
void dir(int8 val)
Definition: Segment.h:129
size_t slotCount() const
Definition: Segment.h:91
const CharInfo * charinfo(unsigned int index) const
Definition: Segment.h:98
uint16 findClassIndex(uint16 cid, uint16 gid) const
Definition: Segment.h:118
JustifyRope m_justifies
Definition: Segment.h:165
bool currdir() const
Definition: Segment.h:130
void appendSlot(int i, int cid, int gid, int fid, size_t coffset)
const Face * getFace() const
Definition: Segment.h:140
Position positionSlots(const Font *font=0, Slot *first=0, Slot *last=0, bool isRtl=false, bool isFinal=true)
Definition: Segment.cpp:288
uint8 passBits() const
Definition: Segment.h:131
Slot * findRoot(Slot *is) const
Definition: Segment.h:137
void delLineEnd(Slot *s)
bool hasCollisionInfo() const
Definition: Segment.h:151
void finalise(const Font *font, bool reverse=false)
size_t m_numGlyphs
Definition: Segment.h:176
void last(Slot *p)
Definition: Segment.h:108
size_t m_numCharinfo
Definition: Segment.h:177
int8 getSlotBidiClass(Slot *s) const
Position m_advance
Definition: Segment.h:162
void mergePassBits(const uint8 val)
Definition: Segment.h:132
SlotJustify * m_freeJustifies
Definition: Segment.h:168
void freeSlot(Slot *)
int32 getGlyphMetric(Slot *iSlot, uint8 metric, uint8 attrLevel, bool rtl) const
Definition: Segment.h:207
void freeJustify(SlotJustify *aJustify)
int defaultOriginal() const
Definition: Segment.h:139
void finalise(const Font *font, bool reverse=false)
Definition: Segment.h:195
void chooseSilf(uint32 script)
Definition: Segment.h:95
const Face * m_face
Definition: Segment.h:171
CharInfo * m_charinfo
Definition: Segment.h:169
size_t charInfoCount() const
Definition: Segment.h:97
FeatureList m_feats
Definition: Segment.h:166
void linkClusters(Slot *first, Slot *last)
const Features & getFeatures(unsigned int)
Definition: Segment.h:141
uint8 flags() const
Definition: Segment.h:103
float justify(Slot *pSlot, const Font *font, float width, enum justFlags flags, Slot *pFirst, Slot *pLast)
void bidiPass(int paradir, uint8 aMirror)
Slot * m_freeSlots
Definition: Segment.h:167
int addFeatures(const Features &feats)
Definition: Segment.h:119
int8 dir() const
Definition: Segment.h:128
Segment(const Segment &)
const Silf * m_silf
Definition: Segment.h:172
void first(Slot *p)
Definition: Segment.h:106
int16 glyphAttr(uint16 gid, uint16 gattr) const
Definition: Segment.h:133
bool read_text(const Face *face, const Features *pFeats, gr_encform enc, const void *pStart, size_t nChars)
const Silf * silf() const
Definition: Segment.h:96
void flags(uint8 f)
Definition: Segment.h:104
bool isWhitespace(const int cid) const
Definition: Segment.h:218
Segment(size_t numchars, const Face *face, uint32 script, int dir)
Slot * addLineEnd(Slot *nSlot)
SlotCollision * collisionInfo(const Slot *s) const
Definition: Segment.h:152
SlotJustify * newJustify()
Slot * first()
Definition: Segment.h:105
uint16 getClassGlyph(uint16 cid, uint16 offset) const
Definition: Segment.h:117
bool runGraphite()
Definition: Segment.h:94
float glyphAdvance(uint16 gid) const
Definition: Segment.h:135
bool isWhitespace(const int cid) const
void doMirror(uint16 aMirror)
Position advance() const
Definition: Segment.h:93
const Rect & theGlyphBBoxTemporary(uint16 gid) const
Definition: Segment.h:136
int32 getGlyphMetric(Slot *iSlot, uint8 metric, uint8 attrLevel, bool rtl) const
uint16 getClassGlyph(uint16 cid, unsigned int index) const
Definition: Silf.cpp:338
uint8 aBidi() const
Definition: Silf.h:87
byte dir() const
Definition: Silf.h:97
uint16 findClassIndex(uint16 cid, uint16 gid) const
Definition: Silf.cpp:312
uint8 numUser() const
Definition: Silf.h:82
const FeatureMap & theFeatureMap() const
Definition: FeatureMap.h:185
void push_back(const T &v)
Definition: List.h:91
size_t size() const
Definition: List.h:70
mpz_t * f
Definition: gen-fib.c:34
#define s
Definition: afcover.h:80
assert(pcxLoadImage24((char *)((void *) 0), fp, pinfo, hdr))
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p
Definition: afcover.h:72
small capitals from c petite p scientific i
Definition: afcover.h:80
xD9 x84 xD8 xAD xD9 x80 xF0 x90 xAC x9A xE0 xA7 xA6 xE0 xA7 xAA xF0 x91 x84 xA4 xF0 x91 x84 x89 xF0 x91 x84 x9B xF0 x90 x8A xAB xF0 x90 x8B x89 xE2 xB2 x9E xE2 xB2 x9F xD0 xBE xD0 x9E xF0 x90 x90 x84 xF0 x90 x90 xAC xE1 x83 x98 xE1 x83 x94 xE1 x83 x90 xE1 xB2 xBF xE2 xB0 x95 xE2 xB1 x85 xCE xBF xCE x9F xE0 xA8 xA0 xE0 xA8 xB0 xE0 xA9 xA6 Kayah xEA xA4 x8D xEA xA4 x80 Khmer xE1 xA7 xA1 xE1 xA7 xAA xE0 xBB x90 Latin Subscript xE2 x82 x92 xE2 x82 x80 xEA x93 xB3 xF0 x96 xB9 xA1 xF0 x96 xB9 x9B xF0 x96 xB9 xAF xE1 x80 x9D xE1 x80 x84 xE1 x80 x82 no script
Definition: afscript.h:271
FT_Face face
Definition: cffdrivr.c:659
int num
Definition: disdvi.c:621
long int32
Definition: tiff.h:67
unsigned char uint8
Definition: tiff.h:60
Definition: bits.h:30
SpliceParam
Definition: Segment.h:56
@ eMaxSpliceSize
Definition: Segment.h:59
gr_int16 int16
Definition: Main.h:43
Vector< int16 * > AttributeRope
Definition: Segment.h:49
Vector< Slot * > SlotRope
Definition: Segment.h:48
gr_int8 int8
Definition: Main.h:42
Vector< SlotJustify * > JustifyRope
Definition: Segment.h:50
gr_uint8 uint8
Definition: Main.h:38
@ gr_justEndInline
Definition: Segment.h:64
@ gr_justStartInline
Definition: Segment.h:63
Vector< Features > FeatureList
Definition: Segment.h:47
gr_uint16 uint16
Definition: Main.h:40
gr_uint32 uint32
Definition: Main.h:41
gr_int32 int32
Definition: Main.h:44
#define res(length)
Definition: picttoppm.c:287
#define index(s, c)
Definition: plain2.h:351
static boolean reverse
Definition: ppagelist.c:30
static int offset
Definition: ppmtogif.c:642
gr_encform
Definition: Types.h:39
#define CLASS_NEW_DELETE
Definition: Main.h:159
Definition: pbmfont.h:11
Definition: mendex.h:20
Definition: sh2.c:920
Definition: strexpr.c:21
#define is
Definition: tex2xindy.c:759
val
Definition: tex4ht.c:3227
return() int(((double) *(font_tbl[cur_fnt].wtbl+(int)(*(font_tbl[cur_fnt].char_wi+(int)(ch - font_tbl[cur_fnt].char_f)% 256)))/(double)(1L<< 20)) *(double) font_tbl[cur_fnt].scale)