Debian Codegraph @

contrib/C#/NGraphite/Graphite2Api.cs

raw
1 // SPDX-License-Identifier: MIT OR MPL-2.0 OR LGPL-2.1-or-later OR GPL-2.0-or-later
2 // Copyright (C) 2012 SIL International
3 using System;
4 using System.Runtime.InteropServices;
5 using System.Text;
6
7 namespace NGraphite
8 {
9 public class Graphite2Api
10 {
11 public Graphite2Api()
12 {
13 }
14
15 #region Font methods
16 /// <summary>
17 /// Returns version information on this engine
18 /// </summary>
19 [DllImport("graphite2.dll", EntryPoint="gr_engine_version")]
20 internal static extern void EngineVersion(out int nMajor, out int nMinor, out int nBugFix);
21
22 /// <summary>
23 /// type describing function to retrieve font table information
24 /// </summary>
25 internal delegate /*gr_face*/ IntPtr GetTableFn(IntPtr appFaceHandle, uint name, out int len);
26
27 /// <summary>
28 /// Create a gr_face object given application information and a getTable function
29 /// </summary>
30 /// <returns>
31 /// gr_face or NULL if the font fails to load for some reason.
32 /// </returns>
33 /// <param name='appFaceHandle'>
34 /// This is application specific information that is passed to the getTable
35 /// function. The appFaceHandle must stay alive as long as the gr_face is alive.
36 /// </param>
37 /// <param name='getTable'>
38 /// This function is called whenever graphite needs access to a table of data
39 /// in the font.
40 /// </param>
41 /// <param name='faceOptions'>
42 /// Bitfield describing various options. See enum gr_face_options for details.
43 /// </param>
44 [DllImport("graphite2.dll", EntryPoint="gr_make_face")]
45 internal static extern /*gr_face*/ IntPtr MakeFace(IntPtr appFaceHandle, GetTableFn getTable, uint faceOptions);
46
47 // This only exists if GRAPHITE2_NSEGCACHE was not defined when graphite was compiled.
48 /// <summary>
49 /// Create a gr_face object given application information, with subsegmental caching support
50 /// </summary>
51 /// <returns>
52 /// gr_face or NULL if the font fails to load.
53 /// </returns>
54 /// <param name='appFaceHandle'>
55 /// is a pointer to application specific information that is passed to getTable.
56 /// This may not be NULL and must stay alive as long as the gr_face is alive.
57 /// </param>
58 /// <param name='getTable'>
59 /// The function graphite calls to access font table data
60 /// </param>
61 /// <param name='segCacheMaxSize'>
62 /// How large the segment cache is.
63 /// </param>
64 /// <param name='faceOptions'>
65 /// Bitfield of values from enum gr_face_options
66 /// </param>
67 [DllImport("graphite2.dll", EntryPoint="gr_make_face_with_seg_cache")]
68 internal static extern /*gr_face*/ IntPtr MakeFaceWithSegCache(IntPtr appFaceHandle, GetTableFn getTable, uint segCacheMaxSize, uint faceOptions);
69
70 /// <summary>
71 /// Convert a tag in a string into a gr_uint32
72 /// </summary>
73 /// <returns>
74 /// gr_uint32 tag, zero padded
75 /// </returns>
76 /// <param name='str'>
77 /// str a nul terminated string of which at most the first 4 characters are read
78 /// </param>
79 [DllImport("graphite2.dll", EntryPoint="gr_str_to_tag")]
80 internal static extern UInt32 StrToTag(string str);
81
82 /// <summary>
83 /// Convert a gr_uint32 tag into a string
84 /// </summary>
85 /// <param name='tag'>
86 /// contains the tag to convert
87 /// </param>
88 /// <param name='str'>
89 /// is a pointer to a char array of at least size 4 bytes. The first 4 bytes of this array
90 /// will be overwritten by this function. No nul is appended.
91 /// </param>
92 [DllImport("graphite2.dll", EntryPoint="gr_tag_to_str")]
93 internal static extern void TagToStr(UInt32 tag, IntPtr str);
94
95 /// <summary>
96 /// Get feature values for a given language or default
97 /// </summary>
98 /// <returns>
99 /// a copy of the default feature values for a given language. The application must call
100 /// gr_featureval_destroy() to free this object when done.
101 /// </returns>
102 /// <param name='pFace'>
103 /// The font face to get feature values from
104 /// </param>
105 /// <param name='langname'>
106 /// The language tag to get feature values for. If there is no such language or
107 /// langname is 0, the default feature values for the font are returned.
108 /// langname is right 0 padded and assumes lowercase. Thus the en langauge
109 /// would be 0x656E0000. Langname may also be space padded, thus 0x656E2020.
110 /// </param>
111 [DllImport("graphite2.dll", EntryPoint="gr_face_featureval_for_lang")]
112 internal static extern /*gr_feature_val */ IntPtr FaceFeaturevalForLang(/* gr_face */ IntPtr pFace, UInt32 langname);
113
114 /// <summary>
115 /// Get feature reference for a given feature id from a face
116 /// </summary>
117 /// <returns>
118 /// a feature reference corresponding to the given id. This data is part of the gr_face and
119 /// will be freed when the face is destroyed.
120 /// </returns>
121 /// <param name='pFace'>
122 /// Font face to get information on.
123 /// </param>
124 /// <param name='featid'>
125 /// Feature id tag to get reference to.
126 /// </param>
127 [DllImport("graphite2.dll", EntryPoint="gr_face_find_fref")]
128 internal static extern /* gr_feature_ref*/ IntPtr FaceFindFref(/* gr_face */ IntPtr pFace, Int32 featid);
129
130 /// <summary>
131 /// Returns number of feature references in a face
132 /// </summary>
133 [DllImport("graphite2.dll", EntryPoint="gr_face_n_fref")]
134 internal static extern UInt16 FaceNFref(/* gr_face */ IntPtr pFace);
135
136 /// <summary>
137 /// Returns feature reference at given index in face
138 /// </summary>
139 [DllImport("graphite2.dll", EntryPoint="gr_face_fref")]
140 internal static extern /* gr_feature_ref */ IntPtr FaceFref(/*gr_face*/ IntPtr pFace, UInt16 i);
141
142 /// <summary>
143 /// Return number of languages the face knows about
144 /// </summary>
145 [DllImport("graphite2.dll", EntryPoint="gr_face_n_languages")]
146 internal static extern ushort FaceNLanguages(/*gr_face*/ IntPtr pFace);
147
148 /// <summary>
149 /// Returns a language id corresponding to a language of given index in the face
150 /// </summary>
151 [DllImport("graphite2.dll", EntryPoint="gr_face_lang_by_index")]
152 internal static extern UInt32 FaceLangByIndex(/*gr_face*/ IntPtr pFace, UInt16 i);
153
154 /// <summary>
155 /// Destroy the given face and free its memory
156 /// </summary>
157 [DllImport("graphite2.dll", EntryPoint="gr_face_destroy")]
158 internal static extern void FaceDestroy(/*gr_face*/ IntPtr pFace);
159
160 /// <summary>
161 /// Returns the number of glyphs in the face
162 /// </summary>
163 [DllImport("graphite2.dll", EntryPoint="gr_face_n_glyphs")]
164 internal static extern short FaceNGlyphs(/*gr_face*/ IntPtr pFace);
165
166
167 // Only exists if GRAPHITE2_NFILEFACE was not defined when libgraphite2 was compiled
168 /// <summary>
169 /// Create gr_face from a font file
170 /// </summary>
171 /// <returns>
172 /// gr_face that accesses a font file directly. Returns NULL on failure.
173 /// </returns>
174 /// <param name='filename'>
175 /// Full path and filename to font file
176 /// </param>
177 /// <param name='faceOptions'>
178 /// Bitfile from enum gr_face_options to control face options.
179 /// </param>
180 [DllImport("graphite2.dll", EntryPoint="gr_make_file_face")]
181 internal static extern /*gr_face*/ IntPtr MakeFileFace(string filename, FaceOptions faceOptions);
182
183 // Only exists if GRAPHITE2_NFILEFACE was not defined when libgraphite2 was compiled
184 /// <summary>
185 /// Create gr_face from a font file, with subsegment caching support.
186 /// </summary>
187 /// <returns>
188 /// gr_face that accesses a font file directly. Returns NULL on failure.
189 /// </returns>
190 /// <param name='filename'>
191 /// Full path and filename to font file
192 /// </param>
193 /// <param name='segCacheMaxSize'>
194 /// Specifies how big to make the cache in segments.
195 /// </param>
196 /// <param name='faceOptions'>
197 /// Bitfield from enum gr_face_options to control face options.
198 /// </param>
199 [DllImport("graphite2.dll", EntryPoint="gr_make_file_face_with_seg_cache")]
200 internal static extern /*gr_face*/ IntPtr MakeFileFaceWithSegCache(string filename, uint segCacheMaxSize, FaceOptions faceOptions);
201
202 /// <summary>
203 /// Create a font from a face
204 /// </summary>
205 /// <returns>
206 /// gr_font Call font_destroy to free this font
207 /// </returns>
208 /// <param name='ppm'>
209 /// Resolution of the font in pixels per em
210 /// </param>
211 /// <param name='face'>
212 /// Face this font corresponds to. This must stay alive as long as the font is alive.
213 /// </param>
214 [DllImport("graphite2.dll", EntryPoint="gr_make_font")]
215 internal static extern /*gr_font*/ IntPtr MakeFont(float ppm, /*gr_face*/ IntPtr face);
216
217 /// <summary>
218 /// query function to find the hinted advance width of a glyph
219 /// </summary>
220 internal delegate float AdvanceFn(IntPtr appFontHandle, UInt16 glyphid);
221
222 /// <summary>
223 /// Creates a font with hinted advance width query function
224 /// </summary>
225 /// <returns>
226 /// gr_font to be destroyed via font_destroy
227 /// </returns>
228 /// <param name='ppm'>
229 /// size of font in pixels per em
230 /// </param>
231 /// <param name='appFontHandle'>
232 /// font specific information that must stay alive as long as the font does
233 /// </param>
234 /// <param name='advance'>
235 /// function to call with appFontHandle and glyphid to get horizontal advance in pixels.
236 /// </param>
237 /// <param name='face'>
238 /// the face this font corresponds to. Must stay alive as long as the font does.
239 /// </param>
240 [DllImport("graphite2.dll", EntryPoint="gr_make_font_with_advance_fn")]
241 internal static extern /*gr_font*/ IntPtr MakeFontWithAdvanceFn(float ppm, IntPtr appFontHandle, AdvanceFn advance, /*gr_face*/IntPtr face);
242
243 /// <summary>
244 /// Free a font
245 /// </summary>
246 [DllImport("graphite2.dll", EntryPoint="gr_font_destroy")]
247 internal static extern void FontDestroy(/*gr_font*/ IntPtr font);
248
249 /// <summary>
250 /// get a feature value
251 /// </summary>
252 /// <returns>
253 /// value of specific feature or 0 if any problems.
254 /// </returns>
255 /// <param name='pfeatureref'>
256 /// gr_feature_ref to the feature
257 /// </param>
258 /// <param name='feats'>
259 /// containing all the values
260 /// </param>
261 [DllImport("graphite2.dll", EntryPoint="gr_fref_feature_value")]
262 internal static extern UInt16 FrefFeatureValue(/*gr_feature_ref*/ IntPtr pfeatureref, /*gr_feature_val*/IntPtr feats);
263
264 /// <summary>
265 /// set a feature value
266 /// </summary>
267 /// <returns>
268 /// false if there were any problems (value out of range, etc.)
269 /// </returns>
270 /// <param name='pfeatureref'>
271 /// gr_feature_ref to the feature
272 /// </param>
273 /// <param name='val'>
274 /// value to set the feature to
275 /// </param>
276 /// <param name='pDest'>
277 /// the gr_feature_val containing all the values for all the features
278 /// </param>
279 [DllImport("graphite2.dll", EntryPoint="gr_fref_set_feature_value")]
280 internal static extern int FrefSetFeatureValue(/*gr_feature_ref*/ IntPtr pfeatureref, UInt16 val, /*gr_feature_val*/IntPtr pDest);
281
282 /// <summary>
283 /// Returns the id tag for a gr_feature_ref
284 /// </summary>
285 [DllImport("graphite2.dll", EntryPoint="gr_fref_id")]
286 internal static extern UInt32 FrefId(/*gr_feature_ref*/ IntPtr pfeatureref);
287
288 /// <summary>
289 /// Returns number of values a feature may take, given a gr_feature_ref.
290 /// </summary>
291 [DllImport("graphite2.dll", EntryPoint="gr_fref_n_values")]
292 internal static extern UInt16 FrefNValues(/*gr_feature_ref*/ IntPtr pfeatureref);
293
294 /// <summary>
295 /// Returns the value associated with a particular value in a feature
296 /// </summary>
297 /// <returns>
298 /// value.
299 /// </returns>
300 /// <param name='pfeatureref'>
301 /// gr_feature_ref of the feature of interest
302 /// </param>
303 /// <param name='settingno'>
304 /// Index up to the return value of gr_fref_n_values() of the value
305 /// </param>
306 [DllImport("graphite2.dll", EntryPoint="gr_fref_value")]
307 internal static extern UInt16 FrefValue(/*gr_feature_ref*/ IntPtr pfeatureref, UInt16 settingno);
308
309 /// <summary>
310 /// Returns a string of the UI name of a feature
311 /// </summary>
312 /// <returns>
313 /// string of the UI name, in the encoding form requested. Call gr_label_destroy() after use.
314 /// </returns>
315 /// <param name='pfeatureref'>
316 /// gr_feature_ref of the feature
317 /// </param>
318 /// <param name='langid'>
319 /// This is a pointer since the face may not support a string in the requested
320 /// language. The actual language of the string is returned in langId
321 /// </param>
322 /// <param name='utf'>
323 /// Encoding form for the string
324 /// </param>
325 /// <param name='length'>
326 /// Used to return the length of the string returned in bytes.
327 /// </param>
328 [DllImport("graphite2.dll", EntryPoint="gr_fref_label", CharSet = CharSet.Ansi)]
329 internal static extern IntPtr FrefLabel(/*gr_feature_ref*/ IntPtr pfeatureref, ref UInt16 langid, Encform utf, out UInt32 length);
330
331 /// <summary>
332 /// Return a UI string for a possible value of a feature
333 /// </summary>
334 /// <returns>
335 /// string of the UI name, in the encoding form requested. nul terminated. Call gr_label_destroy()
336 /// after use.
337 /// </returns>
338 /// <param name='pfeatureref'>
339 /// gr_feature_ref of the feature
340 /// </param>
341 /// <param name='settingsno'>
342 /// Value setting index
343 /// </param>
344 /// <param name='langId'>
345 /// This is a pointer to the requested language. The requested language id is
346 /// replaced by the actual language id of the string returned.
347 /// </param>
348 /// <param name='utf'>
349 /// Encoding form for the string
350 /// </param>
351 /// <param name='length'>
352 /// Returns the length of the string returned in bytes.
353 /// </param>
354 [DllImport("graphite2.dll", EntryPoint="gr_fref_value_label")]
355 internal static extern IntPtr FrefValueLabel(/*gr_feature_ref*/ IntPtr pfeatureref, UInt16 settingsno, ref UInt16 langId, Encform utf, out UInt32 length);
356
357 /// <summary>
358 /// Destroy a previously returned label string
359 /// </summary>
360 [DllImport("graphite2.dll", EntryPoint="gr_label_destroy")]
361 internal static extern void LabelDestroy(IntPtr label);
362
363 /// <summary>
364 /// Copies a gr_feature_val
365 /// </summary>
366 [DllImport("graphite2.dll", EntryPoint="gr_featureval_clone")]
367 internal static extern /*gr_feature_val*/ IntPtr FeaturevalClone(/*gr_feature_val*/ IntPtr pfeatures);
368
369 /// <summary>
370 /// Destroys a gr_feature_val
371 /// </summary>
372 [DllImport("graphite2.dll", EntryPoint="gr_featureval_destroy")]
373 internal static extern void FeatureValDestroy(/*gr_feature_val*/ IntPtr pfeatures);
374
375 #endregion
376
377 #region Segment methods
378
379 /// <summary>
380 /// Returns Unicode character for a charinfo.
381 /// </summary>
382 /// <param name='p'>
383 /// Pointer to charinfo to return information on.
384 /// </param>
385 [DllImport("graphite2.dll", EntryPoint="gr_cinfo_unicode_char")]
386 internal static extern UInt32 CinfoUnicodeChar(/*gr_char_info**/ IntPtr p/*not NULL*/);
387
388 /// <summary>
389 /// Returns breakweight for a charinfo.
390 /// </summary>
391 /// <returns>
392 /// Breakweight is a number between -50 and 50 indicating the cost of a
393 /// break before or after this character.
394 /// </returns>
395 /// <param name='p'>
396 /// Pointer to charinfo to return information on.
397 /// </param>
398 [DllImport("graphite2.dll", EntryPoint="gr_cinfo_break_weight")]
399 internal static extern int CinfoBreakWeight(/*gr_char_info**/ IntPtr p/*not NULL*/);
400
401 /// <summary>
402 /// Returns the slot index that after this character is after in the slot stream
403 /// </summary>
404 /// <returns>
405 /// after slot index between 0 and gr_seg_n_slots()
406 /// </returns>
407 /// <param name='p'>
408 /// Pointer to charinfo to return information on.
409 /// </param>
410 [DllImport("graphite2.dll", EntryPoint="gr_cinfo_after")]
411 internal static extern int CinfoAfter(/*gr_char_info**/IntPtr p/*not NULL*/);
412
413 /// <summary>
414 /// Returns the slot index that before this character is before in the slot stream
415 /// </summary>
416 /// <returns>
417 /// before slot index between 0 and gr_seg_n_slots()
418 /// </returns>
419 /// <param name='p'>
420 /// Pointer to charinfo to return information on.
421 /// </param>
422 [DllImport("graphite2.dll", EntryPoint="gr_cinfo_before")]
423 internal static extern int CinfoBefore(/*gr_char_info**/IntPtr p/*not NULL*/);
424
425 /// <summary>
426 /// Returns the code unit index of this character in the input string
427 /// </summary>
428 /// <returns>
429 /// code unit index between 0 and the end of the string
430 /// </returns>
431 /// <param name='p'>
432 /// Pointer to charinfo to return information on.
433 /// </param>
434 [DllImport("graphite2.dll", EntryPoint="gr_cinfo_base")]
435 internal static extern int CinfoBase(/*gr_char_info**/IntPtr p/*not NULL*/);
436
437 /// <summary>
438 /// Returns the number of unicode characters in a string.
439 /// </summary>
440 /// <returns>
441 /// number of characters in the string
442 /// </returns>
443 /// <param name='enc'>
444 /// the type of data in the string: utf8, utf16, utf32
445 /// </param>
446 /// <param name='buffer_begin'>
447 /// The start of the string
448 /// </param>
449 /// <param name='buffer_end'>
450 /// Measure up to the first nul or when end is reached, whichever is earliest.
451 /// This parameter may be NULL.
452 /// </param>
453 /// <param name='pError'>
454 /// If there is a structural fault in the string, the location is returned
455 /// in this variable. If no error occurs, pError will contain NULL. NULL
456 /// may be passed for pError if no such information is required.
457 /// </param>
458 [DllImport("graphite2.dll", EntryPoint="gr_count_unicode_characters")]
459 internal static extern int CountUnicodeCharacters(Encform enc, IntPtr buffer_begin, IntPtr buffer_end, ref IntPtr pError);
460
461 /// <summary>
462 /// Creates and returns a segment.
463 /// </summary>
464 /// <returns>
465 /// a segment that needs seg_destroy called on it. May return NULL if bad problems
466 /// in segment processing.
467 /// </returns>
468 /// <param name='font'>
469 /// Gives the size of the font in pixels per em for final positioning. If
470 /// NULL, positions are returned in design units, i.e. at a ppm of the upem
471 /// of the face.
472 /// </param>
473 /// <param name='face'>
474 /// The face containing all the non-size dependent information.
475 /// </param>
476 /// <param name='script'>
477 /// This is a tag containing a script identifier that is used to choose
478 /// which graphite table within the font to use. Maybe 0. Tag may be 4 chars
479 /// NULL padded in LSBs or space padded in LSBs.
480 /// </param>
481 /// <param name='pFeats'>
482 /// Pointer to a feature values to be used for the segment. Only one
483 /// feature values may be used for a segment. If NULL the default features
484 /// for the font will be used.
485 /// </param>
486 /// <param name='enc'>
487 /// Specifies what encoding form the string is in (utf8, utf16, utf32)
488 /// </param>
489 /// <param name='pStart'>
490 /// Start of the string
491 /// </param>
492 /// <param name='nChars'>
493 /// Number of unicode characters to process in the string. The string will
494 /// be processed either up to the first NULL or until nChars have been
495 /// processed. nChars is also used to initialise the internal memory
496 /// allocations of the segment. So it is wise not to make nChars too much
497 /// greater than the actual number of characters being processed.
498 /// </param>
499 /// <param name='dir'>
500 /// Specifies whether the segment is processed right to left (1) or left to
501 /// right (0) and whether to run the internal bidi pass, if a font requests it.
502 /// See enum gr_bidirtl for details.
503 /// </param>
504 [DllImport("graphite2.dll", EntryPoint="gr_make_seg")]
505 internal static extern /*gr_segment**/IntPtr MakeSeg(/*gr_font**/IntPtr font, /*gr_face**/IntPtr face, UInt32 script, /*gr_feature_val**/IntPtr pFeats, Encform enc, IntPtr pStart, int nChars, Bidirtl dir);
506
507 /// <summary>
508 /// Destroys a segment, freeing the memory.
509 /// </summary>
510 /// <param name='p'>
511 /// The segment to destroy
512 /// </param>
513 [DllImport("graphite2.dll", EntryPoint="gr_seg_destroy")]
514 internal static extern void SegDestroy(/*gr_segment**/IntPtr p);
515
516 /// <summary>
517 /// Returns the advance for the whole segment.
518 /// </summary>
519 /// <returns>
520 /// Returns the width of the segment up to the next glyph origin after the segment
521 /// </returns>
522 [DllImport("graphite2.dll", EntryPoint="gr_seg_advance_X")]
523 internal static extern float SegAdvanceX(/*gr_segment**/IntPtr pSeg/*not NULL*/);
524
525 /// <summary>
526 /// Returns the height advance for the segment.
527 /// </summary>
528 [DllImport("graphite2.dll", EntryPoint="gr_seg_advance_Y")]
529 internal static extern float SegAdvanceY(/*gr_segment**/IntPtr pSeg/*not NULL*/);
530
531 /// <summary>
532 /// Returns the number of gr_char_infos in the segment.
533 /// </summary>
534 [DllImport("graphite2.dll", EntryPoint="gr_seg_n_cinfo")]
535 internal static extern uint SegNCinfo(/*gr_segment**/IntPtr pSeg/*not NULL*/);
536
537 /// <summary>
538 /// Returns a gr_char_info at a given index in the segment.
539 /// </summary>
540 [DllImport("graphite2.dll", EntryPoint="gr_seg_cinfo")]
541 internal static extern /*gr_char_info**/IntPtr SegCinfo(/*gr_segment*/IntPtr pSeg/*not NULL*/, uint index/*must be <number_of_CharInfo*/);
542
543 /// <summary>
544 /// Returns the number of glyph gr_slots in the segment.
545 /// </summary>
546 [DllImport("graphite2.dll", EntryPoint="gr_seg_n_slots")]
547 internal static extern uint SegNSlots(/*gr_segment**/IntPtr pSeg/*not NULL*/); //one slot per glyph
548
549 /// <summary>
550 /// Returns the first gr_slot in the segment.
551 ///
552 /// The first slot in a segment has a gr_slot_prev_in_segment() of NULL. Slots are owned
553 /// by their segment and are destroyed along with the segment.
554 /// </summary>
555 [DllImport("graphite2.dll", EntryPoint="gr_seg_first_slot")]
556 internal static extern /*gr_slot*/IntPtr SegFirstSlot(/*gr_segment**/IntPtr pSeg/*not NULL*/); //may give a base slot or a slot which is attached to another
557
558 /// <summary>
559 /// Returns the last gr_slot in the segment.
560 ///
561 /// The last slot in a segment has a gr_slot_next_in_segment() of NULL
562 /// </summary>
563 [DllImport("graphite2.dll", EntryPoint="gr_seg_last_slot")]
564 internal static extern /*gr_slot**/IntPtr SegLastSlot(/*gr_segment**/IntPtr pSeg/*not NULL*/); //may give a base slot or a slot which is attached to another
565
566 /// <summary>
567 /// Justifies a linked list of slots for a line to a given width
568 ///
569 /// Passed a pointer to the start of a linked list of slots corresponding to a line, as
570 /// set up by gr_slot_linebreak_before, this function will position the glyphs in the line
571 /// to take up the given width. It is possible to specify a subrange within the line to process.
572 /// This allows skipping of line initial or final whitespace, for example. While this will ensure
573 /// that the subrange fits width, the line will still be positioned with the first glyph of the
574 /// line at 0. So the resulting positions may be beyond width.
575 /// </summary>
576 /// <param name='pSeg'>
577 /// Pointer to the segment
578 /// </param>
579 /// <param name='pStart'>
580 /// Pointer to the start of the line linked list (including skipped characters)
581 /// </param>
582 /// <param name='pFont'>
583 /// Font to use for positioning
584 /// </param>
585 /// <param name='width'>
586 /// Width in pixels in which to fit the line
587 /// </param>
588 /// <param name='flags'>
589 /// Indicates line ending types. Default is linked list is a full line
590 /// </param>
591 /// <param name='pFirst'>
592 /// If not NULL, the first slot in the list to be considered part of the line (so can skip)
593 /// </param>
594 /// <param name='pLast'>
595 /// If not NULL, the last slot to process in the line (allow say trailing whitespace to be skipped)
596 /// </param>
597 [DllImport("graphite2.dll", EntryPoint="gr_seg_justify")]
598 internal static extern void SegJustify(/*gr_segment**/IntPtr pSeg/*not NULL*/, /*gr_slot**/IntPtr pStart/*not NULL*/, /*gr_font **/ IntPtr pFont, double width, JustFlags flags, /*gr_slot**/IntPtr pFirst, /*gr_slot**/IntPtr pLast);
599
600 /// <summary>
601 /// Returns the next slot along in the segment.
602 ///
603 /// Slots are held in a linked list. This returns the next in the linked list. The slot
604 /// may or may not be attached to another slot. Returns NULL at the end of the segment.
605 /// </summary>
606 [DllImport("graphite2.dll", EntryPoint="gr_slot_next_in_segment")]
607 internal static extern /*gr_slot**/IntPtr SlotNextInSegment(/*gr_slot**/ IntPtr p);
608
609 /// <summary>
610 /// Returns the previous slot along in the segment.
611 ///
612 /// Slots are held in a doubly linked list. This returns the previos slot in the linked
613 /// list. This slot may or may not be attached to it. Returns NULL at the start of the
614 /// segment.
615 /// </summary>
616 [DllImport("graphite2.dll", EntryPoint="gr_slot_prev_in_segment")]
617 internal static extern /*gr_slot**/IntPtr SlotPrevInSegment(/*gr_slot**/IntPtr p);
618
619 /// <summary>
620 /// Returns the attachment parent slot of this slot.
621 ///
622 /// Attached slots form a tree. This returns the parent of this slot in that tree. A
623 /// base glyph which is not attached to another glyph, always returns NULL.
624 /// </summary>
625 [DllImport("graphite2.dll", EntryPoint="gr_slot_attached_to")]
626 internal static extern /*gr_slot**/IntPtr SlotAttachedTo(/*gr_slot**/IntPtr p);
627
628 /// <summary>
629 /// Returns the first slot attached to this slot.
630 ///
631 /// Attached slots form a singly linked list from the parent. This returns the first
632 /// slot in that list. Note that this is a reference to another slot that is also in
633 /// the main segment doubly linked list.
634 ///
635 /// if gr_slot_first_attachment(p) != NULL then gr_slot_attached_to(gr_slot_first_attachment(p)) == p.
636 /// </summary>
637 [DllImport("graphite2.dll", EntryPoint="gr_slot_first_attachment")]
638 internal static extern /*gr_slot**/IntPtr SlotFirstAttachment(/*gr_slot**/IntPtr p);
639
640 /// <summary>
641 /// Returns the next slot attached to our attachment parent.
642 ///
643 /// This returns the next slot in the singly linked list of slots attached to this
644 /// slot's parent. If there are no more such slots, NULL is returned. If there is
645 /// no parent, i.e. the passed slot is a base, then the next base in graphical order
646 /// (ltr even for rtl text) is returned.
647 ///
648 /// if gr_slot_next_sibling_attachment(p) != NULL then gr_slot_attached_to(gr_slot_next_sibling_attachment(p)) == gr_slot_attached_to(p).
649 /// </summary>
650 [DllImport("graphite2.dll", EntryPoint="gr_slot_next_sibling_attachment")]
651 internal static extern /*gr_slot**/IntPtr SlotNextSiblingAttachment(/*gr_slot**/IntPtr p);
652
653 /// <summary>
654 /// Returns glyph id of the slot
655 ///
656 /// Each slot has a glyphid which is rendered at the position given by the slot. This
657 /// glyphid is the real glyph to be rendered and never a pseudo glyph.
658 /// </summary>
659 [DllImport("graphite2.dll", EntryPoint="gr_slot_gid")]
660 internal static extern ushort SlotGid(/*gr_slot**/IntPtr p);
661
662 /// <summary>
663 /// Returns X offset of glyph from start of segment
664 /// </summary>
665 [DllImport("graphite2.dll", EntryPoint="gr_slot_origin_X")]
666 internal static extern float SlotOriginX(/*gr_slot**/IntPtr p);
667
668 /// <summary>
669 /// Returns Y offset of glyph from start of segment
670 /// </summary>
671 [DllImport("graphite2.dll", EntryPoint="gr_slot_origin_Y")]
672 internal static extern float SlotOriginY(/*gr_slot**/IntPtr p);
673
674 /// <summary>
675 /// Returns the glyph advance for this glyph as adjusted for kerning
676 /// </summary>
677 /// <param name='p'>
678 /// Slot to give results for
679 /// </param>
680 /// <param name='face'>
681 /// face gr_face of the glyphs. May be NULL if unhinted advances used
682 /// </param>
683 /// <param name='font'>
684 /// font gr_font to scale for pixel results. If NULL returns design units advance. If not NULL then returns pixel advance based on hinted or scaled glyph advances in the font. face must be passed for hinted advances to be used.
685 /// </param>
686 [DllImport("graphite2.dll", EntryPoint="gr_slot_advance_X")]
687 internal static extern float SlotAdvanceX(/*gr_slot**/IntPtr p, /*gr_face**/IntPtr face, /*gr_font **/IntPtr font);
688
689 /// <summary>
690 /// Returns the vertical advance for the glyph in the slot adjusted for kerning
691 ///
692 /// Returns design units unless font is not NULL in which case the pixel value is returned scaled for the given font
693 /// </summary>
694 [DllImport("graphite2.dll", EntryPoint="gr_slot_advance_Y")]
695 internal static extern float SlotAdvanceY(/*gr_slot**/IntPtr p, /*gr_face**/IntPtr face, /*gr_font **/IntPtr font);
696
697 /// <summary>
698 /// Returns the gr_char_info index before us
699 ///
700 /// Returns the index of the gr_char_info that a cursor before this slot, would put
701 /// an underlying cursor before.
702 /// </summary>
703 [DllImport("graphite2.dll", EntryPoint="gr_slot_before")]
704 internal static extern int SlotBefore(/*gr_slot**/IntPtr p/*not NULL*/);
705
706 /// <summary>
707 /// Returns the gr_char_info index after us
708 ///
709 /// Returns the index of the gr_char_info that a cursor after this slot would put an
710 /// underlying cursor after.
711 /// </summary>
712 [DllImport("graphite2.dll", EntryPoint="gr_slot_after")]
713 internal static extern int SlotAfter(/*gr_slot**/IntPtr p/*not NULL*/);
714
715 /// <summary>
716 /// Returns the index of this slot in the segment
717 ///
718 /// Returns the index given to this slot during final positioning. This corresponds to the value returned br gr_cinfo_before()
719 /// and gr_cinfo_after()
720 /// </summary>
721 [DllImport("graphite2.dll", EntryPoint="gr_slot_index")]
722 internal static extern uint SlotIndex(/*gr_slot**/IntPtr p/*not NULL*/);
723
724 /// <summary>
725 /// Return a slot attribute value
726 ///
727 /// Given a slot and an attribute along with a possible subattribute, return the
728 /// corresponding value in the slot. See enum gr_attrCode for details of each attribute.
729 /// </summary>
730 [DllImport("graphite2.dll", EntryPoint="gr_slot_attr")]
731 internal static extern int SlotAttr(/*gr_slot**/IntPtr p/*not NULL*/, /*gr_segment**/IntPtr pSeg/*not NULL*/, AttrCode index, byte subindex); //tbd - do we need to expose this?
732
733 /// <summary>
734 /// Returns whether text may be inserted before this glyph [check this isn't inverted]
735 /// </summary>
736 [DllImport("graphite2.dll", EntryPoint="gr_slot_can_insert_before")]
737 internal static extern int SlotCanInsertBefore(/*gr_slot**/IntPtr p);
738
739 /// <summary>
740 /// Returns the original gr_char_info index this slot refers to.
741 ///
742 /// Each Slot has a gr_char_info that it originates from. This is that gr_char_info. The index is passed to gr_seg_cinfo(). This
743 /// information is useful for testing.
744 /// </summary>
745 [DllImport("graphite2.dll", EntryPoint="gr_slot_original")]
746 internal static extern int SlotOriginal(/*gr_slot**/IntPtr p/*not NULL*/);
747
748 /// <summary>
749 /// Breaks a segment into lines.
750 ///
751 /// Breaks the slot linked list at the given point in the linked list. It is up
752 /// to the application to keep track of the first slot on each line.
753 /// </summary>
754 [DllImport("graphite2.dll", EntryPoint="gr_slot_linebreak_before")]
755 internal static extern void SlotLinebreakBefore(/*gr_slot **/ IntPtr p/*not NULL*/);
756
757 #endregion
758
759 #region Log methods
760
761 /// <summary>
762 /// Start logging all segment creation and updates on the provided face. This
763 /// is logged to a JSON file, see "Segment JSON Schema.txt" for a precise
764 /// definition of the file
765 /// </summary>
766 /// <returns>
767 /// true if the file was successfully created and logging is correctly initialised.
768 /// </returns>
769 /// <param name='face'>
770 /// the gr_face whose segments you want to log to the given file
771 /// </param>
772 /// <param name='log_path'>
773 /// a utf8 encoded file name and path to log to.
774 /// </param>
775 [DllImport("graphite2.dll", EntryPoint="gr_start_logging", CharSet = CharSet.Ansi)]
776 internal static extern bool StartLogging(/*gr_face **/IntPtr face, string log_path);
777
778
779 /// <summary>
780 /// GStop logging on the given face. This will close the log file created by
781 /// gr_start_logging.
782 /// </summary>
783 /// <param name='face'>
784 /// the gr_face whose segments you want to stop logging
785 /// </param>
786 [DllImport("graphite2.dll", EntryPoint="gr_stop_logging", CharSet = CharSet.Ansi)]
787 internal static extern void StopLogging(/*gr_face **/IntPtr face);
788
789 #endregion
790 }
791 }