update of packages

This commit is contained in:
2023-11-04 19:26:41 +01:00
parent e162a12b58
commit 3b54a3236d
726 changed files with 297673 additions and 34585 deletions

View File

@@ -434,7 +434,8 @@ os_void() {
poppler-glib-devel
zlib-devel
make
pkgconf"
pkgconf
cairo-devel"
PKGCMD=xbps-install
PKGARGS="-Sy"
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/usr/lib/pkgconfig"

View File

@@ -370,17 +370,122 @@ mktempfile()
return filename;
}
/* Holds RGB, HSL, HSV, Lab, or Lch... but note that the order in memory for HSL
* and HSV are actually VSH and LSH. */
struct color
{
union
{
double r, v, l;
};
union
{
double g, s, a;
};
union
{
double b, h;
};
};
#define struct_color(x) (*((struct color *) x))
#define vec_color(x) ((double *) &x)
// Using values reported at https://bottosson.github.io/posts/oklab/#converting-from-linear-srgb-to-oklab
// instead of going through xyz. This ensures any whitepoint is ignored
static struct color
rgb2oklab(struct color rgb)
{
struct color srgb;
for (int i = 0; i < 3; i++)
{
double val = vec_color(rgb)[i];
vec_color(srgb)[i] = ((val > 0.04045)
? pow((val + 0.055) / 1.055, 2.4)
: (val / 12.92));
}
double l = 0.4121656120 * srgb.r + 0.5362752080 * srgb.g + 0.0514575653 * srgb.b;
double m = 0.2118591070 * srgb.r + 0.6807189584 * srgb.g + 0.1074065790 * srgb.b;
double s = 0.0883097947 * srgb.r + 0.2818474174 * srgb.g + 0.6302613616 * srgb.b;
l = cbrt(l);
m = cbrt(m);
s = cbrt(s);
return (struct color) {
.l = 0.2104542553 * l + 0.7936177850 * m - 0.0040720468 * s,
.a = 1.9779984951 * l - 2.4285922050 * m + 0.4505937099 * s,
.b = 0.0259040371 * l + 0.7827717662 * m - 0.8086757660 * s
};
}
static double clamp(double x, double low, double high)
{
return ((x < low)
? low
: ((x > high) ? high : x));
}
static struct color
oklab2rgb(struct color lab)
{
double l = lab.l + 0.3963377774 * lab.a + 0.2158037573 * lab.b;
double m = lab.l - 0.1055613458 * lab.a - 0.0638541728 * lab.b;
double s = lab.l - 0.0894841775 * lab.a - 1.2914855480 * lab.b;
l = l * l * l;
m = m * m * m;
s = s * s * s;
struct color srgb = {
.r = 4.0767245293 * l - 3.3072168827 * m + 0.2307590544 * s,
.g = -1.2681437731 * l + 2.6093323231 * m - 0.3411344290 * s,
.b = -0.0041119885 * l - 0.7034763098 * m + 1.7068625689 * s
};
struct color rgb;
for (int i = 0; i < 3; i++)
{
double val = vec_color(srgb)[i];
val = ((val > 0.0031308)
? (1.055 * pow(val, 1 / 2.4) - 0.055)
: (12.92 * val));
vec_color(rgb)[i] = clamp(val, 0.0, 1.0);
}
return rgb;
}
#undef struct_color
#undef vec_color
static inline gboolean color_equal(struct color a, struct color b)
{
return (a.r == b.r && a.g == b.g && a.b == b.b);
}
static void
image_recolor (cairo_surface_t * surface, const PopplerColor * fg,
const PopplerColor * bg)
const PopplerColor * bg, int usecolors)
{
/* uses a representation of a rgb color as follows:
- a lightness scalar (between 0,1), which is a weighted average of r, g, b,
- a hue vector, which indicates a radian direction from the grey axis,
inside the equal lightness plane.
- a saturation scalar between 0,1. It is 0 when grey, 1 when the color is
in the boundary of the rgb cube.
*/
/* Performs one of two kinds of image recoloring depending on the value of usecolors:
1 -> Bg-Fg Interpolation: maps source document colors to colors
interpolated between the background and foreground values in
pdf-view-midnight-colors via the lightness of the source color. This
discards hue information but allows you to fit your color theme
perfectly.
2 -> Hue-Preserving interpolation: same as above, similar to above, but
attempts to preserve hue while still respecting the background and
foreground colors. This is done by matching source document white and
black to the specified background and foreground as above, but mixes
hue/saturation with the background color. This preserves hue but is
more expensive.
*/
const unsigned int page_width = cairo_image_surface_get_width (surface);
const unsigned int page_height = cairo_image_surface_get_height (surface);
@@ -391,46 +496,131 @@ image_recolor (cairo_surface_t * surface, const PopplerColor * fg,
static const double a[] = { 0.30, 0.59, 0.11 };
const double f = 65535.;
const double rgb_fg[] = {
fg->red / f, fg->green / f, fg->blue / f
const struct color rgb_fg = {
.r = fg->red / f,
.g = fg->green / f,
.b = fg->blue / f
};
const double rgb_bg[] = {
bg->red / f, bg->green / f, bg->blue / f
const struct color rgb_bg = {
.r = bg->red / f,
.g = bg->green / f,
.b = bg->blue / f
};
const double rgb_diff[] = {
rgb_bg[0] - rgb_fg[0],
rgb_bg[1] - rgb_fg[1],
rgb_bg[2] - rgb_fg[2]
const struct color rgb_diff = {
.r = rgb_bg.r - rgb_fg.r,
.g = rgb_bg.g - rgb_fg.g,
.b = rgb_bg.b - rgb_fg.b
};
unsigned int y;
for (y = 0; y < page_height * rowstride; y += rowstride)
switch (usecolors)
{
unsigned char *data = image + y;
case 0:
break;
case 1:
{
unsigned int y;
for (y = 0; y < page_height * rowstride; y += rowstride)
{
unsigned char *data = image + y;
unsigned int x;
for (x = 0; x < page_width; x++, data += 4)
{
/* Careful. data color components blue, green, red. */
const double rgb[3] = {
(double) data[2] / 256.,
(double) data[1] / 256.,
(double) data[0] / 256.
};
unsigned int x;
for (x = 0; x < page_width; x++, data += 4)
{
/* Careful. data color components blue, green, red. */
struct color rgb = {
.r = (double) data[2] / 256.,
.g = (double) data[1] / 256.,
.b = (double) data[0] / 256.
};
/* compute h, s, l data */
double l = a[0] * rgb[0] + a[1] * rgb[1] + a[2] * rgb[2];
/* Linear interpolation between bg and fg based on the
perceptual lightness measure l */
/* compute h, s, l data */
double l = a[0] * rgb.r + a[1] * rgb.g + a[2] * rgb.b;
/* linear interpolation between dark and light with color ligtness as
* a parameter */
data[2] =
(unsigned char) round (255. * (l * rgb_diff[0] + rgb_fg[0]));
data[1] =
(unsigned char) round (255. * (l * rgb_diff[1] + rgb_fg[1]));
data[0] =
(unsigned char) round (255. * (l * rgb_diff[2] + rgb_fg[2]));
}
/* linear interpolation between dark and light with color
lightness as a parameter */
data[2] =
(unsigned char) round (255. * (l * rgb_diff.r + rgb_fg.r));
data[1] =
(unsigned char) round (255. * (l * rgb_diff.g + rgb_fg.g));
data[0] =
(unsigned char) round (255. * (l * rgb_diff.b + rgb_fg.b));
}
}
}
break;
case 2:
{
/* If using the Oklab transform, it is relatively expensive. Precompute
white->background and black->foreground and have a single entry cache to
speed up computation */
const struct color white = {.r = 1.0, .g = 1.0, .b = 1.0};
struct color precomputed_rgb = white;
struct color precomputed_inv_rgb = rgb_bg;
/* Must match the transformation of colors below. */
struct color oklab_fg = rgb2oklab(rgb_fg);
struct color oklab_bg = rgb2oklab(rgb_bg);
const double oklab_diff_l = oklab_fg.l - oklab_bg.l;
unsigned int y;
for (y = 0; y < page_height * rowstride; y += rowstride)
{
unsigned char *data = image + y;
unsigned int x;
for (x = 0; x < page_width; x++, data += 4)
{
/* Careful. data color components blue, green, red. */
struct color rgb = {
.r = (double) data[2] / 256.,
.g = (double) data[1] / 256.,
.b = (double) data[0] / 256.
};
/* Convert to Oklab coordinates, invert perceived lightness,
convert back to RGB. */
if (color_equal(white, rgb))
{
rgb = rgb_bg;
}
else if (color_equal(precomputed_rgb, rgb))
{
rgb = precomputed_inv_rgb;
}
else
{
struct color oklab = rgb2oklab(rgb);
precomputed_rgb = rgb;
/* Invert the perceived lightness, and scales it */
double l = oklab.l;
double inv_l = 1.0 - l;
oklab.l = oklab_bg.l + oklab_diff_l * inv_l;
/* Have a and b parameters (which encode hue and saturation)
start at the background value and interpolate up to
foreground */
oklab.a = (oklab.a + oklab_bg.a * l + oklab_fg.a * inv_l);
oklab.b = (oklab.b + oklab_bg.b * l + oklab_fg.b * inv_l);
rgb = oklab2rgb(oklab);
precomputed_inv_rgb = rgb;
}
data[2] = (unsigned char) round(255. * rgb.r);
data[1] = (unsigned char) round(255. * rgb.g);
data[0] = (unsigned char) round(255. * rgb.b);
}
}
}
break;
default:
internal_error ("image_recolor switch fell through");
}
}
@@ -501,8 +691,8 @@ image_render_page(PopplerDocument *pdf, PopplerPage *page,
cairo_paint (cr);
if (options && options->usecolors)
image_recolor (surface, &options->fg, &options->bg);
if (options && (options->usecolors))
image_recolor (surface, &options->fg, &options->bg, options->usecolors);
cairo_destroy (cr);
@@ -760,6 +950,26 @@ xpoppler_annot_text_state_string (PopplerAnnotTextState state)
}
};
/**
* Validate a PopplerSelectionStyle by replacing invalid styles
* with a default of POPPLER_SELECTION_GLYPH.
*
* @param selection_style The selection style.
*
* @return selection_style for valid styles, otherwise POPPLER_SELECTION_GLYPH.
*/
static PopplerSelectionStyle
xpoppler_validate_selection_style (int selection_style)
{
switch (selection_style) {
case POPPLER_SELECTION_GLYPH:
case POPPLER_SELECTION_WORD:
case POPPLER_SELECTION_LINE:
return selection_style;
}
return POPPLER_SELECTION_GLYPH;
}
static document_t*
document_open (const epdfinfo_t *ctx, const char *filename,
const char *passwd, GError **gerror)
@@ -1347,12 +1557,15 @@ annotation_markup_get_text_regions (PopplerPage *page, PopplerAnnotTextMarkup *a
*
* @param page The page of the annotation. This is used to get the
* text regions and pagesize.
* @param selection_style The selection style.
* @param region The region to add.
* @param garray[in,out] An array of PopplerQuadrilateral, where the
* new quadrilaterals will be appended.
*/
static void
annotation_markup_append_text_region (PopplerPage *page, PopplerRectangle *region,
annotation_markup_append_text_region (PopplerPage *page,
PopplerSelectionStyle selection_style,
PopplerRectangle *region,
GArray *garray)
{
gdouble height;
@@ -1360,7 +1573,7 @@ annotation_markup_append_text_region (PopplerPage *page, PopplerRectangle *regio
replacement. (poppler_page_get_selected_region returns a union
of rectangles.) */
GList *regions =
poppler_page_get_selection_region (page, 1.0, POPPLER_SELECTION_GLYPH, region);
poppler_page_get_selection_region (page, 1.0, selection_style, region);
GList *item;
poppler_page_get_size (page, NULL, &height);
@@ -1389,6 +1602,7 @@ annotation_markup_append_text_region (PopplerPage *page, PopplerRectangle *regio
*
* @param doc The document for which to create it.
* @param type The type of the annotation.
* @param selection_style The selection style.
* @param r The rectangle where annotation will end up on the page.
*
* @return The new annotation, or NULL, if the annotation type is
@@ -1396,8 +1610,9 @@ annotation_markup_append_text_region (PopplerPage *page, PopplerRectangle *regio
*/
static PopplerAnnot*
annotation_new (const epdfinfo_t *ctx, document_t *doc, PopplerPage *page,
const char *type, PopplerRectangle *r,
const command_arg_t *rest, char **error_msg)
const char *type, PopplerSelectionStyle selection_style,
PopplerRectangle *r, const command_arg_t *rest,
char **error_msg)
{
PopplerAnnot *a = NULL;
@@ -1420,6 +1635,21 @@ annotation_new (const epdfinfo_t *ctx, document_t *doc, PopplerPage *page,
#ifdef HAVE_POPPLER_ANNOT_MARKUP
garray = g_array_new (FALSE, FALSE, sizeof (PopplerQuadrilateral));
poppler_page_get_size (page, &width, &height);
if (nargs == 0)
{
PopplerQuadrilateral q;
q.p1.x = r->x1;
q.p1.y = r->y1;
q.p2.x = r->x2;
q.p2.y = r->y1;
q.p4.x = r->x2;
q.p4.y = r->y2;
q.p3.x = r->x1;
q.p3.y = r->y2;
g_array_append_val (garray, q);
}
for (i = 0; i < nargs; ++i)
{
PopplerRectangle *rr = &carg.value.rectangle;
@@ -1428,7 +1658,7 @@ annotation_new (const epdfinfo_t *ctx, document_t *doc, PopplerPage *page,
ARG_EDGES, error_msg));
rr->x1 *= width; rr->x2 *= width;
rr->y1 *= height; rr->y2 *= height;
annotation_markup_append_text_region (page, rr, garray);
annotation_markup_append_text_region (page, selection_style, rr, garray);
}
cerror_if_not (garray->len > 0, error_msg, "%s",
"Unable to create empty markup annotation");
@@ -2319,14 +2549,7 @@ cmd_gettext(const epdfinfo_t *ctx, const command_arg_t *args)
double width, height;
gchar *text = NULL;
switch (selection_style)
{
case POPPLER_SELECTION_GLYPH: break;
case POPPLER_SELECTION_LINE: break;
case POPPLER_SELECTION_WORD: break;
default: selection_style = POPPLER_SELECTION_GLYPH;
}
selection_style = xpoppler_validate_selection_style (selection_style);
page = poppler_document_get_page (doc, pn - 1);
perror_if_not (page, "No such page %d", pn);
poppler_page_get_size (page, &width, &height);
@@ -2368,7 +2591,7 @@ const command_arg_type_t cmd_getselection_spec[] =
{
ARG_DOC,
ARG_NATNUM, /* page number */
ARG_EDGES, /* selection */
ARG_EDGES, /* selection */
ARG_NATNUM /* selection-style */
};
@@ -2384,14 +2607,7 @@ cmd_getselection (const epdfinfo_t *ctx, const command_arg_t *args)
PopplerPage *page = NULL;
int i;
switch (selection_style)
{
case POPPLER_SELECTION_GLYPH: break;
case POPPLER_SELECTION_LINE: break;
case POPPLER_SELECTION_WORD: break;
default: selection_style = POPPLER_SELECTION_GLYPH;
}
selection_style = xpoppler_validate_selection_style (selection_style);
page = poppler_document_get_page (doc, pn - 1);
perror_if_not (page, "No such page %d", pn);
poppler_page_get_size (page, &width, &height);
@@ -2644,6 +2860,7 @@ const command_arg_type_t cmd_addannot_spec[] =
ARG_DOC,
ARG_NATNUM, /* page number */
ARG_STRING, /* type */
ARG_NATNUM, /* selection-style */
ARG_EDGES_OR_POSITION, /* edges or position (uses default size) */
ARG_REST, /* markup regions */
};
@@ -2655,7 +2872,8 @@ cmd_addannot (const epdfinfo_t *ctx, const command_arg_t *args)
document_t *doc = args->value.doc;
gint pn = args[1].value.natnum;
const char *type_string = args[2].value.string;
PopplerRectangle r = args[3].value.rectangle;
int selection_style = args[3].value.natnum;
PopplerRectangle r = args[4].value.rectangle;
int i;
PopplerPage *page = NULL;
double width, height;
@@ -2667,6 +2885,7 @@ cmd_addannot (const epdfinfo_t *ctx, const command_arg_t *args)
gdouble y2;
char *error_msg = NULL;
selection_style = xpoppler_validate_selection_style (selection_style);
page = poppler_document_get_page (doc->pdf, pn - 1);
perror_if_not (page, "Unable to get page %d", pn);
poppler_page_get_size (page, &width, &height);
@@ -2680,7 +2899,8 @@ cmd_addannot (const epdfinfo_t *ctx, const command_arg_t *args)
r.y2 = height - r.y1;
r.y1 = height - y2;
pa = annotation_new (ctx, doc, page, type_string, &r, &args[4], &error_msg);
pa = annotation_new (ctx, doc, page, type_string, selection_style, &r, &args[5],
&error_msg);
perror_if_not (pa, "Creating annotation failed: %s",
error_msg ? error_msg : "Reason unknown");
amap = poppler_annot_mapping_new ();
@@ -3074,6 +3294,7 @@ cmd_renderpage (const epdfinfo_t *ctx, const command_arg_t *args)
PopplerColor bg = { 65535, 0, 0 };
double alpha = 1.0;
double line_width = 1.5;
PopplerSelectionStyle selection_style = POPPLER_SELECTION_GLYPH;
PopplerRectangle cb = {0.0, 0.0, 1.0, 1.0};
int i = 0;
@@ -3202,10 +3423,18 @@ cmd_renderpage (const epdfinfo_t *ctx, const command_arg_t *args)
}
poppler_page_render_selection (page, cr, r, NULL,
POPPLER_SELECTION_GLYPH, &fg, &bg);
selection_style, &fg, &bg);
}
}
}
else if (! strcmp (keyword, ":selection-style"))
{
perror_if_not (command_arg_parse_arg (ctx, rest_args[i], &rest_arg,
ARG_NATNUM, &error_msg),
"%s", error_msg);
++i;
selection_style = xpoppler_validate_selection_style (rest_arg.value.natnum);
}
else
perror_if_not (0, "Unknown render command: %s", keyword);
}
@@ -3420,7 +3649,7 @@ cmd_charlayout(const epdfinfo_t *ctx, const command_arg_t *args)
const document_option_t document_options [] =
{
DEC_DOPT (":render/usecolors", ARG_BOOL, render.usecolors),
DEC_DOPT (":render/usecolors", ARG_NATNUM, render.usecolors),
DEC_DOPT (":render/printed", ARG_BOOL, render.printed),
DEC_DOPT (":render/foreground", ARG_COLOR, render.fg),
DEC_DOPT (":render/background", ARG_COLOR, render.bg),