Skip to content

Commit

Permalink
init mupdf 1.24
Browse files Browse the repository at this point in the history
  • Loading branch information
foobnix committed Mar 15, 2024
1 parent 88cbcf7 commit 5cdd18f
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 58 deletions.
1 change: 1 addition & 0 deletions Builder/jni/~mupdf-1.24.0-rc1/compressed-buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ enum
FZ_IMAGE_PNM,
FZ_IMAGE_TIFF,
FZ_IMAGE_PSD,
FZ_IMAGE_WEBP,
};

/**
Expand Down
1 change: 1 addition & 0 deletions Builder/jni/~mupdf-1.24.0-rc1/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ struct fz_context
fz_colorspace_context *colorspace;
fz_store *store;
fz_glyph_cache *glyph_cache;
float image_scale;
};

fz_context *fz_new_context_imp(const fz_alloc_context *alloc, const fz_locks_context *locks, size_t max_store, const char *version);
Expand Down
79 changes: 60 additions & 19 deletions Builder/jni/~mupdf-1.24.0-rc1/css-apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ fz_css_strtof(char *s, char **endptr)
}

static fz_css_number
number_from_value(fz_css_value *value, float initial, int initial_unit)
number_from_value_in(fz_css_value *value, float initial, int initial_unit, int isFont)
{
char *p;

Expand All @@ -907,7 +907,8 @@ number_from_value(fz_css_value *value, float initial, int initial_unit)
float x = fz_css_strtof(value->data, &p);

if (p[0] == 'e' && p[1] == 'm' && p[2] == 0)
return make_number(x, N_SCALE);
return isFont? make_number(x < 0.5 ? 0.5: x, N_SCALE) : make_number(x, N_SCALE);

if (p[0] == 'e' && p[1] == 'x' && p[2] == 0)
return make_number(x / 2, N_SCALE);

Expand All @@ -921,19 +922,19 @@ number_from_value(fz_css_value *value, float initial, int initial_unit)
return make_number(x * 12, N_LENGTH);

if (p[0] == 'p' && p[1] == 't' && p[2] == 0)
return make_number(x, N_LENGTH);
return isFont? make_number(x / 12 < 1 ? 1 : x / 12, N_SCALE) :make_number(x, N_LENGTH);

if (p[0] == 'p' && p[1] == 'x' && p[2] == 0)
return make_number(x, N_LENGTH);
return isFont? make_number(x / 25 < 1 ? 1 : x / 25, N_SCALE): make_number(x, N_LENGTH);

/* FIXME: 'rem' should be 'em' of root element. This is a bad approximation. */
if (p[0] == 'r' && p[1] == 'e' && p[2] == 'm' && p[3] == 0)
return make_number(x * 16, N_LENGTH);
return isFont? make_number(x <1.0 ? 1: x, N_SCALE) : make_number(x, N_SCALE);


/* FIXME: 'ch' should be width of '0' character. This is an approximation. */
if (p[0] == 'c' && p[1] == 'h' && p[2] == 0)
return make_number(x / 2, N_LENGTH);

return make_number(x, N_LENGTH);
return make_number(x, N_SCALE);
}

if (value->type == CSS_KEYWORD)
Expand All @@ -945,6 +946,16 @@ number_from_value(fz_css_value *value, float initial, int initial_unit)
return make_number(initial, initial_unit);
}


static fz_css_number
number_from_value(fz_css_value *value, float initial, int initial_unit){
return number_from_value_in(value, initial, initial_unit, 0);
}
static fz_css_number
number_from_value_font(fz_css_value *value, float initial, int initial_unit){
return number_from_value_in(value, initial, initial_unit, 1);
}

