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

Function PiuTextFormatLine

modules/piu/All/piuText.c:845–903  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

843}
844
845void PiuTextFormatLine(PiuText* self, PiuTextFormatContext ctx, PiuTextKind kind, PiuTextOffset length)
846{
847 xsMachine *the = (*self)->the;
848 PiuTextBuffer* lineBuffer = (*self)->lineBuffer;
849 PiuTextOffset lineOffset = (PiuTextOffset)(*lineBuffer)->current;
850 PiuTextLine line;
851 PiuCoordinate x = (*ctx->blockStyle)->margins.left;
852 xsIntegerValue leading = (*ctx->blockStyle)->leading;
853 xsIntegerValue ascent, height;
854
855 PiuTextBufferGrow(the, lineBuffer, sizeof(PiuTextLineRecord));
856 line = LINE(lineOffset);
857 line->textOffset = ctx->lineOffset;
858
859 switch ((*ctx->blockStyle)->horizontal) {
860 case piuCenter:
861#ifdef piuPC
862 line->x = x + ((ctx->blockWidth - ctx->lineWidth) / 2);
863#else
864 line->x = x + ((ctx->blockWidth - ctx->lineWidth) >> 1);
865#endif
866 line->portion = line->slop = 0;
867 break;
868 case piuLeft:
869 line->x = x;
870 line->portion = line->slop = 0;
871 break;
872 case piuRight:
873 line->x = x + ctx->blockWidth - ctx->lineWidth;
874 line->portion = line->slop = 0;
875 break;
876 default:
877 line->x = x;
878 line->portion = ctx->spaceCount;
879 line->slop = (ctx->spaceCount) ? ctx->blockWidth - (ctx->lineWidth - ctx->spaceSum) : 0;
880 break;
881 }
882 if (kind == piuTextReturn) {
883 line->portion = 0;
884 line->slop = -length;
885 }
886 ascent = ctx->lineAscent;
887 height = ctx->lineHeight;
888 if (leading < 0) {
889 leading = -leading;
890 ascent = (ascent * leading) / 100;
891 height = (height * leading) / 100;
892 }
893 else if (leading > 0) {
894 if (0 < height && height < leading) {
895 ascent = (ascent * leading) / height;
896 height = leading;
897 }
898 }
899 line->top = ctx->y + (PiuCoordinate)ascent - ctx->lineAscent;
900 line->base = ctx->y + (PiuCoordinate)ascent;
901 line->bottom = line->top + ctx->lineHeight;
902 ctx->y += (PiuCoordinate)height;

Callers 1

PiuTextFormatBlockFunction · 0.85

Calls 1

PiuTextBufferGrowFunction · 0.85

Tested by

no test coverage detected