Index: glib/poppler-page.cc =================================================================== RCS file: /cvs/poppler/poppler/glib/poppler-page.cc,v retrieving revision 1.54 diff -u -u -r1.54 poppler-page.cc --- glib/poppler-page.cc 24 Feb 2007 23:32:22 -0000 1.54 +++ glib/poppler-page.cc 22 Apr 2007 09:26:31 -0000 @@ -27,6 +27,7 @@ #include #include #include +#include #include "poppler.h" #include "poppler-private.h" @@ -141,6 +142,93 @@ 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 { @@ -1039,6 +1127,40 @@ 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 Index: glib/poppler-page.h =================================================================== RCS file: /cvs/poppler/poppler/glib/poppler-page.h,v retrieving revision 1.23 diff -u -u -r1.23 poppler-page.h --- glib/poppler-page.h 24 Feb 2007 23:32:22 -0000 1.23 +++ glib/poppler-page.h 22 Apr 2007 09:26:31 -0000 @@ -38,54 +38,55 @@ #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_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); +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_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 Index: glib/poppler.h =================================================================== RCS file: /cvs/poppler/poppler/glib/poppler.h,v retrieving revision 1.13 diff -u -u -r1.13 poppler.h --- glib/poppler.h 24 Feb 2007 23:32:22 -0000 1.13 +++ glib/poppler.h 22 Apr 2007 09:26:31 -0000 @@ -42,6 +42,34 @@ 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 @@ 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 { Index: glib/test-poppler-glib.c =================================================================== RCS file: /cvs/poppler/poppler/glib/test-poppler-glib.c,v retrieving revision 1.19 diff -u -u -r1.19 test-poppler-glib.c --- glib/test-poppler-glib.c 26 Dec 2006 19:56:29 -0000 1.19 +++ glib/test-poppler-glib.c 22 Apr 2007 09:26:32 -0000 @@ -109,11 +109,62 @@ 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 @@ 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); Index: poppler/Makefile.am =================================================================== RCS file: /cvs/poppler/poppler/poppler/Makefile.am,v retrieving revision 1.30 diff -u -u -r1.30 Makefile.am --- poppler/Makefile.am 4 Apr 2007 02:42:29 -0000 1.30 +++ poppler/Makefile.am 22 Apr 2007 09:26:32 -0000 @@ -150,6 +150,7 @@ Outline.h \ OutputDev.h \ Page.h \ + PageTransition.h \ Parser.h \ PDFDoc.h \ PDFDocEncoding.h \ @@ -214,6 +215,7 @@ Outline.cc \ OutputDev.cc \ Page.cc \ + PageTransition.cc \ Parser.cc \ PDFDoc.cc \ PDFDocEncoding.cc \ Index: poppler/PageTransition.cc =================================================================== RCS file: /cvs/poppler/poppler/poppler/PageTransition.cc,v retrieving revision 1.2 diff -u -u -r1.2 PageTransition.cc --- poppler/PageTransition.cc 2 Jan 2006 14:24:31 -0000 1.2 +++ poppler/PageTransition.cc 22 Apr 2007 09:26:32 -0000 @@ -16,174 +16,121 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include +#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 (Object *trans) { + Object obj; + Dict *dict; -PageTransition::PageTransition(const PageTransitionParams ¶ms) -{ - 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"); + type = transitionReplace; + duration = 1; + alignment = transitionHorizontal; + direction = transitionInward; + angle = 0; + scale = 1.0; + rectangular = gFalse; + ok = gTrue; + + if (!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; -} - -} Index: poppler/PageTransition.h =================================================================== RCS file: poppler/PageTransition.h diff -N poppler/PageTransition.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ poppler/PageTransition.h 22 Apr 2007 09:26:32 -0000 @@ -0,0 +1,83 @@ +#ifndef PAGE_TRANSITION_H +#define PAGE_TRANSITION_H + +#ifdef USE_GCC_PRAGMAS +#pragma interface +#endif + +#include "Object.h" + +//------------------------------------------------------------------------ +// PageTransition +//------------------------------------------------------------------------ + +enum PageTransitionType { + transitionReplace, + transitionSplit, + transitionBlinds, + transitionBox, + transitionWipe, + transitionDissolve, + transitionGlitter, + transitionFly, + transitionPush, + transitionCover, + transitionUncover, + transitionFade +}; + +enum PageTransitionAlignment { + transitionHorizontal, + transitionVertical +}; + +enum PageTransitionDirection { + transitionInward, + transitionOutward +}; + +class PageTransition { +public: + // Construct a Page Transition. + PageTransition (Object *trans); + + // Destructor. + ~PageTransition (); + + // Was the Page Transition created successfully? + GBool isOk() { return ok; } + + // Get type + PageTransitionType getType() { return type; } + + // Get duration + int getDuration() { return duration;} + + // Get alignment + PageTransitionAlignment getAlignment() { return alignment; } + + // Get direction + PageTransitionDirection getDirection() { return direction; } + + // Get angle + int getAngle() { return angle; } + + // Get scale + double getScale() { return scale; } + + // Is rectangular? + GBool isRectangular() { return rectangular; } + +private: + + PageTransitionType type; // transition style + int duration; // duration of the effect in seconds + PageTransitionAlignment alignment; // dimension of the effect + PageTransitionDirection direction; // direction of motion + int angle; // direction in degrees + double scale; // scale + GBool rectangular; // is the area to be flown in rectangular? + GBool ok; // set if created successfully +}; + +#endif /* PAGE_TRANSITION_H */