Commit cd77915f authored by simurgh9's avatar simurgh9
Browse files

debugging.

parent a73ea8d3
Pipeline #658449 failed with stages
in 1 minute and 56 seconds
From 073de2570304aade0f69823198dec839fc8cdfdd Mon Sep 17 00:00:00 2001
From: Anuj Khare <khareanuj18@gmail.com>
Date: Sun, 27 Jul 2014 08:04:41 +0200
Subject: [PATCH 1/4] core: Expose AnnotFreeText::parseAppearanceString
The frontends need to parse the DA string of the free text annotations
to get the font size and color of the text. This function is made public
to avoid the repeated effort.
---
poppler/Annot.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 8fde6a6..df01ab0 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -933,6 +933,7 @@ public:
// getters
GooString *getAppearanceString() const { return appearanceString; }
AnnotFreeTextQuadding getQuadding() const { return quadding; }
+ void parseAppearanceString(GooString *da, double &fontsize, AnnotColor* &fontcolor);
// return rc
GooString *getStyleString() const { return styleString; }
AnnotCalloutLine *getCalloutLine() const { return calloutLine; }
@@ -944,7 +945,6 @@ public:
protected:
void initialize(PDFDoc *docA, Dict *dict);
- static void parseAppearanceString(GooString *da, double &fontsize, AnnotColor* &fontcolor);
void generateFreeTextAppearance();
// required
--
1.9.1
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 15dbfe81..456f1900 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -1076,6 +1076,7 @@ public:
// getters
std::unique_ptr<DefaultAppearance> getDefaultAppearance() const;
VariableTextQuadding getQuadding() const { return quadding; }
+ void parseAppearanceString(GooString *da, double &fontsize, AnnotColor* &fontcolor);
// return rc
const GooString *getStyleString() const { return styleString.get(); }
AnnotCalloutLine *getCalloutLine() const { return calloutLine.get(); }
From 25ecf82123aa4dff2238bf420779ac6616976c1d Mon Sep 17 00:00:00 2001
From: Anuj Khare <khareanuj18@gmail.com>
Date: Mon, 21 Jul 2014 00:03:11 +0530
Subject: [PATCH 2/4] glib: Add PopplerFontDescription boxed type
This boxed type is used to represent the font attributes of annotations.
---
glib/poppler-annot.cc | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++
glib/poppler-annot.h | 14 ++++++++++++
glib/poppler.h | 1 +
3 files changed, 77 insertions(+)
diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc
index e87bce3..67602f4 100644
--- a/glib/poppler-annot.cc
+++ b/glib/poppler-annot.cc
@@ -1808,6 +1808,68 @@ poppler_annot_callout_line_free (PopplerAnnotCalloutLine *callout)
g_free (callout);
}
+/* PopplerFontDescription */
+POPPLER_DEFINE_BOXED_TYPE (PopplerFontDescription, poppler_font_description,
+ poppler_font_description_copy,
+ poppler_font_description_free)
+
+/**
+ * poppler_font_description_new:
+ *
+ * Creates a new empty #PopplerFontDescription.
+ *
+ * Return value: a new allocated #PopplerFontDescription, %NULL in other case.
+ * It must be freed with poppler_font_description_free when done.
+ **/
+PopplerFontDescription *
+poppler_font_description_new (void)
+{
+ return g_new0 (PopplerFontDescription, 1);
+}
+
+/**
+ * poppler_font_description_copy:
+ * @font: the #PopplerFontDescription to be copied.
+ *
+ * It does copy @font to a new #PopplerFontDescription.
+ *
+ * Return value: a new allocated #PopplerFontDescription as exact copy of
+ * @font, %NULL in other case. It must be freed with
+ poppler_font_description_free when done.
+ **/
+PopplerFontDescription *
+poppler_font_description_copy (PopplerFontDescription *font)
+{
+ PopplerFontDescription *new_font;
+
+ g_return_val_if_fail (font != NULL, NULL);
+
+ new_font = g_new0 (PopplerFontDescription, 1);
+
+ *new_font = *font;
+ new_font->name = g_strdup (font->name);
+ return new_font;
+}
+
+/**
+ * poppler_font_description_free:
+ * @font: a #PopplerFontDescription
+ *
+ * Frees the memory used by #PopplerFontDescription.
+ **/
+void
+poppler_font_description_free (PopplerFontDescription *font)
+{
+ if (font->name)
+ g_free (font->name);
+
+ if (font->color)
+ g_free (font->color);
+
+ g_free (font);
+}
+
+
/* PopplerAnnotMovie */
/**
diff --git a/glib/poppler-annot.h b/glib/poppler-annot.h
index 441563e..1177f13 100644
--- a/glib/poppler-annot.h
+++ b/glib/poppler-annot.h
@@ -64,6 +64,7 @@ G_BEGIN_DECLS
#define POPPLER_IS_ANNOT_LINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), POPPLER_TYPE_ANNOT_LINE))
#define POPPLER_TYPE_ANNOT_CALLOUT_LINE (poppler_annot_callout_line_get_type ())
+#define POPPLER_TYPE_FONT_DESCRIPTION (poppler_font_description_get_type ())
#define POPPLER_TYPE_ANNOT_CIRCLE (poppler_annot_circle_get_type ())
#define POPPLER_ANNOT_CIRCLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), POPPLER_TYPE_ANNOT_CIRCLE, PopplerAnnotCircle))
@@ -170,6 +171,13 @@ struct _PopplerAnnotCalloutLine
gdouble y3;
};
+struct _PopplerFontDescription
+{
+ PopplerColor *color;
+ gdouble size;
+ gchar *name;
+};
+
GType poppler_annot_get_type (void) G_GNUC_CONST;
PopplerAnnotType poppler_annot_get_annot_type (PopplerAnnot *poppler_annot);
gchar *poppler_annot_get_contents (PopplerAnnot *poppler_annot);
@@ -275,6 +283,12 @@ PopplerAnnotCalloutLine *poppler_annot_callout_line_new (
PopplerAnnotCalloutLine *poppler_annot_callout_line_copy (PopplerAnnotCalloutLine *callout);
void poppler_annot_callout_line_free (PopplerAnnotCalloutLine *callout);
+/* PopplerFontDescription */
+GType poppler_font_description_get_type (void) G_GNUC_CONST;
+PopplerFontDescription *poppler_font_description_new (void);
+PopplerFontDescription *poppler_font_description_copy (PopplerFontDescription *font);
+void poppler_font_description_free (PopplerFontDescription *font);
+
/* PopplerAnnotCircle */
GType poppler_annot_circle_get_type (void) G_GNUC_CONST;
PopplerAnnot *poppler_annot_circle_new (PopplerDocument *doc,
diff --git a/glib/poppler.h b/glib/poppler.h
index 4df9c0e..93f2d92 100644
--- a/glib/poppler.h
+++ b/glib/poppler.h
@@ -208,6 +208,7 @@ typedef struct _PopplerAnnotCalloutLine PopplerAnnotCalloutLine;
typedef struct _PopplerAnnotLine PopplerAnnotLine;
typedef struct _PopplerAnnotCircle PopplerAnnotCircle;
typedef struct _PopplerAnnotSquare PopplerAnnotSquare;
+typedef struct _PopplerFontDescription PopplerFontDescription;
typedef struct _PopplerQuadrilateral PopplerQuadrilateral;
typedef struct _PopplerStructureElement PopplerStructureElement;
typedef struct _PopplerStructureElementIter PopplerStructureElementIter;
--
1.9.1
diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc
index b995f037..f963e060 100644
--- a/glib/poppler-annot.cc
+++ b/glib/poppler-annot.cc
@@ -1888,6 +1888,67 @@ void poppler_annot_callout_line_free(PopplerAnnotCalloutLine *callout)
g_free(callout);
}
+/* PopplerFontDescription */
+POPPLER_DEFINE_BOXED_TYPE (PopplerFontDescription, poppler_font_description,
+ poppler_font_description_copy,
+ poppler_font_description_free)
+
+/**
+ * poppler_font_description_new:
+ *
+ * Creates a new empty #PopplerFontDescription.
+ *
+ * Return value: a new allocated #PopplerFontDescription, %NULL in other case.
+ * It must be freed with poppler_font_description_free when done.
+ **/
+PopplerFontDescription *
+poppler_font_description_new (void)
+{
+ return g_new0 (PopplerFontDescription, 1);
+}
+
+/**
+ * poppler_font_description_copy:
+ * @font: the #PopplerFontDescription to be copied.
+ *
+ * It does copy @font to a new #PopplerFontDescription.
+ *
+ * Return value: a new allocated #PopplerFontDescription as exact copy of
+ * @font, %NULL in other case. It must be freed with
+ poppler_font_description_free when done.
+ **/
+PopplerFontDescription *
+poppler_font_description_copy (PopplerFontDescription *font)
+{
+ PopplerFontDescription *new_font;
+
+ g_return_val_if_fail (font != NULL, NULL);
+
+ new_font = g_new0 (PopplerFontDescription, 1);
+
+ *new_font = *font;
+ new_font->name = g_strdup (font->name);
+ return new_font;
+}
+
+/**
+ * poppler_font_description_free:
+ * @font: a #PopplerFontDescription
+ *
+ * Frees the memory used by #PopplerFontDescription.
+ **/
+void
+poppler_font_description_free (PopplerFontDescription *font)
+{
+ if (font->name)
+ g_free (font->name);
+
+ if (font->color)
+ g_free (font->color);
+
+ g_free (font);
+}
+
/* PopplerAnnotMovie */
/**
* poppler_annot_movie_get_title:
diff --git a/glib/poppler-annot.h b/glib/poppler-annot.h
index 509ecdff..688d389c 100644
--- a/glib/poppler-annot.h
+++ b/glib/poppler-annot.h
@@ -63,6 +63,7 @@ G_BEGIN_DECLS
#define POPPLER_IS_ANNOT_LINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), POPPLER_TYPE_ANNOT_LINE))
#define POPPLER_TYPE_ANNOT_CALLOUT_LINE (poppler_annot_callout_line_get_type())
+#define POPPLER_TYPE_FONT_DESCRIPTION (poppler_font_description_get_type())
#define POPPLER_TYPE_ANNOT_CIRCLE (poppler_annot_circle_get_type())
#define POPPLER_ANNOT_CIRCLE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), POPPLER_TYPE_ANNOT_CIRCLE, PopplerAnnotCircle))
@@ -173,6 +174,13 @@ struct _PopplerAnnotCalloutLine
gdouble y3;
};
+struct _PopplerFontDescription
+{
+ PopplerColor *color;
+ gdouble size;
+ gchar *name;
+};
+
typedef enum
{
POPPLER_ANNOT_STAMP_ICON_UNKNOWN = 0,
@@ -331,6 +339,12 @@ PopplerAnnotCalloutLine *poppler_annot_callout_line_copy(PopplerAnnotCalloutLine
POPPLER_PUBLIC
void poppler_annot_callout_line_free(PopplerAnnotCalloutLine *callout);
+/* PopplerFontDescription */
+GType poppler_font_description_get_type (void) G_GNUC_CONST;
+PopplerFontDescription *poppler_font_description_new (void);
+PopplerFontDescription *poppler_font_description_copy (PopplerFontDescription *font);
+void poppler_font_description_free (PopplerFontDescription *font);
+
/* PopplerAnnotCircle */
POPPLER_PUBLIC
GType poppler_annot_circle_get_type(void) G_GNUC_CONST;
diff --git a/glib/poppler.h b/glib/poppler.h
index 710b7b23..7e538375 100644
--- a/glib/poppler.h
+++ b/glib/poppler.h
@@ -213,6 +213,7 @@ typedef struct _PopplerAnnotCalloutLine PopplerAnnotCalloutLine;
typedef struct _PopplerAnnotLine PopplerAnnotLine;
typedef struct _PopplerAnnotCircle PopplerAnnotCircle;
typedef struct _PopplerAnnotSquare PopplerAnnotSquare;
+typedef struct _PopplerFontDescription PopplerFontDescription;
typedef struct _PopplerQuadrilateral PopplerQuadrilateral;
typedef struct _PopplerStructureElement PopplerStructureElement;
typedef struct _PopplerStructureElementIter PopplerStructureElementIter;
From 9dfdaf6f206e61759ea9b4b8ebf9d41c515c45fa Mon Sep 17 00:00:00 2001
From: Anuj Khare <khareanuj18@gmail.com>
Date: Fri, 25 Jul 2014 15:17:15 +0200
Subject: [PATCH 3/4] glib: Extend FreeText annotation support
This patch allows adding new freetext annotations, their intent,
quadding and callout lines.
---
glib/poppler-annot.cc | 282 +++++++++++++++++++++++++++++++++++++++++++++++++-
glib/poppler-annot.h | 24 +++++
2 files changed, 305 insertions(+), 1 deletion(-)
diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc
index 67602f4..47e3ee5 100644
--- a/glib/poppler-annot.cc
+++ b/glib/poppler-annot.cc
@@ -41,6 +41,9 @@ typedef struct _PopplerAnnotLineClass PopplerAnnotLineClass;
typedef struct _PopplerAnnotCircleClass PopplerAnnotCircleClass;
typedef struct _PopplerAnnotSquareClass PopplerAnnotSquareClass;
+static PopplerColor *create_poppler_color_from_annot_color (AnnotColor *color);
+static AnnotColor *create_annot_color_from_poppler_color (PopplerColor *poppler_color);
+
struct _PopplerAnnotClass
{
GObjectClass parent_class;
@@ -79,6 +82,8 @@ struct _PopplerAnnotTextMarkupClass
struct _PopplerAnnotFreeText
{
PopplerAnnotMarkup parent_instance;
+
+ PopplerFontDescription *font;
};
struct _PopplerAnnotFreeTextClass
@@ -470,10 +475,92 @@ poppler_annot_free_text_class_init (PopplerAnnotFreeTextClass *klass)
{
}
+static GooString *create_appearance_string (PopplerFontDescription *font)
+{
+ if (!font)
+ return new GooString ("/Invalid_font 10 Tf");
+
+ /* Core does not parse the font name as of yet. */
+ GooString *s = new GooString ("/Invalid_font");
+ s->appendf (" {0:f} Tf", font->size);
+
+ if (font->color) {
+ AnnotColor *annot_color;
+ const double *values;
+
+ annot_color = create_annot_color_from_poppler_color (font->color);
+ values = annot_color->getValues ();
+
+ s->appendf (" {0:.2f} {1:.2f} {2:.2f} rg", values[0], values[1], values[2]);
+ delete annot_color;
+ }
+
+ return s;
+}
+
PopplerAnnot *
_poppler_annot_free_text_new (Annot *annot)
{
- return _poppler_create_annot (POPPLER_TYPE_ANNOT_FREE_TEXT, annot);
+ AnnotFreeText *annot_ftext;
+ PopplerAnnot *poppler_annot;
+ GooString *da;
+ AnnotColor *annot_color;
+ PopplerAnnotFreeText *poppler_ftext;
+
+ poppler_annot = _poppler_create_annot (POPPLER_TYPE_ANNOT_FREE_TEXT, annot);
+ poppler_ftext = POPPLER_ANNOT_FREE_TEXT (poppler_annot);
+
+ annot_ftext = static_cast<AnnotFreeText *>(annot);
+ da = annot_ftext->getAppearanceString();
+
+ g_assert (da!=NULL && da->getLength()!=0);
+
+ poppler_ftext->font = poppler_font_description_new ();
+ annot_ftext->parseAppearanceString (da, poppler_ftext->font->size, annot_color);
+ poppler_ftext->font->color = create_poppler_color_from_annot_color (annot_color);
+ delete annot_color;
+
+ return poppler_annot;
+}
+
+/**
+ * poppler_annot_free_text_new:
+ * @doc: a #PopplerDocument
+ * @rect: a #PopplerRectangle
+ * @poppler_font: a #PopplerFontDescription
+ *
+ * Creates a Free Text annotation with font attributes taken from
+ * @poppler_font that will be located on @rect when added to a page.
+ * See poppler_page_add_annot().
+ * Annotation takes ownership of the font description.
+ *
+ * Return value: A newly created #PopplerAnnotFreeText annotation
+ *
+ * Since: 0.28
+ */
+PopplerAnnot *
+poppler_annot_free_text_new (PopplerDocument *doc,
+ PopplerRectangle *rect,
+ PopplerFontDescription *font)
+{
+ PopplerAnnot *poppler_annot;
+ AnnotFreeText *annot;
+ GooString *goo_tmp;
+
+ PDFRectangle pdf_rect (rect->x1, rect->y1,
+ rect->x2, rect->y2);
+
+ g_return_val_if_fail (font != NULL, NULL);
+
+ goo_tmp = create_appearance_string (font);
+ annot = new AnnotFreeText (doc->doc, &pdf_rect, goo_tmp);
+ delete goo_tmp;
+
+ poppler_annot = _poppler_create_annot (POPPLER_TYPE_ANNOT_FREE_TEXT, annot);
+
+ POPPLER_ANNOT_FREE_TEXT (poppler_annot)->font = font;
+
+ return poppler_annot;
}
static void
@@ -1659,6 +1746,66 @@ poppler_annot_free_text_get_quadding (PopplerAnnotFreeText *poppler_annot)
}
/**
+ * poppler_annot_free_text_set_quadding:
+ * @poppler_annot: a #PopplerAnnotFreeText
+ * @quadding: a #PopplerAnnotFreeTextQuadding
+ *
+ * Sets the justification of the text of @poppler_annot.
+ *
+ * Since: 0.28
+ **/
+void
+poppler_annot_free_text_set_quadding (PopplerAnnotFreeText *poppler_annot,
+ PopplerAnnotFreeTextQuadding quadding)
+{
+ AnnotFreeText *annot;
+
+ g_return_if_fail (POPPLER_IS_ANNOT_FREE_TEXT (poppler_annot));
+
+ annot = static_cast<AnnotFreeText *>(POPPLER_ANNOT (poppler_annot)->annot);
+ annot->setQuadding ((AnnotFreeText::AnnotFreeTextQuadding) quadding);
+}
+
+/**
+ * poppler_annot_free_text_get_intent:
+ * @poppler_annot: a #PopplerAnnotFreeText
+ * @intent: a #PopplerAnnotFreeTextIntent
+ *
+ * Returns: the intent of the text of @poppler_annot.
+ * Since: 0.28
+ **/
+PopplerAnnotFreeTextIntent
+poppler_annot_free_text_get_intent (PopplerAnnotFreeText *poppler_annot)
+{
+ AnnotFreeText *annot;
+
+ g_return_val_if_fail (POPPLER_IS_ANNOT_FREE_TEXT (poppler_annot), POPPLER_ANNOT_FREE_TEXT_INTENT_FREE_TEXT);
+
+ annot = static_cast<AnnotFreeText *>(POPPLER_ANNOT (poppler_annot)->annot);
+ return (PopplerAnnotFreeTextIntent) annot->getIntent ();
+}
+
+/**
+ * poppler_annot_free_text_set_intent:
+ * @poppler_annot: a #PopplerAnnotFreeText
+ * @intent: a #PopplerAnnotFreeTextIntent
+ *
+ * Sets the intent of the text of @poppler_annot.
+ * Since: 0.28
+ **/
+void
+poppler_annot_free_text_set_intent (PopplerAnnotFreeText *poppler_annot,
+ PopplerAnnotFreeTextIntent intent)
+{
+ AnnotFreeText *annot;
+
+ g_return_if_fail (POPPLER_IS_ANNOT_FREE_TEXT (poppler_annot));
+
+ annot = static_cast<AnnotFreeText *>(POPPLER_ANNOT (poppler_annot)->annot);
+ annot->setIntent ((AnnotFreeText::AnnotFreeTextIntent) intent);
+}
+
+/**
* poppler_annot_free_text_get_callout_line:
* @poppler_annot: a #PopplerAnnotFreeText
*
@@ -1702,6 +1849,139 @@ poppler_annot_free_text_get_callout_line (PopplerAnnotFreeText *poppler_annot)
return NULL;
}
+/**
+ * poppler_annot_free_text_set_callout_line:
+ * @poppler_annot: a #PopplerAnnotFreeText
+ * @callout: (allow-none): a #PopplerAnnotCalloutLine
+ *
+ * Sets the callout line of the text of @poppler_annot to @callout,
+ * or removes the callout line if %NULL
+ *
+ * Since: 0.28
+ **/
+void
+poppler_annot_free_text_set_callout_line (PopplerAnnotFreeText *poppler_annot,
+ PopplerAnnotCalloutLine *callout)
+{
+ AnnotFreeText *annot;
+ AnnotCalloutLine *line = NULL;
+
+ g_return_if_fail (POPPLER_IS_ANNOT_FREE_TEXT (poppler_annot));
+
+ if (callout != NULL) {
+ if (callout->multiline) {
+ line = new AnnotCalloutMultiLine (callout->x1, callout->y1,
+ callout->x2, callout->y2,
+ callout->x3, callout->y3);
+ } else {
+ line = new AnnotCalloutLine (callout->x1, callout->y1,
+ callout->x2, callout->y2);
+ }
+ }
+
+ annot = static_cast<AnnotFreeText *>(POPPLER_ANNOT (poppler_annot)->annot);
+ annot->setCalloutLine (line);
+ if (line)
+ delete line;
+}
+
+static void
+poppler_annot_free_text_set_appearance_string (PopplerAnnotFreeText *poppler_annot)
+{
+ AnnotFreeText *annot;
+ GooString *da;
+
+ annot = static_cast<AnnotFreeText *>(POPPLER_ANNOT (poppler_annot)->annot);
+ da = create_appearance_string (poppler_annot->font);
+ annot->setAppearanceString(da);
+ delete da;
+}
+
+/**
+ * poppler_annot_free_text_get_font_size:
+ * @poppler_annot: a #PopplerAnnotFreeText
+ *
+ * Retrieves the font size of @poppler_annot.
+ *
+ * Return value: The font size of the @poppler_annot.
+ * Since: 0.28
+ **/
+gdouble
+poppler_annot_free_text_get_font_size (PopplerAnnotFreeText *poppler_annot)
+{
+ g_return_val_if_fail (POPPLER_IS_ANNOT_FREE_TEXT (poppler_annot), -1);
+
+ return poppler_annot->font->size;
+}
+
+/**
+ * poppler_annot_free_text_set_font_size:
+ * @poppler_annot: a #PopplerAnnotFreeText
+ * @size: a gdouble
+ *
+ * Sets the font size of the @poppler_annot to @size.
+ *
+ * Since: 0.28
+ **/
+void
+poppler_annot_free_text_set_font_size (PopplerAnnotFreeText *poppler_annot,
+ gdouble size)
+{
+ g_return_if_fail (POPPLER_IS_ANNOT_FREE_TEXT (poppler_annot));
+
+ poppler_annot->font->size = size;
+ poppler_annot_free_text_set_appearance_string (poppler_annot);
+}
+
+/**
+ * poppler_annot_free_text_get_font_color:
+ * @poppler_annot: a #PopplerAnnotFreeText
+ *
+ * Retrieves the font color of @poppler_annot.
+ *
+ * Return value: (transfer none): a #PopplerColor with the font color
+ * values of @poppler_annot, or %NULL.
+ * Since: 0.28
+ **/
+PopplerColor *
+poppler_annot_free_text_get_font_color (PopplerAnnotFreeText *poppler_annot)
+{
+ g_return_val_if_fail (POPPLER_IS_ANNOT_FREE_TEXT (poppler_annot), NULL);
+
+ return poppler_annot->font->color;
+}
+
+/**
+ * poppler_annot_free_text_set_font_color:
+ * @poppler_annot: a #PopplerAnnotFreeText
+ * @poppler_color: (allow-none): a #PopplerColor, or %NULL
+ *
+ * Sets the color of @poppler_annot to @poppler_color, or if %NULL,