MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / PiuTextHit

Function PiuTextHit

modules/piu/All/piuText.c:905–1022  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

903}
904
905void* PiuTextHit(void* it, PiuCoordinate x, PiuCoordinate y)
906{
907 PiuText* self = it;
908 xsMachine *the = (*self)->the;
909 PiuTextBuffer* lineBuffer = (*self)->lineBuffer;
910 PiuTextOffset lineOffset = sizeof(PiuTextBufferRecord);
911 PiuTextOffset lineLimit = (PiuTextOffset)(*lineBuffer)->current;
912 PiuTextBuffer* nodeBuffer = (*self)->nodeBuffer;
913 PiuTextOffset nodeOffset = sizeof(PiuTextBufferRecord);
914 PiuTextOffset nodeLimit = (PiuTextOffset)(*nodeBuffer)->current;
915 PiuStyle* style = C_NULL;
916 PiuTextOffset fromOffset, toOffset;
917 xsIntegerValue portion;
918 xsIntegerValue slop = 0;
919 xsIntegerValue step;
920 PiuCoordinate lineLeft = 0;
921 PiuCoordinate lineRight = 0;
922 PiuTextLine line = NULL, nextLine = LINE(lineOffset);
923
924 void* link = NULL;
925 if (!((*self)->flags & piuActive))
926 return NULL;
927 if ((x < 0) || (y < 0) || (x >= (*self)->bounds.width) || (y >= (*self)->bounds.height))
928 return NULL;
929 while (lineOffset < lineLimit) {
930 line = nextLine;
931 lineOffset += sizeof(PiuTextLineRecord);
932 nextLine = (lineOffset < lineLimit) ? LINE(lineOffset) : NULL;
933
934 if (y < line->top)
935 break;
936
937 if (line->bottom < y)
938 continue;
939
940 fromOffset = line->textOffset;
941 toOffset = (nextLine) ? nextLine->textOffset : (*self)->textOffset;
942
943 lineLeft = line->x;
944 portion = line->portion;
945 if (portion) {
946 slop = 0;
947 step = line->slop << 16;
948 step /= portion;
949 }
950
951 while ((fromOffset < toOffset) && (nodeOffset < nodeLimit)) {
952 switch (KIND(nodeOffset)) {
953 case piuTextNodeBeginBlockKind:
954 case piuTextNodeBeginSpanKind: {
955 PiuTextNodeBegin nodeBegin = NODE(nodeOffset);
956 style = nodeBegin->computedStyle;
957 link = nodeBegin->link;
958 nodeOffset += sizeof(PiuTextNodeBeginRecord);
959 } break;
960 case piuTextNodeEndBlockKind: {
961 style = NULL;
962 link = NULL;

Callers

nothing calls this directly

Calls 2

PiuTextAdvanceFunction · 0.85
PiuFontGetWidthFunction · 0.50

Tested by

no test coverage detected