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)  

gr_segment.cpp
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 #include "graphite2/Segment.h"
28 #include "inc/UtfCodec.h"
29 #include "inc/Segment.h"
30 
31 using namespace graphite2;
32 
33 namespace
34 {
35 
36  gr_segment* makeAndInitialize(const Font *font, const Face *face, uint32 script, const Features* pFeats/*must not be NULL*/, gr_encform enc, const void* pStart, size_t nChars, int dir)
37  {
38  if (script == 0x20202020) script = 0;
39  else if ((script & 0x00FFFFFF) == 0x00202020) script = script & 0xFF000000;
40  else if ((script & 0x0000FFFF) == 0x00002020) script = script & 0xFFFF0000;
41  else if ((script & 0x000000FF) == 0x00000020) script = script & 0xFFFFFF00;
42  // if (!font) return NULL;
43  Segment* pRes=new Segment(nChars, face, script, dir);
44 
45 
46  if (!pRes->read_text(face, pFeats, enc, pStart, nChars) || !pRes->runGraphite())
47  {
48  delete pRes;
49  return NULL;
50  }
51  pRes->finalise(font, true);
52 
53  return static_cast<gr_segment*>(pRes);
54  }
55 
56  template <typename utf_iter>
57  inline size_t count_unicode_chars(utf_iter first, const utf_iter last, const void **error)
58  {
59  size_t n_chars = 0;
60  uint32 usv = 0;
61 
62  if (last)
63  {
64  if (!first.validate(last))
65  {
66  if (error) *error = last - 1;
67  return 0;
68  }
69  for (;first != last; ++first, ++n_chars)
70  if ((usv = *first) == 0 || first.error()) break;
71  }
72  else
73  {
74  while ((usv = *first) != 0 && !first.error())
75  {
76  ++first;
77  ++n_chars;
78  }
79  }
80 
81  if (error) *error = first.error() ? first : 0;
82  return n_chars;
83  }
84 }
85 
86 
87 extern "C" {
88 
89 size_t gr_count_unicode_characters(gr_encform enc, const void* buffer_begin, const void* buffer_end/*don't go on or past end, If NULL then ignored*/, const void** pError) //Also stops on nul. Any nul is not in the count
90 {
91  assert(buffer_begin);
92 
93  switch (enc)
94  {
95  case gr_utf8: return count_unicode_chars<utf8::const_iterator>(buffer_begin, buffer_end, pError); break;
96  case gr_utf16: return count_unicode_chars<utf16::const_iterator>(buffer_begin, buffer_end, pError); break;
97  case gr_utf32: return count_unicode_chars<utf32::const_iterator>(buffer_begin, buffer_end, pError); break;
98  default: return 0;
99  }
100 }
101 
102 
103 gr_segment* gr_make_seg(const gr_font *font, const gr_face *face, gr_uint32 script, const gr_feature_val* pFeats, gr_encform enc, const void* pStart, size_t nChars, int dir)
104 {
105  if (!face) return nullptr;
106 
107  const gr_feature_val * tmp_feats = 0;
108  if (pFeats == 0)
109  pFeats = tmp_feats = static_cast<const gr_feature_val*>(face->theSill().cloneFeatures(0));
110  gr_segment * seg = makeAndInitialize(font, face, script, pFeats, enc, pStart, nChars, dir);
111  delete static_cast<const FeatureVal*>(tmp_feats);
112 
113  return seg;
114 }
115 
116 
118 {
119  delete static_cast<Segment*>(p);
120 }
121 
122 
123 float gr_seg_advance_X(const gr_segment* pSeg/*not NULL*/)
124 {
125  assert(pSeg);
126  return pSeg->advance().x;
127 }
128 
129 
130 float gr_seg_advance_Y(const gr_segment* pSeg/*not NULL*/)
131 {
132  assert(pSeg);
133  return pSeg->advance().y;
134 }
135 
136 
137 unsigned int gr_seg_n_cinfo(const gr_segment* pSeg/*not NULL*/)
138 {
139  assert(pSeg);
140  return static_cast<unsigned int>(pSeg->charInfoCount());
141 }
142 
143 
144 const gr_char_info* gr_seg_cinfo(const gr_segment* pSeg/*not NULL*/, unsigned int index/*must be <number_of_CharInfo*/)
145 {
146  assert(pSeg);
147  return static_cast<const gr_char_info*>(pSeg->charinfo(index));
148 }
149 
150 unsigned int gr_seg_n_slots(const gr_segment* pSeg/*not NULL*/)
151 {
152  assert(pSeg);
153  return static_cast<unsigned int>(pSeg->slotCount());
154 }
155 
156 const gr_slot* gr_seg_first_slot(gr_segment* pSeg/*not NULL*/)
157 {
158  assert(pSeg);
159  return static_cast<const gr_slot*>(pSeg->first());
160 }
161 
162 const gr_slot* gr_seg_last_slot(gr_segment* pSeg/*not NULL*/)
163 {
164  assert(pSeg);
165  return static_cast<const gr_slot*>(pSeg->last());
166 }
167 
168 float gr_seg_justify(gr_segment* pSeg/*not NULL*/, const gr_slot* pSlot/*not NULL*/, const gr_font *pFont, double width, enum gr_justFlags flags, const gr_slot *pFirst, const gr_slot *pLast)
169 {
170  assert(pSeg);
171  assert(pSlot);
172  return pSeg->justify(const_cast<gr_slot *>(pSlot), pFont, float(width), justFlags(flags), const_cast<gr_slot *>(pFirst), const_cast<gr_slot *>(pLast));
173 }
174 
175 } // extern "C"
#define width(a)
Definition: aptex-macros.h:198
Slot * last()
Definition: Segment.h:107
float justify(Slot *pSlot, const Font *font, float width, enum justFlags flags, Slot *pFirst, Slot *pLast)
Definition: Justifier.cpp:63
size_t slotCount() const
Definition: Segment.h:91
const CharInfo * charinfo(unsigned int index) const
Definition: Segment.h:98
void finalise(const Font *font, bool reverse=false)
Definition: Segment.h:195
bool read_text(const Face *face, const Features *pFeats, gr_encform enc, const void *pStart, size_t nChars)
Definition: Segment.cpp:385
size_t charInfoCount() const
Definition: Segment.h:97
Slot * first()
Definition: Segment.h:105
bool runGraphite()
Definition: Segment.h:94
Position advance() const
Definition: Segment.h:93
#define error(a)
Definition: dviinfo.c:48
assert(pcxLoadImage24((char *)((void *) 0), fp, pinfo, hdr))
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p
Definition: afcover.h:72
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
char * buffer_end
Definition: cwebboot.c:308
unsigned long uint32
Definition: tiff.h:68
Definition: bits.h:30
static int32_t last
Definition: ppagelist.c:29
static int32_t first
Definition: ppagelist.c:29
gr_justFlags
Definition: Segment.h:53
gr_encform
Definition: Types.h:39
@ gr_utf16
Definition: Types.h:40
@ gr_utf32
Definition: Types.h:40
@ gr_utf8
Definition: Types.h:40
unsigned int gr_uint32
Definition: Types.h:36
#define dir
#define seg
#define flags
float gr_seg_advance_Y(const gr_segment *pSeg)
Definition: gr_segment.cpp:130
float gr_seg_advance_X(const gr_segment *pSeg)
Definition: gr_segment.cpp:123
const gr_slot * gr_seg_last_slot(gr_segment *pSeg)
Definition: gr_segment.cpp:162
const gr_slot * gr_seg_first_slot(gr_segment *pSeg)
Definition: gr_segment.cpp:156
void gr_seg_destroy(gr_segment *p)
Definition: gr_segment.cpp:117
float gr_seg_justify(gr_segment *pSeg, const gr_slot *pSlot, const gr_font *pFont, double width, enum gr_justFlags flags, const gr_slot *pFirst, const gr_slot *pLast)
Definition: gr_segment.cpp:168
gr_segment * gr_make_seg(const gr_font *font, const gr_face *face, gr_uint32 script, const gr_feature_val *pFeats, gr_encform enc, const void *pStart, size_t nChars, int dir)
Definition: gr_segment.cpp:103
const gr_char_info * gr_seg_cinfo(const gr_segment *pSeg, unsigned int index)
Definition: gr_segment.cpp:144
unsigned int gr_seg_n_slots(const gr_segment *pSeg)
Definition: gr_segment.cpp:150
unsigned int gr_seg_n_cinfo(const gr_segment *pSeg)
Definition: gr_segment.cpp:137
size_t gr_count_unicode_characters(gr_encform enc, const void *buffer_begin, const void *buffer_end, const void **pError)
Definition: gr_segment.cpp:89
Definition: pbmfont.h:11
Definition: Face.h:225
Definition: Font.h:90
Definition: Slot.h:170
Definition: mendex.h:20
Definition: gd.c:2418