Gitweb links:
...log
http://git.netsurf-browser.org/libnspdf.git/shortlog/d9bf14b9a1a5fa577080...
...commit
http://git.netsurf-browser.org/libnspdf.git/commit/d9bf14b9a1a5fa5770808c...
...tree
http://git.netsurf-browser.org/libnspdf.git/tree/d9bf14b9a1a5fa5770808c18...
The branch, master has been updated
via d9bf14b9a1a5fa5770808c18d8039da0fb34021c (commit)
via 24f990ef17253074f3d667a8d4c88efd2fb1d4f6 (commit)
from d2d566cf50835d728f1c65ebeccf914b43d81867 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/libnspdf.git/commit/?id=d9bf14b9a1a5fa5770...
commit d9bf14b9a1a5fa5770808c18d8039da0fb34021c
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
fix line width scaling
diff --git a/src/cos_stream_filter.c b/src/cos_stream_filter.c
index 0c08442..c12f641 100644
--- a/src/cos_stream_filter.c
+++ b/src/cos_stream_filter.c
@@ -105,7 +105,7 @@ nspdf__cos_stream_filter(struct nspdf_doc *doc,
nspdferror res;
//printf("applying filter %s\n", filter_name);
-
+ /** \todo implement all the other mandantory stream filters */
if (strcmp(filter_name, "FlateDecode") == 0) {
res = cos_stream_inflate(doc, stream_out);
} else {
diff --git a/src/document.c b/src/document.c
index bd3d314..9e8ed22 100644
--- a/src/document.c
+++ b/src/document.c
@@ -22,6 +22,22 @@
#include "xref.h"
#include "pdf_doc.h"
+/*
+ * And you may find yourself
+ * Writing another PDF parser
+ * And you may find yourself
+ * In a middle of a debug session
+ * And you may find yourself
+ * Behind an British English keyboard
+ * And you may find yourself in a gdb
+ * With a long stacktrace
+ * And you may ask yourself, well
+ * How did I get here?
+ *
+ * Andrew Shadura 2018
+ */
+
+
#define SLEN(x) (sizeof((x)) - 1)
/* byte data acessory, allows for more complex buffer handling in future */
diff --git a/src/graphics_state.h b/src/graphics_state.h
index e5cc2bf..40060dd 100644
--- a/src/graphics_state.h
+++ b/src/graphics_state.h
@@ -52,7 +52,17 @@ struct graphics_state_param {
struct {
struct graphics_state_color colour;
} other;
- /* text state */
+ /** text state */
+ struct {
+ float charspacing;
+ float wordspacing;
+ float hscale;
+ float leading;
+ float fontsize;
+ unsigned int rendermode;
+ float rise;
+ /* knockout */
+ } text;
float line_width;
unsigned int line_cap;
unsigned int line_join;
diff --git a/src/page.c b/src/page.c
index 2a3a836..7a0a33b 100644
--- a/src/page.c
+++ b/src/page.c
@@ -13,6 +13,8 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
+#include <math.h>
+
#include <nspdf/page.h>
#include "graphics_state.h"
@@ -409,14 +411,31 @@ render_operation_f(struct graphics_state *gs, struct
nspdf_render_ctx* render_ct
return NSPDFERROR_OK;
}
+static inline nspdferror
+scale_stroke_width(float *ctm, float unscaled, float *scaled)
+{
+ float avscale;
+ avscale = (fabs(ctm[0]) + fabs(ctm[3])) / 2.0; /* average scale of x and y axis */
+
+ *scaled = unscaled * avscale;
+ if (*scaled < 0.1) {
+ /* printf("sx:%f sy:%f av:%f un:%f sc:%f\n",
+ ctm[0], ctm[3], avscale, unscaled, *scaled);*/
+ *scaled = 0.1;
+ }
+ return NSPDFERROR_OK;
+}
static inline nspdferror
render_operation_B(struct graphics_state *gs, struct nspdf_render_ctx* render_ctx)
{
struct nspdf_style style;
style.stroke_type = NSPDF_OP_TYPE_SOLID;
- style.stroke_width = gs->param_stack[gs->param_stack_idx].line_width;
- gsc_to_device(&gs->param_stack[gs->param_stack_idx].stroke.colour,
&style.stroke_colour);
+ scale_stroke_width(gs->param_stack[gs->param_stack_idx].ctm,
+ gs->param_stack[gs->param_stack_idx].line_width,
+ &style.stroke_width);
+ gsc_to_device(&gs->param_stack[gs->param_stack_idx].stroke.colour,
+ &style.stroke_colour);
style.fill_type = NSPDF_OP_TYPE_SOLID;
gsc_to_device(&gs->param_stack[gs->param_stack_idx].other.colour,
&style.fill_colour);
@@ -441,8 +460,11 @@ render_operation_S(struct graphics_state *gs, struct
nspdf_render_ctx* render_ct
style.fill_colour = 0x01000000;
style.stroke_type = NSPDF_OP_TYPE_SOLID;
- style.stroke_width = gs->param_stack[gs->param_stack_idx].line_width;
- gsc_to_device(&gs->param_stack[gs->param_stack_idx].stroke.colour,
&style.stroke_colour);
+ scale_stroke_width(gs->param_stack[gs->param_stack_idx].ctm,
+ gs->param_stack[gs->param_stack_idx].line_width,
+ &style.stroke_width);
+ gsc_to_device(&gs->param_stack[gs->param_stack_idx].stroke.colour,
+ &style.stroke_colour);
render_ctx->path(&style,
gs->path,
commitdiff
http://git.netsurf-browser.org/libnspdf.git/commit/?id=24f990ef17253074f3...
commit 24f990ef17253074f3d667a8d4c88efd2fb1d4f6
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
simplify path render a bit
diff --git a/src/page.c b/src/page.c
index 3b2371b..2a3a836 100644
--- a/src/page.c
+++ b/src/page.c
@@ -409,28 +409,6 @@ render_operation_f(struct graphics_state *gs, struct
nspdf_render_ctx* render_ct
return NSPDFERROR_OK;
}
-static inline nspdferror
-render_operation_b(struct graphics_state *gs, struct nspdf_render_ctx* render_ctx)
-{
- struct nspdf_style style;
- style.stroke_type = NSPDF_OP_TYPE_SOLID;
- style.stroke_width = gs->param_stack[gs->param_stack_idx].line_width;
- gsc_to_device(&gs->param_stack[gs->param_stack_idx].stroke.colour,
&style.stroke_colour);
-
- style.fill_type = NSPDF_OP_TYPE_SOLID;
- gsc_to_device(&gs->param_stack[gs->param_stack_idx].other.colour,
&style.fill_colour);
-
- gs->path[gs->path_idx++] = NSPDF_PATH_CLOSE;
-
- render_ctx->path(&style,
- gs->path,
- gs->path_idx,
- gs->param_stack[gs->param_stack_idx].ctm,
- render_ctx->ctx);
- gs->path_idx = 0;
-
- return NSPDFERROR_OK;
-}
static inline nspdferror
render_operation_B(struct graphics_state *gs, struct nspdf_render_ctx* render_ctx)
@@ -823,7 +801,8 @@ nspdf_page_render(struct nspdf_doc *doc,
case CONTENT_OP_b:
case CONTENT_OP_b_:
- res = render_operation_b(&gs, render_ctx);
+ render_operation_h(&gs);
+ res = render_operation_B(&gs, render_ctx);
break;
case CONTENT_OP_s:
-----------------------------------------------------------------------
Summary of changes:
src/cos_stream_filter.c | 2 +-
src/document.c | 16 ++++++++++++++++
src/graphics_state.h | 12 +++++++++++-
src/page.c | 45 +++++++++++++++++++++++----------------------
4 files changed, 51 insertions(+), 24 deletions(-)
diff --git a/src/cos_stream_filter.c b/src/cos_stream_filter.c
index 0c08442..c12f641 100644
--- a/src/cos_stream_filter.c
+++ b/src/cos_stream_filter.c
@@ -105,7 +105,7 @@ nspdf__cos_stream_filter(struct nspdf_doc *doc,
nspdferror res;
//printf("applying filter %s\n", filter_name);
-
+ /** \todo implement all the other mandantory stream filters */
if (strcmp(filter_name, "FlateDecode") == 0) {
res = cos_stream_inflate(doc, stream_out);
} else {
diff --git a/src/document.c b/src/document.c
index bd3d314..9e8ed22 100644
--- a/src/document.c
+++ b/src/document.c
@@ -22,6 +22,22 @@
#include "xref.h"
#include "pdf_doc.h"
+/*
+ * And you may find yourself
+ * Writing another PDF parser
+ * And you may find yourself
+ * In a middle of a debug session
+ * And you may find yourself
+ * Behind an British English keyboard
+ * And you may find yourself in a gdb
+ * With a long stacktrace
+ * And you may ask yourself, well
+ * How did I get here?
+ *
+ * Andrew Shadura 2018
+ */
+
+
#define SLEN(x) (sizeof((x)) - 1)
/* byte data acessory, allows for more complex buffer handling in future */
diff --git a/src/graphics_state.h b/src/graphics_state.h
index e5cc2bf..40060dd 100644
--- a/src/graphics_state.h
+++ b/src/graphics_state.h
@@ -52,7 +52,17 @@ struct graphics_state_param {
struct {
struct graphics_state_color colour;
} other;
- /* text state */
+ /** text state */
+ struct {
+ float charspacing;
+ float wordspacing;
+ float hscale;
+ float leading;
+ float fontsize;
+ unsigned int rendermode;
+ float rise;
+ /* knockout */
+ } text;
float line_width;
unsigned int line_cap;
unsigned int line_join;
diff --git a/src/page.c b/src/page.c
index 3b2371b..7a0a33b 100644
--- a/src/page.c
+++ b/src/page.c
@@ -13,6 +13,8 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
+#include <math.h>
+
#include <nspdf/page.h>
#include "graphics_state.h"
@@ -410,25 +412,17 @@ render_operation_f(struct graphics_state *gs, struct
nspdf_render_ctx* render_ct
}
static inline nspdferror
-render_operation_b(struct graphics_state *gs, struct nspdf_render_ctx* render_ctx)
+scale_stroke_width(float *ctm, float unscaled, float *scaled)
{
- struct nspdf_style style;
- style.stroke_type = NSPDF_OP_TYPE_SOLID;
- style.stroke_width = gs->param_stack[gs->param_stack_idx].line_width;
- gsc_to_device(&gs->param_stack[gs->param_stack_idx].stroke.colour,
&style.stroke_colour);
-
- style.fill_type = NSPDF_OP_TYPE_SOLID;
- gsc_to_device(&gs->param_stack[gs->param_stack_idx].other.colour,
&style.fill_colour);
-
- gs->path[gs->path_idx++] = NSPDF_PATH_CLOSE;
-
- render_ctx->path(&style,
- gs->path,
- gs->path_idx,
- gs->param_stack[gs->param_stack_idx].ctm,
- render_ctx->ctx);
- gs->path_idx = 0;
+ float avscale;
+ avscale = (fabs(ctm[0]) + fabs(ctm[3])) / 2.0; /* average scale of x and y axis */
+ *scaled = unscaled * avscale;
+ if (*scaled < 0.1) {
+ /* printf("sx:%f sy:%f av:%f un:%f sc:%f\n",
+ ctm[0], ctm[3], avscale, unscaled, *scaled);*/
+ *scaled = 0.1;
+ }
return NSPDFERROR_OK;
}
@@ -437,8 +431,11 @@ render_operation_B(struct graphics_state *gs, struct
nspdf_render_ctx* render_ct
{
struct nspdf_style style;
style.stroke_type = NSPDF_OP_TYPE_SOLID;
- style.stroke_width = gs->param_stack[gs->param_stack_idx].line_width;
- gsc_to_device(&gs->param_stack[gs->param_stack_idx].stroke.colour,
&style.stroke_colour);
+ scale_stroke_width(gs->param_stack[gs->param_stack_idx].ctm,
+ gs->param_stack[gs->param_stack_idx].line_width,
+ &style.stroke_width);
+ gsc_to_device(&gs->param_stack[gs->param_stack_idx].stroke.colour,
+ &style.stroke_colour);
style.fill_type = NSPDF_OP_TYPE_SOLID;
gsc_to_device(&gs->param_stack[gs->param_stack_idx].other.colour,
&style.fill_colour);
@@ -463,8 +460,11 @@ render_operation_S(struct graphics_state *gs, struct
nspdf_render_ctx* render_ct
style.fill_colour = 0x01000000;
style.stroke_type = NSPDF_OP_TYPE_SOLID;
- style.stroke_width = gs->param_stack[gs->param_stack_idx].line_width;
- gsc_to_device(&gs->param_stack[gs->param_stack_idx].stroke.colour,
&style.stroke_colour);
+ scale_stroke_width(gs->param_stack[gs->param_stack_idx].ctm,
+ gs->param_stack[gs->param_stack_idx].line_width,
+ &style.stroke_width);
+ gsc_to_device(&gs->param_stack[gs->param_stack_idx].stroke.colour,
+ &style.stroke_colour);
render_ctx->path(&style,
gs->path,
@@ -823,7 +823,8 @@ nspdf_page_render(struct nspdf_doc *doc,
case CONTENT_OP_b:
case CONTENT_OP_b_:
- res = render_operation_b(&gs, render_ctx);
+ render_operation_h(&gs);
+ res = render_operation_B(&gs, render_ctx);
break;
case CONTENT_OP_s:
--
PDF Manipulation Library