1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
5 * (C) Copyright IBM Corp. 1998-2011 - All Rights Reserved
13 * ParagraphLayout doesn't make much sense without
16 #include "unicode/ubidi.h"
17 #if ! UCONFIG_NO_BREAK_ITERATION
18 #ifndef U_HIDE_INTERNAL_API
20 #include "layout/LETypes.h"
25 * \brief C API for paragraph layout.
27 * This is a technology preview. The API may
28 * change significantly.
33 * The opaque type for a paragraph layout.
37 typedef void pl_paragraph
;
40 * The opaque type for a line in a paragraph layout.
47 * The opaque type for a visual run in a line.
51 typedef void pl_visualRun
;
54 * Construct a <code>ParagraphLayout</code> object for a styled paragraph. The paragraph is specified
55 * as runs of text all in the same font. An <code>LEFontInstance</code> object and a limit offset
56 * are specified for each font run. The limit offset is the offset of the character immediately
59 * Clients can optionally specify directional runs and / or script runs. If these aren't specified
60 * they will be computed.
62 * If any errors are encountered during construction, <code>status</code> will be set, and the object
63 * will be set to be empty.
65 * @param chars is an array of the characters in the paragraph
67 * @param count is the number of characters in the paragraph.
69 * @param fontRuns a pointer to a <code>pl_fontRuns</code> object representing the font runs.
71 * @param levelRuns is a pointer to a <code>pl_valueRuns</code> object representing the directional levels.
72 * If this pointer in <code>NULL</code> the levels will be determined by running the Unicde
75 * @param scriptRuns is a pointer to a <code>pl_valueRuns</code> object representing script runs.
76 * If this pointer in <code>NULL</code> the script runs will be determined using the
77 * Unicode code points.
79 * @param localeRuns is a pointer to a <code>pl_localeRuns</code> object representing locale runs.
80 * The <code>Locale</code> objects are used to determind the language of the text. If this
81 * pointer is <code>NULL</code> the default locale will be used for all of the text.
83 * @param paragraphLevel is the directionality of the paragraph, as in the UBiDi object.
85 * @param vertical is <code>TRUE</code> if the paragraph should be set vertically.
87 * @param status will be set to any error code encountered during construction.
89 * @return a pointer to the newly created <code>pl_paragraph</code> object. The object
90 * will remain valid until <code>pl_close</code> is called.
98 U_INTERNAL pl_paragraph
* U_EXPORT2
99 pl_create(const LEUnicode chars
[],
101 const pl_fontRuns
*fontRuns
,
102 const pl_valueRuns
*levelRuns
,
103 const pl_valueRuns
*scriptRuns
,
104 const pl_localeRuns
*localeRuns
,
105 UBiDiLevel paragraphLevel
,
107 LEErrorCode
*status
);
110 * Close the given paragraph layout object.
112 * @param paragraph the <code>pl_paragraph</code> object to be
113 * closed. Once this routine returns the object
114 * can no longer be referenced
118 U_INTERNAL
void U_EXPORT2
119 pl_close(pl_paragraph
*paragraph
);
122 * Examine the given text and determine if it contains characters in any
123 * script which requires complex processing to be rendered correctly.
125 * @param chars is an array of the characters in the paragraph
127 * @param count is the number of characters in the paragraph.
129 * @return <code>TRUE</code> if any of the text requires complex processing.
134 U_INTERNAL le_bool U_EXPORT2
135 pl_isComplex(const LEUnicode chars
[],
139 * Return the resolved paragraph level. This is useful for those cases
140 * where the bidi analysis has determined the level based on the first
141 * strong character in the paragraph.
143 * @param paragraph the <code>pl_paragraph</code>
145 * @return the resolved paragraph level.
149 U_INTERNAL UBiDiLevel U_EXPORT2
150 pl_getParagraphLevel(pl_paragraph
*paragraph
);
153 * Return the directionality of the text in the paragraph.
155 * @param paragraph the <code>pl_paragraph</code>
157 * @return <code>UBIDI_LTR</code> if the text is all left to right,
158 * <code>UBIDI_RTL</code> if the text is all right to left,
159 * or <code>UBIDI_MIXED</code> if the text has mixed direction.
163 U_INTERNAL UBiDiDirection U_EXPORT2
164 pl_getTextDirection(pl_paragraph
*paragraph
);
167 * Get the max ascent value for all the fonts
170 * @param paragraph the <code>pl_paragraph</code>
172 * Return the max ascent value for all the fonts
175 * @param paragraph the <code>pl_paragraph</code>
177 * @return the ascent value.
181 U_INTERNAL le_int32 U_EXPORT2
182 pl_getAscent(const pl_paragraph
*paragraph
);
185 * Return the max descent value for all the fonts
188 * @param paragraph the <code>pl_paragraph</code>
190 * @return the decent value.
194 U_INTERNAL le_int32 U_EXPORT2
195 pl_getDescent(const pl_paragraph
*paragraph
);
198 * Return the max leading value for all the fonts
201 * @param paragraph the <code>pl_paragraph</code>
203 * @return the leading value.
207 U_INTERNAL le_int32 U_EXPORT2
208 pl_getLeading(const pl_paragraph
*paragraph
);
211 * Reset line breaking to start from the beginning of the paragraph.
213 * @param paragraph the <code>pl_paragraph</code>
217 U_INTERNAL
void U_EXPORT2
218 pl_reflow(pl_paragraph
*paragraph
);
221 * Return a <code>pl_line</code> object which represents next line
222 * in the paragraph. The width of the line is specified each time so that it can
223 * be varied to support arbitrary paragraph shapes.
225 * @param paragraph the <code>pl_paragraph</code>
226 * @param width is the width of the line. If <code>width</code> is less than or equal
227 * to zero, a <code>ParagraphLayout::Line</code> object representing the
228 * rest of the paragraph will be returned.
230 * @return a <code>ParagraphLayout::Line</code> object which represents the line. The caller
231 * is responsible for deleting the object. Returns <code>NULL</code> if there are no
232 * more lines in the paragraph.
238 U_INTERNAL pl_line
* U_EXPORT2
239 pl_nextLine(pl_paragraph
*paragraph
, float width
);
242 * Close the given line object. Line objects are created
243 * by <code>pl_nextLine</code> but it is the client's responsibility
244 * to close them by calling this routine.
246 * @param line the <code>pl_line</code> object to close.
250 U_INTERNAL
void U_EXPORT2
251 pl_closeLine(pl_line
*line
);
254 * Count the number of visual runs in the line.
256 * @param line the <code>pl_line</code> object.
258 * @return the number of visual runs.
262 U_INTERNAL le_int32 U_EXPORT2
263 pl_countLineRuns(const pl_line
*line
);
266 * Get the ascent of the line. This is the maximum ascent
267 * of all the fonts on the line.
269 * @param line the <code>pl_line</code> object.
271 * @return the ascent of the line.
275 U_INTERNAL le_int32 U_EXPORT2
276 pl_getLineAscent(const pl_line
*line
);
279 * Get the descent of the line. This is the maximum descent
280 * of all the fonts on the line.
282 * @param line the <code>pl_line</code> object.
284 * @return the descent of the line.
288 U_INTERNAL le_int32 U_EXPORT2
289 pl_getLineDescent(const pl_line
*line
);
292 * Get the leading of the line. This is the maximum leading
293 * of all the fonts on the line.
295 * @param line the <code>pl_line</code> object.
297 * @return the leading of the line.
301 U_INTERNAL le_int32 U_EXPORT2
302 pl_getLineLeading(const pl_line
*line
);
305 * Get the width of the line. This is a convenience method
306 * which returns the last X position of the last visual run
309 * @param line the <code>pl_line</code> object.
311 * @return the width of the line.
315 U_INTERNAL le_int32 U_EXPORT2
316 pl_getLineWidth(const pl_line
*line
);
319 * Get a <code>ParagraphLayout::VisualRun</code> object for a given
320 * visual run in the line.
322 * @param line the <code>pl_line</code> object.
323 * @param runIndex is the index of the run, in visual order.
325 * @return the <code>pl_visualRun</code> object representing the
326 * visual run. This object is owned by the <code>pl_line</code> object which
327 * created it, and will remain valid for as long as the <code>pl_line</code>
334 U_INTERNAL
const pl_visualRun
* U_EXPORT2
335 pl_getLineVisualRun(const pl_line
*line
, le_int32 runIndex
);
338 * Get the <code>le_font</code> object which
339 * represents the font of the visual run. This will always
340 * be a non-composite font.
342 * @param run the <code>pl_visualRun</code> object.
344 * @return the <code>le_font</code> object which represents the
345 * font of the visual run.
351 U_INTERNAL
const le_font
* U_EXPORT2
352 pl_getVisualRunFont(const pl_visualRun
*run
);
355 * Get the direction of the visual run.
357 * @param run the <code>pl_visualRun</code> object.
359 * @return the direction of the run. This will be <code>UBIDI_LTR</code> if the
360 * run is left-to-right and <code>UBIDI_RTL</code> if the line is right-to-left.
364 U_INTERNAL UBiDiDirection U_EXPORT2
365 pl_getVisualRunDirection(const pl_visualRun
*run
);
368 * Get the number of glyphs in the visual run.
370 * @param run the <code>pl_visualRun</code> object.
372 * @return the number of glyphs.
376 U_INTERNAL le_int32 U_EXPORT2
377 pl_getVisualRunGlyphCount(const pl_visualRun
*run
);
380 * Get the glyphs in the visual run. Glyphs with the values <code>0xFFFE</code> and
381 * <code>0xFFFF</code> should be ignored.
383 * @param run the <code>pl_visualRun</code> object.
385 * @return the address of the array of glyphs for this visual run. The storage
386 * is owned by the <code>pl_visualRun</code> object and must not be deleted.
387 * It will remain valid as long as the <code>pl_visualRun</code> object is valid.
391 U_INTERNAL
const LEGlyphID
* U_EXPORT2
392 pl_getVisualRunGlyphs(const pl_visualRun
*run
);
395 * Get the (x, y) positions of the glyphs in the visual run. To simplify storage
396 * management, the x and y positions are stored in a single array with the x positions
397 * at even offsets in the array and the corresponding y position in the following odd offset.
398 * There is an extra (x, y) pair at the end of the array which represents the advance of
399 * the final glyph in the run.
401 * @param run the <code>pl_visualRun</code> object.
403 * @return the address of the array of glyph positions for this visual run. The storage
404 * is owned by the <code>pl_visualRun</code> object and must not be deleted.
405 * It will remain valid as long as the <code>pl_visualRun</code> object is valid.
409 U_INTERNAL
const float * U_EXPORT2
410 pl_getVisualRunPositions(const pl_visualRun
*run
);
413 * Get the glyph-to-character map for this visual run. This maps the indices into
414 * the glyph array to indices into the character array used to create the paragraph.
416 * @param run the <code>pl_visualRun</code> object.
418 * @return the address of the character-to-glyph map for this visual run. The storage
419 * is owned by the <code>pl_visualRun</code> object and must not be deleted.
420 * It will remain valid as long as the <code>pl_visualRun</code> object is valid.
424 U_INTERNAL
const le_int32
* U_EXPORT2
425 pl_getVisualRunGlyphToCharMap(const pl_visualRun
*run
);
428 * A convenience method which returns the ascent value for the font
429 * associated with this run.
431 * @param run the <code>pl_visualRun</code> object.
433 * @return the ascent value of this run's font.
437 U_INTERNAL le_int32 U_EXPORT2
438 pl_getVisualRunAscent(const pl_visualRun
*run
);
441 * A convenience method which returns the descent value for the font
442 * associated with this run.
444 * @param run the <code>pl_visualRun</code> object.
446 * @return the descent value of this run's font.
450 U_INTERNAL le_int32 U_EXPORT2
451 pl_getVisualRunDescent(const pl_visualRun
*run
);
454 * A convenience method which returns the leading value for the font
455 * associated with this run.
457 * @param run the <code>pl_visualRun</code> object.
459 * @return the leading value of this run's font.
463 U_INTERNAL le_int32 U_EXPORT2
464 pl_getVisualRunLeading(const pl_visualRun
*run
);
466 #endif /* U_HIDE_INTERNAL_API */