~alcinnz/fontconfig-pure

677feaa727bccd8fbae4c852caabb87bca2f00a9 — Adrian Cochrane 10 months ago a1837e5
Implement a scanner on C-side (LibCMP doesn't provide it).
1 files changed, 43 insertions(+), 0 deletions(-)

M cbits/transcode.c
M cbits/transcode.c => cbits/transcode.c +43 -0
@@ 382,3 382,46 @@ bool encodeFontSet(cmp_ctx_t *bytes, FcFontSet *data) {
    }
    return true;
}

struct bytes {
    uint8_t *start;
    size_t offset;
    size_t length;
};

bool bytes_reader(struct cmp_ctx_s *ctx, void *data, size_t limit) {
    struct bytes *bytes = ctx->buf;
    if (bytes->offset + limit > bytes->length) return false;
    data = bytes->start + bytes->offset;
    bytes->offset += limit;
    return true;
}

bool bytes_skipper(struct cmp_ctx_s *ctx, size_t count) {
    struct bytes *bytes = ctx->buf;
    if (bytes->offset + count > bytes->length) return false;
    bytes->offset += count;
    return true;
}

size_t bytes_writer(struct cmp_ctx_s *ctx, const void *data, size_t count) {
    struct bytes *bytes = ctx->buf;
    if (bytes->offset + count > bytes->length) return 0;
    memcpy(bytes->start + bytes->offset, data, count);
    bytes->offset += count;
    return count;
}

void cmp_bytes_init(cmp_ctx_t *ctx, uint8_t *buf, size_t length) {
    struct bytes *inner = malloc(sizeof(struct bytes));
    inner->start = buf;
    inner->offset = 0;
    inner->length = length;
    cmp_init(ctx, inner, bytes_reader, bytes_skipper, bytes_writer);
}

void cmp_bytes_free(cmp_ctx_t *ctx) {
    struct bytes *bytes = ctx->buf;
    free(bytes->start);
    free(bytes);
}