Path: blob/master/thirdparty/graphite/include/graphite2/Segment.h
9906 views
/* SPDX-License-Identifier: MIT OR MPL-2.0 OR LGPL-2.1-or-later OR GPL-2.0-or-later */1/* Copyright 2010, SIL International, All rights reserved. */2#pragma once34#include "graphite2/Types.h"5#include "graphite2/Font.h"67#ifdef __cplusplus8extern "C"9{10#endif1112enum gr_break_weight {13gr_breakNone = 0,14/* after break weights */15gr_breakWhitespace = 10,16gr_breakWord = 15,17gr_breakIntra = 20,18gr_breakLetter = 30,19gr_breakClip = 40,20/* before break weights */21gr_breakBeforeWhitespace = -10,22gr_breakBeforeWord = -15,23gr_breakBeforeIntra = -20,24gr_breakBeforeLetter = -30,25gr_breakBeforeClip = -4026};2728enum gr_justFlags {29/// Indicates that this segment is a complete line30gr_justCompleteLine = 0,31/// Indicates that the start of the slot list is not at the start of a line32gr_justStartInline = 1,33/// Indicates that the end of the slot list is not at the end of a line34gr_justEndInline = 235};3637/** Used for looking up slot attributes. Most are already available in other functions **/38enum gr_attrCode {39/// adjusted glyph advance in x direction in design units40gr_slatAdvX = 0,41/// adjusted glyph advance in y direction (usually 0) in design units42gr_slatAdvY,43/// returns 0. Deprecated.44gr_slatAttTo,45/// This slot attaches to its parent at the given design units in the x direction46gr_slatAttX,47/// This slot attaches to its parent at the given design units in the y direction48gr_slatAttY,49/// This slot attaches to its parent at the given glyph point (not implemented)50gr_slatAttGpt,51/// x-direction adjustment from the given glyph point (not implemented)52gr_slatAttXOff,53/// y-direction adjustment from the given glyph point (not implemented)54gr_slatAttYOff,55/// Where on this glyph should align with the attachment point on the parent glyph in the x-direction.56gr_slatAttWithX,57/// Where on this glyph should align with the attachment point on the parent glyph in the y-direction58gr_slatAttWithY,59/// Which glyph point on this glyph should align with the attachment point on the parent glyph (not implemented).60gr_slatWithGpt,61/// Adjustment to gr_slatWithGpt in x-direction (not implemented)62gr_slatAttWithXOff,63/// Adjustment to gr_slatWithGpt in y-direction (not implemented)64gr_slatAttWithYOff,65/// Attach at given nesting level (not implemented)66gr_slatAttLevel,67/// Line break breakweight for this glyph68gr_slatBreak,69/// Ligature component reference (not implemented)70gr_slatCompRef,71/// bidi directionality of this glyph (not implemented)72gr_slatDir,73/// Whether insertion is allowed before this glyph74gr_slatInsert,75/// Final positioned position of this glyph relative to its parent in x-direction in pixels76gr_slatPosX,77/// Final positioned position of this glyph relative to its parent in y-direction in pixels78gr_slatPosY,79/// Amount to shift glyph by in x-direction design units80gr_slatShiftX,81/// Amount to shift glyph by in y-direction design units82gr_slatShiftY,83/// attribute user184gr_slatUserDefnV1,85/// not implemented86gr_slatMeasureSol,87/// not implemented88gr_slatMeasureEol,89/// Amount this slot can stretch (not implemented)90gr_slatJStretch,91/// Amount this slot can shrink (not implemented)92gr_slatJShrink,93/// Granularity by which this slot can stretch or shrink (not implemented)94gr_slatJStep,95/// Justification weight for this glyph (not implemented)96gr_slatJWeight,97/// Amount this slot mush shrink or stretch in design units98gr_slatJWidth = 29,99/// SubSegment split point100gr_slatSegSplit = gr_slatJStretch + 29,101/// User defined attribute, see subattr for user attr number102gr_slatUserDefn,103/// Bidi level104gr_slatBidiLevel = 56,105/// Collision flags106gr_slatColFlags,107/// Collision constraint rectangle left (bl.x)108gr_slatColLimitblx,109/// Collision constraint rectangle lower (bl.y)110gr_slatColLimitbly,111/// Collision constraint rectangle right (tr.x)112gr_slatColLimittrx,113/// Collision constraint rectangle upper (tr.y)114gr_slatColLimittry,115/// Collision shift x116gr_slatColShiftx,117/// Collision shift y118gr_slatColShifty,119/// Collision margin120gr_slatColMargin,121/// Margin cost weight122gr_slatColMarginWt,123// Additional glyph that excludes movement near this one:124gr_slatColExclGlyph,125gr_slatColExclOffx,126gr_slatColExclOffy,127// Collision sequence enforcing attributes:128gr_slatSeqClass,129gr_slatSeqProxClass,130gr_slatSeqOrder,131gr_slatSeqAboveXoff,132gr_slatSeqAboveWt,133gr_slatSeqBelowXlim,134gr_slatSeqBelowWt,135gr_slatSeqValignHt,136gr_slatSeqValignWt,137138/// not implemented139gr_slatMax,140/// not implemented141gr_slatNoEffect = gr_slatMax + 1142};143144enum gr_bidirtl {145/// Underlying paragraph direction is RTL146gr_rtl = 1,147/// Set this to not run the bidi pass internally, even if the font asks for it.148/// This presumes that the segment is in a single direction. Most of the time149/// this bit should be set unless you know you are passing full paragraphs of text.150gr_nobidi = 2,151/// Disable auto mirroring for rtl text152gr_nomirror = 4153};154155typedef struct gr_char_info gr_char_info;156typedef struct gr_segment gr_segment;157typedef struct gr_slot gr_slot;158159/** Returns Unicode character for a charinfo.160*161* @param p Pointer to charinfo to return information on.162*/163GR2_API unsigned int gr_cinfo_unicode_char(const gr_char_info* p/*not NULL*/);164165/** Returns breakweight for a charinfo.166*167* @return Breakweight is a number between -50 and 50 indicating the cost of a168* break before or after this character. If the value < 0, the absolute value169* is this character's contribution to the overall breakweight before it. If the value170* > 0, then the value is this character's contribution to the overall breakweight after it.171* The overall breakweight between two characters is the maximum of the breakweight172* contributions from the characters either side of it. If a character makes no173* contribution to the breakweight on one side of it, the contribution is considered174* to be 0.175* @param p Pointer to charinfo to return information on.176*/177GR2_API int gr_cinfo_break_weight(const gr_char_info* p/*not NULL*/);178179/** Returns the slot index that after this character is after in the slot stream180*181* In effect each character is associated with a set of slots and this returns182* the index of the last slot in the segment this character is associated with.183*184* @return after slot index between 0 and gr_seg_n_slots()185* @param p Pointer to charinfo to return information on.186*/187GR2_API int gr_cinfo_after(const gr_char_info* p/*not NULL*/);188189/** Returns the slot index that before this character is before in the slot stream190*191* In effect each character is associated with a set of slots and this returns192* the index of the first slot in the segment this character is associated with.193*194* @return before slot index between 0 and gr_seg_n_slots()195* @param p Pointer to charinfo to return information on.196*/197GR2_API int gr_cinfo_before(const gr_char_info* p/*not NULL*/);198199/** Returns the code unit index of this character in the input string200*201* @return code unit index between 0 and the end of the string202* @param p Pointer to charinfo to return information on.203*/204GR2_API size_t gr_cinfo_base(const gr_char_info* p/*not NULL*/);205206/** Returns the number of unicode characters in a string.207*208* @return number of characters in the string209* @param enc Specifies the type of data in the string: utf8, utf16, utf32210* @param buffer_begin The start of the string211* @param buffer_end Measure up to the first nul or when end is reached, whichever is earliest.212* This parameter may be NULL.213* @param pError If there is a structural fault in the string, the location is returned214* in this variable. If no error occurs, pError will contain NULL. NULL215* may be passed for pError if no such information is required.216*/217GR2_API size_t gr_count_unicode_characters(enum gr_encform enc, const void* buffer_begin, const void* buffer_end, const void** pError);218219/** Creates and returns a segment.220*221* @return a segment that needs seg_destroy called on it. May return NULL if bad problems222* in segment processing.223* @param font Gives the size of the font in pixels per em for final positioning. If224* NULL, positions are returned in design units, i.e. at a ppm of the upem225* of the face.226* @param face The face containing all the non-size dependent information.227* @param script This is a tag containing a script identifier that is used to choose228* which graphite table within the font to use. Maybe 0. Tag may be 4 chars229* NULL padded in LSBs or space padded in LSBs.230* @param pFeats Pointer to a feature values to be used for the segment. Only one231* feature values may be used for a segment. If NULL the default features232* for the font will be used.233* @param enc Specifies what encoding form the string is in (utf8, utf16, utf32)234* @param pStart Start of the string235* @param nChars Number of unicode characters to process in the string. The string will236* be processed either up to the first NULL or until nChars have been237* processed. nChars is also used to initialise the internal memory238* allocations of the segment. So it is wise not to make nChars too much239* greater than the actual number of characters being processed.240* @param dir Specifies whether the segment is processed right to left (1) or left to241* right (0) and whether to run the internal bidi pass, if a font requests it.242* See enum gr_bidirtl for details.243*/244GR2_API gr_segment* gr_make_seg(const gr_font* font, const gr_face* face, gr_uint32 script, const gr_feature_val* pFeats, enum gr_encform enc, const void* pStart, size_t nChars, int dir);245246/** Destroys a segment, freeing the memory.247*248* @param p The segment to destroy249*/250GR2_API void gr_seg_destroy(gr_segment* p);251252/** Returns the advance for the whole segment.253*254* Returns the width of the segment up to the next glyph origin after the segment255*/256GR2_API float gr_seg_advance_X(const gr_segment* pSeg/*not NULL*/);257258/** Returns the height advance for the segment. **/259GR2_API float gr_seg_advance_Y(const gr_segment* pSeg/*not NULL*/);260261/** Returns the number of gr_char_infos in the segment. **/262GR2_API unsigned int gr_seg_n_cinfo(const gr_segment* pSeg/*not NULL*/);263264/** Returns a gr_char_info at a given index in the segment. **/265GR2_API const gr_char_info* gr_seg_cinfo(const gr_segment* pSeg/*not NULL*/, unsigned int index/*must be <number_of_CharInfo*/);266267/** Returns the number of glyph gr_slots in the segment. **/268GR2_API unsigned int gr_seg_n_slots(const gr_segment* pSeg/*not NULL*/); //one slot per glyph269270/** Returns the first gr_slot in the segment.271*272* The first slot in a segment has a gr_slot_prev_in_segment() of NULL. Slots are owned273* by their segment and are destroyed along with the segment.274*/275GR2_API const gr_slot* gr_seg_first_slot(gr_segment* pSeg/*not NULL*/); //may give a base slot or a slot which is attached to another276277/** Returns the last gr_slot in the segment.278*279* The last slot in a segment has a gr_slot_next_in_segment() of NULL280*/281GR2_API const gr_slot* gr_seg_last_slot(gr_segment* pSeg/*not NULL*/); //may give a base slot or a slot which is attached to another282283/** Justifies a linked list of slots for a line to a given width284*285* Passed a pointer to the start of a linked list of slots corresponding to a line, as286* set up by gr_slot_linebreak_before, this function will position the glyphs in the line287* to take up the given width. It is possible to specify a subrange within the line to process.288* This allows skipping of line initial or final whitespace, for example. While this will ensure289* that the subrange fits width, the line will still be positioned with the first glyph of the290* line at 0. So the resulting positions may be beyond width.291*292* @return float The resulting width of the range of slots justified.293* @param pSeg Pointer to the segment294* @param pStart Pointer to the start of the line linked list (including skipped characters)295* @param pFont Font to use for positioning296* @param width Width in pixels in which to fit the line. If < 0. don't adjust natural width, just run justification passes297* to handle line end contextuals, if there are any.298* @param flags Indicates line ending types. Default is linked list is a full line299* @param pFirst If not NULL, the first slot in the list to be considered part of the line (so can skip)300* @param pLast If not NULL, the last slot to process in the line (allow say trailing whitespace to be skipped)301*/302GR2_API float gr_seg_justify(gr_segment* pSeg/*not NULL*/, const gr_slot* pStart/*not NULL*/, const gr_font *pFont, double width, enum gr_justFlags flags, const gr_slot* pFirst, const gr_slot* pLast);303304/** Returns the next slot along in the segment.305*306* Slots are held in a linked list. This returns the next in the linked list. The slot307* may or may not be attached to another slot. Returns NULL at the end of the segment.308*/309GR2_API const gr_slot* gr_slot_next_in_segment(const gr_slot* p);310311/** Returns the previous slot along in the segment.312*313* Slots are held in a doubly linked list. This returns the previos slot in the linked314* list. This slot may or may not be attached to it. Returns NULL at the start of the315* segment.316*/317GR2_API const gr_slot* gr_slot_prev_in_segment(const gr_slot* p);318319/** Returns the attachment parent slot of this slot.320*321* Attached slots form a tree. This returns the parent of this slot in that tree. A322* base glyph which is not attached to another glyph, always returns NULL.323*/324GR2_API const gr_slot* gr_slot_attached_to(const gr_slot* p);325326/** Returns the first slot attached to this slot.327*328* Attached slots form a singly linked list from the parent. This returns the first329* slot in that list. Note that this is a reference to another slot that is also in330* the main segment doubly linked list.331*332* if gr_slot_first_attachment(p) != NULL then gr_slot_attached_to(gr_slot_first_attachment(p)) == p.333*/334GR2_API const gr_slot* gr_slot_first_attachment(const gr_slot* p);335336/** Returns the next slot attached to our attachment parent.337*338* This returns the next slot in the singly linked list of slots attached to this339* slot's parent. If there are no more such slots, NULL is returned. If there is340* no parent, i.e. the passed slot is a cluster base, then the next cluster base341* in graphical order (ltr, even for rtl text) is returned.342*343* if gr_slot_next_sibling_attachment(p) != NULL then gr_slot_attached_to(gr_slot_next_sibling_attachment(p)) == gr_slot_attached_to(p).344*/345GR2_API const gr_slot* gr_slot_next_sibling_attachment(const gr_slot* p);346347348/** Returns glyph id of the slot349*350* Each slot has a glyphid which is rendered at the position given by the slot. This351* glyphid is the real glyph to be rendered and never a pseudo glyph.352*/353GR2_API unsigned short gr_slot_gid(const gr_slot* p);354355/** Returns X offset of glyph from start of segment **/356GR2_API float gr_slot_origin_X(const gr_slot* p);357358/** Returns Y offset of glyph from start of segment **/359GR2_API float gr_slot_origin_Y(const gr_slot* p);360361/** Returns the glyph advance for this glyph as adjusted for kerning362*363* @param p Slot to give results for364* @param face gr_face of the glyphs. May be NULL if unhinted advances used365* @param font gr_font to scale for pixel results. If NULL returns design366* units advance. If not NULL then returns pixel advance based367* on hinted or scaled glyph advances in the font. face must be368* passed for hinted advances to be used.369*/370GR2_API float gr_slot_advance_X(const gr_slot* p, const gr_face* face, const gr_font *font);371372/** Returns the vertical advance for the glyph in the slot adjusted for kerning373*374* Returns design units unless font is not NULL in which case the pixel value375* is returned scaled for the given font376*/377GR2_API float gr_slot_advance_Y(const gr_slot* p, const gr_face* face, const gr_font *font);378379/** Returns the gr_char_info index before us380*381* Returns the index of the gr_char_info that a cursor before this slot, would put382* an underlying cursor before. This may also be interpretted as each slot holding383* a set of char_infos that it is associated with and this function returning the384* index of the char_info with lowest index, from this set.385*/386GR2_API int gr_slot_before(const gr_slot* p/*not NULL*/);387388/** Returns the gr_char_info index after us389*390* Returns the index of the gr_char_info that a cursor after this slot would put an391* underlying cursor after. This may also be interpretted as each slot holding a set392* of char_infos that it is associated with and this function returning the index of393* the char_info with the highest index, from this set.394*/395GR2_API int gr_slot_after(const gr_slot* p/*not NULL*/);396397/** Returns the index of this slot in the segment398*399* Returns the index given to this slot during final positioning. This corresponds400* to the value returned br gr_cinfo_before() and gr_cinfo_after()401*/402GR2_API unsigned int gr_slot_index(const gr_slot* p/*not NULL*/);403404/** Return a slot attribute value405*406* Given a slot and an attribute along with a possible subattribute, return the407* corresponding value in the slot. See enum gr_attrCode for details of each attribute.408*/409GR2_API int gr_slot_attr(const gr_slot* p/*not NULL*/, const gr_segment* pSeg/*not NULL*/, enum gr_attrCode index, gr_uint8 subindex); //tbd - do we need to expose this?410411/** Returns whether text may be inserted before this glyph.412*413* This indicates whether a cursor can be put before this slot. It applies to414* base glyphs that have no parent as well as attached glyphs that have the415* .insert attribute explicitly set to true. This is the primary mechanism416* for identifying contiguous sequences of base plus diacritics.417*/418GR2_API int gr_slot_can_insert_before(const gr_slot* p);419420/** Returns the original gr_char_info index this slot refers to.421*422* Each Slot has a gr_char_info that it originates from. This is that gr_char_info.423* The index is passed to gr_seg_cinfo(). This information is useful for testing.424*/425GR2_API int gr_slot_original(const gr_slot* p/*not NULL*/);426427/** Breaks a segment into lines.428*429* Breaks the slot linked list at the given point in the linked list. It is up430* to the application to keep track of the first slot on each line.431*/432GR2_API void gr_slot_linebreak_before(gr_slot *p/*not NULL*/);433434#ifdef __cplusplus435}436#endif437438439