static fz_css_number
number_from_property(fz_css_match *match, int property, float initial, int initial_unit)
{
Expand Down Expand Up @@ -977,6 +988,7 @@ border_style_from_property(fz_css_match *match, int property)
if (!strcmp(value->data, "none")) return BS_NONE;
else if (!strcmp(value->data, "hidden")) return BS_NONE;
else if (!strcmp(value->data, "solid")) return BS_SOLID;
else if (!strcmp(value->data, "dotted")) return BS_SOLID;
}
return BS_NONE;
}
Expand Down Expand Up @@ -1301,21 +1313,39 @@ fz_apply_css_style(fz_context *ctx, fz_html_font_set *set, fz_css_style *style,
value = value_from_property(match, PRO_FONT_SIZE);
if (value)
{
if (!strcmp(value->data, "xx-large")) style->font_size = make_number(1.73f, N_SCALE);
else if (!strcmp(value->data, "x-large")) style->font_size = make_number(1.44f, N_SCALE);
if (!strcmp(value->data, "xx-large")) style->font_size = make_number(1.7f, N_SCALE);
else if (!strcmp(value->data, "x-large")) style->font_size = make_number(1.4f, N_SCALE);
else if (!strcmp(value->data, "xxx-large")) style->font_size = make_number(2.0f, N_SCALE);
else if (!strcmp(value->data, "large")) style->font_size = make_number(1.2f, N_SCALE);
else if (!strcmp(value->data, "medium")) style->font_size = make_number(1.0f, N_SCALE);
else if (!strcmp(value->data, "small")) style->font_size = make_number(0.83f, N_SCALE);
else if (!strcmp(value->data, "x-small")) style->font_size = make_number(0.69f, N_SCALE);
else if (!strcmp(value->data, "xx-small")) style->font_size = make_number(0.69f, N_SCALE);
else if (!strcmp(value->data, "normal")) style->font_size = make_number(1.0f, N_SCALE);
else if (!strcmp(value->data, "small")) style->font_size = make_number(0.8f, N_SCALE);
else if (!strcmp(value->data, "x-small")) style->font_size = make_number(0.6f, N_SCALE);
else if (!strcmp(value->data, "xx-small")) style->font_size = make_number(0.5f, N_SCALE);
else if (!strcmp(value->data, "larger")) style->font_size = make_number(1.2f, N_SCALE);
else if (!strcmp(value->data, "smaller")) style->font_size = make_number(1/1.2f, N_SCALE);
else style->font_size = number_from_value(value, 12, N_LENGTH);
else if (!strcmp(value->data, "inherit")) style->font_size = make_number(1.0f, N_SCALE);
else if (!strcmp(value->data, "initial")) style->font_size = make_number(1.0f, N_SCALE);
else if (!strcmp(value->data, "unset")) style->font_size = make_number(1.0f, N_SCALE);
else if (!strcmp(value->data, "revert")) style->font_size = make_number(1.0f, N_SCALE);
else if (!strcmp(value->data, "revert-layer")) style->font_size = make_number(1.0f, N_SCALE);
else if (!strcmp(value->data, "math")) style->font_size = make_number(1.0f, N_SCALE);
else
{
if (value->type == CSS_PERCENT){
style->font_size = make_number(fz_css_strtof(value->data, NULL)/100, N_SCALE);
}else{
//style->font_size = number_from_value(value, 12, N_LENGTH);
style->font_size = number_from_value_font(value, 12, N_LENGTH);


}
}
}
else
{
style->font_size = make_number(1, N_SCALE);
}
{
style->font_size = make_number(1, N_SCALE);
}

value = value_from_property(match, PRO_LIST_STYLE_TYPE);
if (value)
Expand Down Expand Up @@ -1350,8 +1380,8 @@ fz_apply_css_style(fz_context *ctx, fz_html_font_set *set, fz_css_style *style,

style->text_indent = number_from_property(match, PRO_TEXT_INDENT, 0, N_LENGTH);

style->width = number_from_property(match, PRO_WIDTH, 0, N_AUTO);
style->height = number_from_property(match, PRO_HEIGHT, 0, N_AUTO);
//style->width = number_from_property(match, PRO_WIDTH, 0, N_AUTO);
//style->height = number_from_property(match, PRO_HEIGHT, 0, N_AUTO);

style->margin[0] = number_from_property(match, PRO_MARGIN_TOP, 0, N_LENGTH);
style->margin[1] = number_from_property(match, PRO_MARGIN_RIGHT, 0, N_LENGTH);
Expand Down Expand Up @@ -1404,6 +1434,17 @@ fz_apply_css_style(fz_context *ctx, fz_html_font_set *set, fz_css_style *style,
if (!style->font)
style->font = fz_load_html_font(ctx, set, "serif", is_bold, is_italic, style->small_caps);
}


style->padding[1].value = style->padding[1].value / 2;
style->padding[3].value = style->padding[3].value / 2;

style->margin[1].value = style->margin[1].value / 2;
style->margin[3].value = style->margin[3].value / 2;


if (style->line_height.value < 0) style->line_height.value = 1.2f;

}

#ifdef DEBUG_CSS_SPLAY
Expand Down
11 changes: 10 additions & 1 deletion Builder/jni/~mupdf-1.24.0-rc1/html-layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -1806,6 +1806,15 @@ fz_layout_html(fz_context *ctx, fz_html *html, float w, float h, float em)
#endif
}

