/*
* Copyright (C) 2008 Inigo Martinez <inigomartinez@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <gtk/gtk.h>
#include <string.h>
#include "annots.h"
#include "utils.h"
enum {
ANNOTS_X1_COLUMN,
ANNOTS_Y1_COLUMN,
ANNOTS_X2_COLUMN,
ANNOTS_Y2_COLUMN,
ANNOTS_TYPE_COLUMN,
ANNOTS_COLOR_COLUMN,
ANNOTS_FLAG_INVISIBLE_COLUMN,
ANNOTS_FLAG_HIDDEN_COLUMN,
ANNOTS_FLAG_PRINT_COLUMN,
ANNOTS_COLUMN,
N_COLUMNS
};
typedef struct {
PopplerDocument *doc;
PopplerPage *page;
GtkListStore *model;
GtkWidget *annot_view;
GtkWidget *timer_label;
gint num_page;
} PgdAnnotsDemo;
static void
pgd_annots_free (PgdAnnotsDemo *demo)
{
if (!demo)
return;
if (demo->doc) {
g_object_unref (demo->doc);
demo->doc = NULL;
}
if (demo->page) {
g_object_unref (demo->page);
demo->page = NULL;
}
if (demo->model) {
g_object_unref (demo->model);
demo->model = NULL;
}
g_free (demo);
}
static GtkWidget *
pgd_annot_view_new (void)
{
GtkWidget *frame, *label;
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label), "<b>Annot Properties</b>");
gtk_frame_set_label_widget (GTK_FRAME (frame), label);
gtk_widget_show (label);
return frame;
}
const gchar *
get_annot_type (PopplerAnnot *poppler_annot)
{
switch (poppler_annot_get_annot_type (poppler_annot))
{
case POPPLER_ANNOT_TEXT:
return "Text";
case POPPLER_ANNOT_LINK:
return "Link";
case POPPLER_ANNOT_FREE_TEXT:
return "Free Text";
case POPPLER_ANNOT_LINE:
return "Line";
case POPPLER_ANNOT_SQUARE:
return "Square";
case POPPLER_ANNOT_CIRCLE:
return "Circle";
case POPPLER_ANNOT_POLYGON:
return "Polygon";
case POPPLER_ANNOT_POLY_LINE:
return "Poly Line";
case POPPLER_ANNOT_HIGHLIGHT:
return "Highlight";
case POPPLER_ANNOT_UNDERLINE:
return "Underline";
case POPPLER_ANNOT_SQUIGGLY:
return "Squiggly";
case POPPLER_ANNOT_STRIKE_OUT:
return "Strike Out";
case POPPLER_ANNOT_STAMP:
return "Stamp";
case POPPLER_ANNOT_CARET:
return "Caret";
case POPPLER_ANNOT_INK:
return "Ink";
case POPPLER_ANNOT_POPUP:
return "Popup";
case POPPLER_ANNOT_FILE_ATTACHMENT:
return "File Attachment";
case POPPLER_ANNOT_SOUND:
return "Sound";
case POPPLER_ANNOT_MOVIE:
return "Movie";
case POPPLER_ANNOT_WIDGET:
return "Widget";
case POPPLER_ANNOT_SCREEN:
return "Screen";
case POPPLER_ANNOT_PRINTER_MARK:
return "Printer Mark";
case POPPLER_ANNOT_TRAP_NET:
return "Trap Net";
case POPPLER_ANNOT_WATERMARK:
return "Watermark";
case POPPLER_ANNOT_3D:
return "3D";
default:
break;
}
return "Unknown";
}
GdkPixbuf *
get_annot_color (PopplerAnnot *poppler_annot)
{
PopplerColor *poppler_color;
if ((poppler_color = poppler_annot_get_color (poppler_annot))) {
GdkPixbuf *pixbuf;
gint rowstride, num, x;
guchar *pixels;
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
FALSE, 8,
64, 16);
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
pixels = gdk_pixbuf_get_pixels (pixbuf);
num = gdk_pixbuf_get_width (pixbuf) *
gdk_pixbuf_get_height (pixbuf);
for (x = 0; x < num; x++) {
pixels[0] = poppler_color->red;
pixels[1] = poppler_color->green;
pixels[2] = poppler_color->blue;
pixels += 3;
}
g_free (poppler_color);
return pixbuf;
}
return NULL;
}
gchar *
get_markup_date (PopplerAnnotMarkup *poppler_annot)
{
GDate *date;
struct tm t;
time_t timet;
date = poppler_annot_markup_get_date (poppler_annot);
if (!date)
return NULL