Commit 45993a6f authored by Albert Astals Cid's avatar Albert Astals Cid

2007-04-28 Carlos Garcia Campos <carlosgc@gnome.org>

        reviewed and some code by: Albert Astals Cid <aacid@kde.org>

        * glib/poppler-page.cc:
        * glib/poppler-page.h:
        * glib/poppler.h:
        * glib/test-poppler-glib.c:
        * poppler/Makefile.am:
        * poppler/PageTransition.cc:
        * poppler/PageTransition.h:
        * qt/poppler-page-transition.cc:
        * qt/poppler-page-transition.h: Move Page Transition parsing from qt
        frontends to poppler core. Expose Page transitions on the glib
        frontend.
parent 877d6b20
2007-04-28 Carlos Garcia Campos <carlosgc@gnome.org>
reviewed and some code by: Albert Astals Cid <aacid@kde.org>
* glib/poppler-page.cc:
* glib/poppler-page.h:
* glib/poppler.h:
* glib/test-poppler-glib.c:
* poppler/Makefile.am:
* poppler/PageTransition.cc:
* poppler/PageTransition.h:
* qt/poppler-page-transition.cc:
* qt/poppler-page-transition.h: Move Page Transition parsing from qt
frontends to poppler core. Expose Page transitions on the glib
frontend.
2007-04-27 Albert Astals Cid <aacid@kde.org>
* glib/poppler-page.cc:
......
......@@ -27,6 +27,7 @@
#include <ErrorCodes.h>
#include <UnicodeMap.h>
#include <GfxState.h>
#include <PageTransition.h>
#include "poppler.h"
#include "poppler-private.h"
......@@ -141,6 +142,93 @@ poppler_page_get_duration (PopplerPage *page)
return page->page->getDuration ();
}
/**
* poppler_page_get_transition:
* @page: a #PopplerPage
*
* Returns the transition effect of @page
*
* Return value: a #PopplerPageTransition or NULL.
**/
PopplerPageTransition *
poppler_page_get_transition (PopplerPage *page)
{
PageTransition *trans;
PopplerPageTransition *transition;
Object obj;
g_return_val_if_fail (POPPLER_IS_PAGE (page), NULL);
trans = new PageTransition (page->page->getTrans (&obj));
obj.free ();
if (!trans->isOk ()) {
delete trans;
return NULL;
}
transition = poppler_page_transition_new ();
switch (trans->getType ())
{
case transitionReplace:
transition->type = POPPLER_PAGE_TRANSITION_REPLACE;
break;
case transitionSplit:
transition->type = POPPLER_PAGE_TRANSITION_SPLIT;
break;
case transitionBlinds:
transition->type = POPPLER_PAGE_TRANSITION_BLINDS;
break;
case transitionBox:
transition->type = POPPLER_PAGE_TRANSITION_BOX;
break;
case transitionWipe:
transition->type = POPPLER_PAGE_TRANSITION_WIPE;
break;
case transitionDissolve:
transition->type = POPPLER_PAGE_TRANSITION_DISSOLVE;
break;
case transitionGlitter:
transition->type = POPPLER_PAGE_TRANSITION_GLITTER;
break;
case transitionFly:
transition->type = POPPLER_PAGE_TRANSITION_FLY;
break;
case transitionPush:
transition->type = POPPLER_PAGE_TRANSITION_PUSH;
break;
case transitionCover:
transition->type = POPPLER_PAGE_TRANSITION_COVER;
break;
case transitionUncover:
transition->type = POPPLER_PAGE_TRANSITION_UNCOVER;
break;
case transitionFade:
transition->type = POPPLER_PAGE_TRANSITION_FADE;
break;
default:
g_assert_not_reached ();
}
transition->alignment = (trans->getAlignment() == transitionHorizontal) ?
POPPLER_PAGE_TRANSITION_HORIZONTAL :
POPPLER_PAGE_TRANSITION_VERTICAL;
transition->direction = (trans->getDirection() == transitionInward) ?
POPPLER_PAGE_TRANSITION_INWARD :
POPPLER_PAGE_TRANSITION_OUTWARD;
transition->duration = trans->getDuration();
transition->angle = trans->getAngle();
transition->scale = trans->getScale();
transition->rectangular = trans->isRectangular();
delete trans;
return transition;
}
#if defined (HAVE_CAIRO)
typedef struct {
......@@ -1040,6 +1128,40 @@ poppler_link_mapping_free (PopplerLinkMapping *mapping)
g_free (mapping);
}
/* Page Transition */
GType
poppler_page_transition (void)
{
static GType our_type = 0;
if (our_type == 0)
our_type = g_boxed_type_register_static("PopplerPageTransition",
(GBoxedCopyFunc) poppler_page_transition_copy,
(GBoxedFreeFunc) poppler_page_transition_free);
return our_type;
}
PopplerPageTransition *
poppler_page_transition_new (void)
{
return (PopplerPageTransition *) g_new0 (PopplerPageTransition, 1);
}
PopplerPageTransition *
poppler_page_transition_copy (PopplerPageTransition *transition)
{
PopplerPageTransition *new_transition;
new_transition = poppler_page_transition_new ();
*new_transition = *transition;
return new_transition;
}
void
poppler_page_transition_free (PopplerPageTransition *transition)
{
g_free (transition);
}
/* Form Type */
GType
......
......@@ -38,54 +38,55 @@ G_BEGIN_DECLS
#define POPPLER_IS_PAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), POPPLER_TYPE_PAGE))
GType poppler_page_get_type (void) G_GNUC_CONST;
void poppler_page_render_to_pixbuf (PopplerPage *page,
int src_x,
int src_y,
int src_width,
int src_height,
double scale,
int rotation,
GdkPixbuf *pixbuf);
GType poppler_page_get_type (void) G_GNUC_CONST;
void poppler_page_render_to_pixbuf (PopplerPage *page,
int src_x,
int src_y,
int src_width,
int src_height,
double scale,
int rotation,
GdkPixbuf *pixbuf);
#ifdef POPPLER_HAS_CAIRO
void poppler_page_render (PopplerPage *page,
cairo_t *cairo);
#endif
void poppler_page_get_size (PopplerPage *page,
double *width,
double *height);
int poppler_page_get_index (PopplerPage *page);
double poppler_page_get_duration (PopplerPage *page);
GdkPixbuf *poppler_page_get_thumbnail (PopplerPage *page);
gboolean poppler_page_get_thumbnail_size (PopplerPage *page,
int *width,
int *height);
GList *poppler_page_find_text (PopplerPage *page,
const char *text);
void poppler_page_render_to_ps (PopplerPage *page,
PopplerPSFile *ps_file);
char *poppler_page_get_text (PopplerPage *page,
PopplerRectangle *rect);
GList *poppler_page_get_link_mapping (PopplerPage *page);
void poppler_page_free_link_mapping (GList *list);
GdkRegion * poppler_page_get_selection_region (PopplerPage *page,
gdouble scale,
PopplerRectangle *selection);
void poppler_page_render_selection (PopplerPage *page,
gdouble scale,
int rotation,
GdkPixbuf *pixbuf,
PopplerRectangle *selection,
PopplerRectangle *old_selection,
GdkColor *glyph_color,
GdkColor *background_color);
GList *poppler_page_get_form_fields (PopplerPage *page);
void poppler_page_free_form_fields (GList *list);
void poppler_page_get_crop_box (PopplerPage *page,
PopplerRectangle *rect);
void poppler_page_render (PopplerPage *page,
cairo_t *cairo);
#endif
void poppler_page_get_size (PopplerPage *page,
double *width,
double *height);
int poppler_page_get_index (PopplerPage *page);
double poppler_page_get_duration (PopplerPage *page);
PopplerPageTransition *poppler_page_get_transition (PopplerPage *page);
GdkPixbuf *poppler_page_get_thumbnail (PopplerPage *page);
gboolean poppler_page_get_thumbnail_size (PopplerPage *page,
int *width,
int *height);
GList *poppler_page_find_text (PopplerPage *page,
const char *text);
void poppler_page_render_to_ps (PopplerPage *page,
PopplerPSFile *ps_file);
char *poppler_page_get_text (PopplerPage *page,
PopplerRectangle *rect);
GList *poppler_page_get_link_mapping (PopplerPage *page);
void poppler_page_free_link_mapping (GList *list);
GdkRegion *poppler_page_get_selection_region (PopplerPage *page,
gdouble scale,
PopplerRectangle *selection);
void poppler_page_render_selection (PopplerPage *page,
gdouble scale,
int rotation,
GdkPixbuf *pixbuf,
PopplerRectangle *selection,
PopplerRectangle *old_selection,
GdkColor *glyph_color,
GdkColor *background_color);
GList *poppler_page_get_form_fields (PopplerPage *page);
void poppler_page_free_form_fields (GList *list);
void poppler_page_get_crop_box (PopplerPage *page,
PopplerRectangle *rect);
/* A rectangle on a page, with coordinates in PDF points. */
......@@ -118,6 +119,24 @@ PopplerLinkMapping *poppler_link_mapping_new (void);
PopplerLinkMapping *poppler_link_mapping_copy (PopplerLinkMapping *mapping);
void poppler_link_mapping_free (PopplerLinkMapping *mapping);
/* Page Transition */
#define POPPLER_TYPE_PAGE_TRANSITION (poppler_page_transition_get_type ())
struct _PopplerPageTransition
{
PopplerPageTransitionType type;
PopplerPageTransitionAlignment alignment;
PopplerPageTransitionDirection direction;
gint duration;
gint angle;
gdouble scale;
gboolean rectangular;
};
GType poppler_page_transition_get_type (void) G_GNUC_CONST;
PopplerPageTransition *poppler_page_transition_new (void);
PopplerPageTransition *poppler_page_transition_copy (PopplerPageTransition *transition);
void poppler_page_transition_free (PopplerPageTransition *transition);
/* FormField */
#define POPPLER_TYPE_FORM_FIELD (poppler_form_field_get_type ())
struct _PopplerTextField
......
......@@ -42,6 +42,34 @@ typedef enum
POPPLER_ORIENTATION_SEASCAPE
} PopplerOrientation;
typedef enum
{
POPPLER_PAGE_TRANSITION_REPLACE,
POPPLER_PAGE_TRANSITION_SPLIT,
POPPLER_PAGE_TRANSITION_BLINDS,
POPPLER_PAGE_TRANSITION_BOX,
POPPLER_PAGE_TRANSITION_WIPE,
POPPLER_PAGE_TRANSITION_DISSOLVE,
POPPLER_PAGE_TRANSITION_GLITTER,
POPPLER_PAGE_TRANSITION_FLY,
POPPLER_PAGE_TRANSITION_PUSH,
POPPLER_PAGE_TRANSITION_COVER,
POPPLER_PAGE_TRANSITION_UNCOVER,
POPPLER_PAGE_TRANSITION_FADE
} PopplerPageTransitionType;
typedef enum
{
POPPLER_PAGE_TRANSITION_HORIZONTAL,
POPPLER_PAGE_TRANSITION_VERTICAL
} PopplerPageTransitionAlignment;
typedef enum
{
POPPLER_PAGE_TRANSITION_INWARD,
POPPLER_PAGE_TRANSITION_OUTWARD
} PopplerPageTransitionDirection;
/* MUST be the same than poppler/Form.h fieldType */
typedef enum
{
......@@ -51,21 +79,21 @@ typedef enum
POPPLER_FORM_FIELD_SIGNATURE,
} PopplerFormFieldType;
typedef struct _PopplerDocument PopplerDocument;
typedef struct _PopplerIndexIter PopplerIndexIter;
typedef struct _PopplerFontsIter PopplerFontsIter;
typedef struct _PopplerRectangle PopplerRectangle;
typedef struct _PopplerLinkMapping PopplerLinkMapping;
typedef struct _PopplerFormField PopplerFormField;
typedef struct _PopplerPage PopplerPage;
typedef struct _PopplerFontInfo PopplerFontInfo;
typedef struct _PopplerPSFile PopplerPSFile;
typedef union _PopplerAction PopplerAction;
typedef struct _PopplerDest PopplerDest;
typedef struct _PopplerTextField PopplerTextField;
typedef struct _PopplerButtonField PopplerButtonField;
typedef struct _PopplerChoiceField PopplerChoiceField;
typedef struct _PopplerDocument PopplerDocument;
typedef struct _PopplerIndexIter PopplerIndexIter;
typedef struct _PopplerFontsIter PopplerFontsIter;
typedef struct _PopplerRectangle PopplerRectangle;
typedef struct _PopplerLinkMapping PopplerLinkMapping;
typedef struct _PopplerPageTransition PopplerPageTransition;
typedef struct _PopplerFormField PopplerFormField;
typedef struct _PopplerPage PopplerPage;
typedef struct _PopplerFontInfo PopplerFontInfo;
typedef struct _PopplerPSFile PopplerPSFile;
typedef union _PopplerAction PopplerAction;
typedef struct _PopplerDest PopplerDest;
typedef struct _PopplerTextField PopplerTextField;
typedef struct _PopplerButtonField PopplerButtonField;
typedef struct _PopplerChoiceField PopplerChoiceField;
typedef enum
{
......
......@@ -109,11 +109,62 @@ print_document_info (PopplerDocument *document)
g_free (linearized);
}
static const gchar *
transition_effect_name (PopplerPageTransitionType type)
{
switch (type)
{
case POPPLER_PAGE_TRANSITION_REPLACE:
return "Replace";
case POPPLER_PAGE_TRANSITION_SPLIT:
return "Split";
case POPPLER_PAGE_TRANSITION_BLINDS:
return "Blinds";
case POPPLER_PAGE_TRANSITION_BOX:
return "Box";
case POPPLER_PAGE_TRANSITION_WIPE:
return "Wipe";
case POPPLER_PAGE_TRANSITION_DISSOLVE:
return "Dissolve";
case POPPLER_PAGE_TRANSITION_GLITTER:
return "Glitter";
case POPPLER_PAGE_TRANSITION_FLY:
return "Fly";
case POPPLER_PAGE_TRANSITION_PUSH:
return "Push";
case POPPLER_PAGE_TRANSITION_COVER:
return "Cover";
case POPPLER_PAGE_TRANSITION_UNCOVER:
return "Uncover";
case POPPLER_PAGE_TRANSITION_FADE:
return "Fade";
}
return "Unknown";
}
static void
print_page_transition (PopplerPageTransition *transition)
{
printf ("\t\tEffect: %s\n", transition_effect_name (transition->type));
printf ("\t\tAlignment: %s\n",
transition->alignment == POPPLER_PAGE_TRANSITION_HORIZONTAL ?
"Horizontal" : "Vertical");
printf ("\t\tDirection: %s\n",
transition->direction == POPPLER_PAGE_TRANSITION_INWARD ?
"Inward" : "Outward");
printf ("\t\tDuration: %d\n", transition->duration);
printf ("\t\tAngle: %d\n", transition->angle);
printf ("\t\tScale: %.2f\n", transition->scale);
printf ("\t\tRectangular: %s\n", transition->rectangular ? "Yes" : "No");
}
int main (int argc, char *argv[])
{
PopplerDocument *document;
PopplerBackend backend;
PopplerPage *page;
PopplerPageTransition *transition;
GEnumValue *enum_value;
char *label;
GError *error;
......@@ -154,6 +205,15 @@ int main (int argc, char *argv[])
else
printf ("\tpage duration:\tno duration for page\n");
transition = poppler_page_get_transition (page);
if (transition) {
printf ("\tpage transition:\n");
print_page_transition (transition);
poppler_page_transition_free (transition);
} else {
printf ("\tpage transition:no transition effect for page\n");
}
thumb = poppler_page_get_thumbnail (page);
if (thumb != NULL) {
gdk_pixbuf_save (thumb, "thumb.png", "png", &error, NULL);
......
......@@ -150,6 +150,7 @@ poppler_include_HEADERS = \
Outline.h \
OutputDev.h \
Page.h \
PageTransition.h \
Parser.h \
PDFDoc.h \
PDFDocEncoding.h \
......@@ -214,6 +215,7 @@ libpoppler_la_SOURCES = \
Outline.cc \
OutputDev.cc \
Page.cc \
PageTransition.cc \
Parser.cc \
PDFDoc.cc \
PDFDocEncoding.cc \
......
......@@ -16,174 +16,121 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <iostream>
#ifdef USE_GCC_PRAGMAS
#pragma implementation
#endif
#include "Error.h"
#include "Object.h"
#include "PageTransition.h"
#include "Private.h"
namespace Poppler {
//------------------------------------------------------------------------
// PageTransition
//------------------------------------------------------------------------
class PageTransitionData
{
public:
PageTransition::Type type;
int duration;
PageTransition::Alignment alignment;
PageTransition::Direction direction;
int angle;
double scale;
bool rectangular;
};
PageTransition::PageTransition(const PageTransitionParams &params)
{
data = new PageTransitionData();
data->type = Replace;
data->duration = 1;
data->alignment = Horizontal;
data->direction = Inward;
data->angle = 0;
data->scale = 1.0;
data->rectangular = false;
// Paranoid safety checks
if (params.dictObj == 0) {
error(-1, "PageTransition::PageTransition() called with params.dictObj==0");
return;
}
if (params.dictObj->isDict() == false) {
error(-1, "PageTransition::PageTransition() called with params.dictObj->isDict()==false");
PageTransition::PageTransition (Object *trans) {
Object obj;
Dict *dict;
type = transitionReplace;
duration = 1;
alignment = transitionHorizontal;
direction = transitionInward;
angle = 0;
scale = 1.0;
rectangular = gFalse;
ok = gTrue;
if (!trans || !trans->isDict ()) {
ok = gFalse;
return;
}
// Obtain a pointer to the dictionary and start parsing.
Dict *transDict = params.dictObj->getDict();
Object obj;
dict = trans->getDict();
if (transDict->lookup("S", &obj)->isName()) {
// get type
if (dict->lookup("S", &obj)->isName()) {
const char *s = obj.getName();
if (strcmp("R", s) == 0)
data->type = Replace;
type = transitionReplace;
else if (strcmp("Split", s) == 0)
data->type = Split;
type = transitionSplit;
else if (strcmp("Blinds", s) == 0)
data->type = Blinds;
type = transitionBlinds;
else if (strcmp("Box", s) == 0)
data->type = Box;
type = transitionBox;
else if (strcmp("Wipe", s) == 0)
data->type = Wipe;
type = transitionWipe;
else if (strcmp("Dissolve", s) == 0)
data->type = Dissolve;
type = transitionDissolve;
else if (strcmp("Glitter", s) == 0)
data->type = Glitter;
type = transitionGlitter;
else if (strcmp("Fly", s) == 0)
data->type = Fly;
type = transitionFly;
else if (strcmp("Push", s) == 0)
data->type = Push;
type = transitionPush;
else if (strcmp("Cover", s) == 0)
data->type = Cover;
type = transitionCover;
else if (strcmp("Uncover", s) == 0)
data->type = Push;
type = transitionPush;
else if (strcmp("Fade", s) == 0)
data->type = Cover;
type = transitionCover;
}
obj.free();
if (transDict->lookup("D", &obj)->isInt()) {
data->duration = obj.getInt();
// get duration
if (dict->lookup("D", &obj)->isInt()) {
duration = obj.getInt();
}
obj.free();
if (transDict->lookup("Dm", &obj)->isName()) {
// get alignment
if (dict->lookup("Dm", &obj)->isName()) {
const char *dm = obj.getName();
if ( strcmp( "H", dm ) == 0 )
data->alignment = Horizontal;
else if ( strcmp( "V", dm ) == 0 )
data->alignment = Vertical;
if (strcmp("H", dm) == 0)
alignment = transitionHorizontal;
else if (strcmp("V", dm) == 0)
alignment = transitionVertical;
}
obj.free();
if (transDict->lookup("M", &obj)->isName()) {
// get direction
if (dict->lookup("M", &obj)->isName()) {
const char *m = obj.getName();
if ( strcmp( "I", m ) == 0 )
data->direction = Inward;
else if ( strcmp( "O", m ) == 0 )
data->direction = Outward;
if (strcmp("I", m) == 0)
direction = transitionInward;
else if (strcmp("O", m) == 0)
direction = transitionOutward;
}
obj.free();
if (transDict->lookup("Di", &obj)->isInt()) {
data->angle = obj.getInt();
// get angle
if (dict->lookup("Di", &obj)->isInt()) {
angle = obj.getInt();
}
obj.free();
if (transDict->lookup("Di", &obj)->isName()) {
if ( strcmp( "None", obj.getName() ) == 0 )
data->angle = 0;
if (dict->lookup("Di", &obj)->isName()) {
if (strcmp("None", obj.getName()) == 0)
angle = 0;
}
obj.free();
if (transDict->lookup("SS", &obj)->isReal()) {
data->scale = obj.getReal();
// get sacle
if (dict->lookup("SS", &obj)->isReal()) {
scale = obj.getReal();
}
obj.free();
if (transDict->lookup("B", &obj)->isBool()) {
data->rectangular = obj.getBool();
// get rectangular
if (dict->lookup("B", &obj)->isBool()) {
rectangular = obj.getBool();
}
obj.free();
}
PageTransition::PageTransition(const PageTransition &pt)
{
data = new PageTransitionData();
data->type = pt.data->type;
data->duration = pt.data->duration;
data->alignment = pt.data->alignment;
data->direction = pt.data->direction;
data->angle = pt.data->angle;
data->scale = pt.data->scale;
data->rectangular = pt.data->rectangular;
}
PageTransition::~PageTransition()
{
}
PageTransition::Type PageTransition::type() const
{
return data->type;
}
int PageTransition::duration() const
{
return data->duration;
}
PageTransition::Alignment PageTransition::alignment() const
{
return data->alignment;
}
PageTransition::Direction PageTransition::direction() const
{
return data->direction;
}
int PageTransition::angle() const
{
return data->angle;
}
double PageTransition::scale() const
{
return data->scale;
}
bool PageTransition::isRectangular() const
{
return data->rectangular;
}
}
#ifndef PAGE_TRANSITION_H
#define PAGE_TRANSITION_H
#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif
#include "Object.h"
//------------------------------------------------------------------------
// PageTransition
//------------------------------------------------------------------------
// if changed remember to keep in sync with frontend enums
enum PageTransitionType {
transitionReplace = 0,
transitionSplit,
transitionBlinds,
transitionBox,
transitionWipe,
transitionDissolve,
transitionGlitter,
transitionFly,
transitionPush,
transitionCover,
transitionUncover,
transitionFade
};
// if changed remember to keep in sync with frontend enums
enum PageTransitionAlignment {
transitionHorizontal = 0,
transitionVertical