const fz_stroke_state librera_stroke_state = {
-2, /* -2 is the magic number we use when we have stroke states stored on the stack */
FZ_LINECAP_BUTT, FZ_LINECAP_BUTT, FZ_LINECAP_BUTT,
FZ_LINEJOIN_MITER,
3, 10,
0, 0, { 0 }
};


/* === DRAW === */

static int draw_flow_box(fz_context *ctx, fz_html_box *box, float page_top, float page_bot, fz_device *dev, fz_matrix ctm, hb_buffer_t *hb_buf, fz_html_restarter *restart)
Expand Down Expand Up @@ -2010,7 +2019,7 @@ static int draw_flow_box(fz_context *ctx, fz_html_box *box, float page_top, floa

if (line)
{
fz_stroke_path(ctx, dev, line, &fz_default_stroke_state, ctm, fz_device_rgb(ctx), color, 1, fz_default_color_params);
fz_stroke_path(ctx, dev, line, &librera_stroke_state, ctm, fz_device_rgb(ctx), color, 10, fz_default_color_params);
fz_drop_path(ctx, line);
line = NULL;
}
Expand Down
52 changes: 32 additions & 20 deletions Builder/jni/~mupdf-1.24.0-rc1/html-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,11 +546,11 @@ static fz_image *load_html_image(fz_context *ctx, fz_archive *zip, const char *b
fz_urldecode(path);
buf = fz_read_archive_entry(ctx, zip, path);
}
#if FZ_ENABLE_SVG

if (strstr(src, ".svg"))
img = fz_new_image_from_svg(ctx, buf, base_uri, zip);
else
#endif

img = fz_new_image_from_buffer(ctx, buf);
}
fz_always(ctx)
Expand All @@ -568,15 +568,12 @@ static fz_image *load_svg_image(fz_context *ctx, fz_archive *zip, const char *ba
fz_xml_doc *xmldoc, fz_xml *node)
{
fz_image *img = NULL;
#if FZ_ENABLE_SVG

fz_try(ctx)
img = fz_new_image_from_svg_xml(ctx, xmldoc, node, base_uri, zip);
fz_catch(ctx)
{
fz_ignore_error(ctx);
fz_warn(ctx, "html: cannot load embedded svg document");
}
#endif

return img;
}

