Skip to content

Commit

Permalink
Remove dependency on libm
Browse files Browse the repository at this point in the history
  • Loading branch information
caramelli committed Mar 25, 2024
1 parent 24737d2 commit 389052e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ libschrift.pc: libschrift.pc.in
@sed 's,@prefix@,$(PREFIX),;s,@version@,$(VERSION),' libschrift.pc.in > $@

demo: demo.o libschrift.a
$(LD) $(EXTRAS_LDFLAGS) $@.o -o $@ -L$(X11LIB) -L. -lX11 -lXrender -lschrift -lm
$(LD) $(EXTRAS_LDFLAGS) $@.o -o $@ -L$(X11LIB) -L. -lX11 -lXrender -lschrift
demo.o: demo.c schrift.h util/utf8_to_utf32.h
$(CC) -c $(EXTRAS_CFLAGS) $(@:.o=.c) -o $@ $(EXTRAS_CPPFLAGS) -I$(X11INC)

stress: stress.o libschrift.a
$(LD) $(EXTRAS_LDFLAGS) $@.o -o $@ -L. -lschrift -lm
$(LD) $(EXTRAS_LDFLAGS) $@.o -o $@ -L. -lschrift
stress.o: stress.c schrift.h util/arg.h
$(CC) -c $(EXTRAS_CFLAGS) $(@:.o=.c) -o $@ $(EXTRAS_CPPFLAGS)

Expand Down
1 change: 0 additions & 1 deletion libschrift.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ Name: libschrift
Description: A lightweight TrueType font rendering library
Version: @version@
Libs: -L${libdir} -lschrift
Libs.private: -lm
Cflags: -I${includedir}
22 changes: 11 additions & 11 deletions schrift.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include <assert.h>
#include <errno.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -65,6 +64,7 @@
#define GOT_A_SCALE_MATRIX 0x080

/* macros */
#define ABS(x) ((x) >= 0 ? (x) : -(x))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SIGN(x) (((x) > 0) - ((x) < 0))
/* Allocate values on the stack if they are small enough, else spill to heap. */
Expand Down Expand Up @@ -588,13 +588,13 @@ clip_points(unsigned int numPts, Point *points, int width, int height)
points[i].x = 0.0;
}
if (pt.x >= width) {
points[i].x = nextafter(width, 0.0);
points[i].x = width;
}
if (pt.y < 0.0) {
points[i].y = 0.0;
}
if (pt.y >= height) {
points[i].y = nextafter(height, 0.0);
points[i].y = height;
}
}
}
Expand Down Expand Up @@ -996,10 +996,10 @@ glyph_bbox(const SFT *sft, uint_fast32_t outline, int box[4])
/* Transform the bounding box into SFT coordinate space. */
xScale = sft->xScale / sft->font->unitsPerEm;
yScale = sft->yScale / sft->font->unitsPerEm;
box[0] = (int) floor(box[0] * xScale + sft->xOffset);
box[1] = (int) floor(box[1] * yScale + sft->yOffset);
box[2] = (int) ceil (box[2] * xScale + sft->xOffset);
box[3] = (int) ceil (box[3] * yScale + sft->yOffset);
box[0] = (int) fast_floor(box[0] * xScale + sft->xOffset);
box[1] = (int) fast_floor(box[1] * yScale + sft->yOffset);
box[2] = (int) fast_ceil (box[2] * xScale + sft->xOffset);
box[3] = (int) fast_ceil (box[3] * yScale + sft->yOffset);
return 0;
}

Expand Down Expand Up @@ -1358,7 +1358,7 @@ is_flat(Outline *outl, Curve curve)
Point c = outl->points[curve.end];
Point g = { b.x-a.x, b.y-a.y };
Point h = { c.x-a.x, c.y-a.y };
double area2 = fabs(g.x*h.y-h.x*g.y);
double area2 = ABS(g.x*h.y-h.x*g.y);
return area2 <= maxArea2;
}

Expand Down Expand Up @@ -1441,8 +1441,8 @@ draw_line(Raster buf, Point origin, Point goal)
return;
}

crossingIncr.x = dir.x ? fabs(1.0 / delta.x) : 1.0;
crossingIncr.y = fabs(1.0 / delta.y);
crossingIncr.x = dir.x ? ABS(1.0 / delta.x) : 1.0;
crossingIncr.y = ABS(1.0 / delta.y);

if (!dir.x) {
pixel.x = fast_floor(origin.x);
Expand Down Expand Up @@ -1524,7 +1524,7 @@ post_process(Raster buf, uint8_t *image)
num = (unsigned int) buf.width * (unsigned int) buf.height;
for (i = 0; i < num; ++i) {
cell = buf.cells[i];
value = fabs(accum + cell.area);
value = ABS(accum + cell.area);
value = MIN(value, 1.0);
value = value * 255.0 + 0.5;
image[i] = (uint8_t) value;
Expand Down

0 comments on commit 389052e

Please sign in to comment.