MCPcopy Create free account
hub / github.com/ClassiCube/ClassiCube / MeasureBitmappedWidth

Function MeasureBitmappedWidth

src/Drawer2D.c:567–593  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

565}
566
567static int MeasureBitmappedWidth(const struct DrawTextArgs* args) {
568 int i, point = args->font->size;
569 int xPadding, width;
570 cc_string text;
571
572 if (!fontBitmap.scan0) return FallbackFont_TextWidth(args);
573
574 /* adjust coords to make drawn text match GDI fonts */
575 xPadding = Drawer2D_XPadding(point);
576 width = 0;
577
578 text = args->text;
579 for (i = 0; i < text.length; i++) {
580 char c = text.buffer[i];
581 if (c == '&' && Drawer2D_ValidColorCodeAt(&text, i + 1)) {
582 i++; continue; /* skip over the color code */
583 }
584 width += Drawer2D_Width(point, c) + xPadding;
585 }
586 if (!width) return 0;
587
588 /* Remove padding at end */
589 if (!(args->font->flags & FONT_FLAGS_PADDING)) width -= xPadding;
590
591 if (args->useShadow) { width += Drawer2D_ShadowOffset(point); }
592 return width;
593}
594
595void Context2D_DrawText(struct Context2D* ctx, struct DrawTextArgs* args, int x, int y) {
596 struct Bitmap* bmp = (struct Bitmap*)ctx;

Callers 1

Drawer2D_TextWidthFunction · 0.85

Calls 3

FallbackFont_TextWidthFunction · 0.85
Drawer2D_WidthFunction · 0.85

Tested by

no test coverage detected