Expand All @@ -591,16 +588,16 @@ static void generate_image(fz_context *ctx, fz_html_box *box, fz_image *img, str

if (!img)
{
const char *alt = "[image]";
add_flow_word(ctx, pool, flow, box, alt, alt + 7, 0);
//const char *alt = "[image]";
//add_flow_word(ctx, pool, flow, box, alt, alt + 7, 0);
}
else
{
fz_try(ctx)
{
add_flow_sbreak(ctx, pool, flow, box);
add_flow_image(ctx, pool, flow, box, img);
add_flow_sbreak(ctx, pool, flow, box);
//add_flow_sbreak(ctx, pool, flow, box);
}
fz_always(ctx)
{
Expand Down Expand Up @@ -965,7 +962,15 @@ static void gen2_image_common(fz_context *ctx, struct genstate *g, fz_html_box *

static void gen2_image_html(fz_context *ctx, struct genstate *g, fz_html_box *root_box, fz_xml *node, int display, fz_css_style *style)
{
const char *src = fz_xml_att(node, "src");
char *src = fz_xml_att(node, "src");

if(!src){
src = fz_xml_att(node, "href");
}
if(!src){
src = fz_xml_att(node, "l:href");
}

if (src)
{
fz_css_style local_style = *style;
Expand Down Expand Up @@ -999,6 +1004,10 @@ static void gen2_image_fb2(fz_context *ctx, struct genstate *g, fz_html_box *roo
{
fz_image *img = fz_tree_lookup(ctx, g->images, src+1);
gen2_image_common(ctx, g, root_box, node, fz_keep_image(ctx, img), display, style);
}else{
fz_css_style local_style = *style;
fz_image *img = load_html_image(ctx, g->zip, g->base_uri, src);
gen2_image_common(ctx, g, root_box, node, img, display, &local_style);
}
}

Expand Down Expand Up @@ -1165,8 +1174,9 @@ static void gen2_children(fz_context *ctx, struct genstate *g, fz_html_box *root
{
gen2_image_html(ctx, g, root_box, node, display, &style);
}
else if (g->is_fb2 && tag[0]=='i' && tag[1]=='m' && tag[2]=='a' && tag[3]=='g' && tag[4]=='e' && tag[5]==0)
else if (tag[0]=='i' && tag[1]=='m' && tag[2]=='a' && tag[3]=='g' && tag[4]=='e' && tag[5]==0)
{
gen2_image_html(ctx, g, root_box, node, display, &style);
gen2_image_fb2(ctx, g, root_box, node, display, &style);
}
else if (tag[0]=='s' && tag[1]=='v' && tag[2]=='g' && tag[3]==0)
Expand Down Expand Up @@ -1635,32 +1645,34 @@ xml_to_boxes(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const char
if (try_fictionbook && fz_xml_find(root, "FictionBook"))
{
g.is_fb2 = 1;
fz_parse_css(ctx, g.css, fb2_default_css, "<default:fb2>");
if (fz_use_document_css(ctx))
fb2_load_css(ctx, g.set, g.zip, g.base_uri, g.css, root);

//fz_parse_css(ctx, g.css, user_css, "<default:fb2>");
//if (fz_use_document_css(ctx))
// fb2_load_css(ctx, g.set, g.zip, g.base_uri, g.css, root);
g.images = load_fb2_images(ctx, root);
}
else if (is_mobi)
{
g.is_fb2 = 0;
fz_parse_css(ctx, g.css, html_default_css, "<default:html>");
fz_parse_css(ctx, g.css, mobi_default_css, "<default:mobi>");
//fz_parse_css(ctx, g.css, user_css, "<default:html>");
//fz_parse_css(ctx, g.css, mobi_default_css, "<default:mobi>");
if (fz_use_document_css(ctx))
html_load_css(ctx, g.set, g.zip, g.base_uri, g.css, root);
}
else
{
g.is_fb2 = 0;
fz_parse_css(ctx, g.css, html_default_css, "<default:html>");
//fz_parse_css(ctx, g.css, user_css, "<default:html>");
if (fz_use_document_css(ctx))
html_load_css(ctx, g.set, g.zip, g.base_uri, g.css, root);
}

if (user_css)
{
fz_parse_css(ctx, g.css, user_css, "<user>");
fz_add_css_font_faces(ctx, g.set, g.zip, ".", g.css);

}
fz_parse_css(ctx, g.css, user_css, "<user>");
fz_add_css_font_faces(ctx, g.set, g.zip, ".", g.css);
}
fz_catch(ctx)
{
Expand Down
3 changes: 2 additions & 1 deletion Builder/jni/~mupdf-1.24.0-rc1/image-imp.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fz_pixmap *fz_load_gif(fz_context *ctx, const unsigned char *data, size_t size);
fz_pixmap *fz_load_bmp(fz_context *ctx, const unsigned char *data, size_t size);
fz_pixmap *fz_load_pnm(fz_context *ctx, const unsigned char *data, size_t size);
fz_pixmap *fz_load_jbig2(fz_context *ctx, const unsigned char *data, size_t size);
fz_pixmap *fz_load_webp(fz_context *ctx, const unsigned char *data, size_t size);

void fz_load_jpeg_info(fz_context *ctx, const unsigned char *data, size_t size, int *w, int *h, int *xres, int *yres, fz_colorspace **cspace, uint8_t *orientation);
void fz_load_jpx_info(fz_context *ctx, const unsigned char *data, size_t size, int *w, int *h, int *xres, int *yres, fz_colorspace **cspace);
Expand All @@ -43,5 +44,5 @@ void fz_load_gif_info(fz_context *ctx, const unsigned char *data, size_t size, i
void fz_load_bmp_info(fz_context *ctx, const unsigned char *data, size_t size, int *w, int *h, int *xres, int *yres, fz_colorspace **cspace);
void fz_load_pnm_info(fz_context *ctx, const unsigned char *data, size_t size, int *w, int *h, int *xres, int *yres, fz_colorspace **cspace);
void fz_load_jbig2_info(fz_context *ctx, const unsigned char *data, size_t size, int *w, int *h, int *xres, int *yres, fz_colorspace **cspace);

void fz_load_webp_info(fz_context *ctx, const unsigned char *data, size_t size, int *w, int *h, int *xres, int *yres, fz_colorspace **cspace);
#endif
12 changes: 10 additions & 2 deletions Builder/jni/~mupdf-1.24.0-rc1/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,9 @@ compressed_image_get_pixmap(fz_context *ctx, fz_image *image_, fz_irect *subarea
case FZ_IMAGE_PSD:
tile = fz_load_psd(ctx, image->buffer->buffer->data, image->buffer->buffer->len);
break;
case FZ_IMAGE_WEBP:
tile = fz_load_webp(ctx, image->buffer->buffer->data, image->buffer->buffer->len);
break;
case FZ_IMAGE_JPEG:
/* Scan JPEG stream and patch missing height values in header */
{
Expand Down Expand Up @@ -1328,6 +1331,8 @@ fz_recognize_image_format(fz_context *ctx, unsigned char p[8])
return FZ_IMAGE_JBIG2;
if (p[0] == '8' && p[1] == 'B' && p[2] == 'P' && p[3] == 'S')
return FZ_IMAGE_PSD;
if (!memcmp(p, "RIFF", 4))
return FZ_IMAGE_WEBP;
return FZ_IMAGE_UNKNOWN;
}

Expand All @@ -1344,8 +1349,8 @@ fz_new_image_from_buffer(fz_context *ctx, fz_buffer *buffer)
int bpc;
uint8_t orientation = 0;

if (len < 8)
fz_throw(ctx, FZ_ERROR_FORMAT, "unknown image file format");
if (len < 16)
fz_throw(ctx, FZ_ERROR_GENERIC, "unknown image file format");

type = fz_recognize_image_format(ctx, buf);
bpc = 8;
Expand Down Expand Up @@ -1378,6 +1383,9 @@ fz_new_image_from_buffer(fz_context *ctx, fz_buffer *buffer)
case FZ_IMAGE_BMP:
fz_load_bmp_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace);
break;
case FZ_IMAGE_WEBP:
fz_load_webp_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace);
break;
case FZ_IMAGE_JBIG2:
fz_load_jbig2_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace);
bpc = 1;
Expand Down
5 changes: 3 additions & 2 deletions Builder/jni/~mupdf-1.24.0-rc1/list-device.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,9 @@ fz_append_display_node(
}
if (private_data_len)
{
if (cmd_needs_alignment(cmd))
pad_size_for_pointer(list, &size);
//#707236 fix freeze PDF
//if (cmd_needs_alignment(cmd))
pad_size_for_pointer(list, &size);
private_off = size;
size += SIZE_IN_NODES(private_data_len);
}
Expand Down
Loading

0 comments on commit 5cdd18f

Please sign in to comment.