Commit 94e6feaf authored by Benoît Minisini's avatar Benoît Minisini
Browse files

New 'gb.poppler' component that will replace 'gb.pdf'.

[CONFIGURATION]
* NEW: Fix component template generator.

[GB.POPPLER]
* NEW: New 'gb.poppler' component that will replace 'gb.pdf'.
parent 57777996
......@@ -26,6 +26,7 @@ SUBDIRS = \
@x11_dir@ \
@keyring_dir@ \
@pdf_dir@ \
@poppler_dir@ \
@cairo_dir@ \
@imageio_dir@ \
@imageimlib_dir@ \
......
......@@ -27,7 +27,7 @@ based on the well known 'test' library:
parent directory named gb.test, with all needed files and symbolic
links ready to be build: configure.ac, Makefile.am, ...
If something is weird, tell me on the gambas developer mailing-list!
If something is weird, tell me on the gambas mailing-list!
Benoît.
......
/* Copyrights */
#define __COPYRIGHT (c)
#define __AUTHOR Benoît Minisini
#define __EMAIL <g4mba5@gmail.com>
/* Name of the component */
#define __COMPONENT gb.poppler
/* Name of the component with points replaced by dashes */
#define __COMPONENT_DASH gb-poppler
/* Name of the component with points replaced by underscore */
#define __COMPONENT_UNDERSCORE gb_poppler
/* Short name of the component */
#define __NAME poppler
/* Short name of the component in uppercase */
#define __UNAME POPPLER
/* Description of the component */
#define __DESCRIPTION Pdf reader based on poppler library
/* If the component detection uses pkg-config */
#define __USE_PKGCONFIG 1
#if __USE_PKGCONFIG
/* Name of the package for pkg-config */
#define __PKGCONFIG_NAME poppler-cpp
/* Minimum version needed */
//#define __PKGCONFIG_VERSION 1.2.8
#else /* __USE_PKGCONFIG */
/* If your component uses C */
#define __USE_C 1
/* If your component uses C++ */
#define __USE_CPLUSPLUS 1
/* If your component uses multi-threading */
#define __USE_THREAD 1
/* If your component uses X-Window */
#define __USE_XWINDOW 1
/* Includes to search for */
#define __SEARCH_INCLUDE poppler.h test2.h
/* Includes directories search path */
#define __SEARCH_INCLUDE_PATH /usr/local/lib /usr/local /usr/lib /usr
/* Includes sub-directories search */
#define __SEARCH_INCLUDE_DIR poppler/include include poppler*/include poppler/*/include
/* Libraries to search for */
#define __SEARCH_LIBRARY libtest.$SHLIBEXT libjpeg.$SHLIBEXT libpng.$SHLIBEXT
/* Libraries directories search path */
#define __SEARCH_LIBRARY_PATH /usr/local /usr
/* Libraries sub-directories search path */
#define __SEARCH_LIBRARY_DIR lib
/* Libraries to link with */
#define __LIBRARY -ljpeg -lpng -ltest
/* Includes to link with */
#define __INCLUDE -ljpeg -lpng -ltest
#endif /* __USE_PKGCONFIG */
/* Source file list */
#define __SOURCES main.c main.h
/* Main C/C++ source basename in uppercase */
#define __MAIN_UNAME MAIN
$#$!/bin/sh
cd src
mv gb.xxx.component __COMPONENT.component
mv .component __COMPONENT.component
......@@ -38,6 +38,7 @@ GB_CONFIG_SUBDIRS(opengl, gb.opengl)
GB_CONFIG_SUBDIRS(x11, gb.desktop.x11)
GB_CONFIG_SUBDIRS(keyring, gb.desktop.gnome.keyring)
GB_CONFIG_SUBDIRS(pdf, gb.pdf)
GB_CONFIG_SUBDIRS(poppler, gb.poppler)
GB_CONFIG_SUBDIRS(cairo, gb.cairo)
GB_CONFIG_SUBDIRS(imageio, gb.image.io)
GB_CONFIG_SUBDIRS(imageimlib, gb.image.imlib)
......
../COPYING
\ No newline at end of file
../INSTALL
\ No newline at end of file
ACLOCAL_AMFLAGS = -I m4 --install
SUBDIRS = @POPPLER_DIR@
EXTRA_DIST = reconf gambas.h gb*.h
../acinclude.m4
\ No newline at end of file
../component.am
\ No newline at end of file
dnl ---- configure.ac for gb.poppler
m4_include([../version.m4])
AC_INIT(gambas3-gb-poppler, GB_VERSION, GB_MAIL, [], GB_URL)
AC_CONFIG_MACRO_DIR([m4])
GB_INIT(gb.poppler)
AC_PROG_LIBTOOL
GB_COMPONENT_PKG_CONFIG(
poppler,
POPPLER,
gb.poppler,
[src],
poppler-cpp poppler-splash)
AC_OUTPUT( Makefile src/Makefile )
GB_PRINT_MESSAGES
../main/share/gambas.h
\ No newline at end of file
../main/lib/image/gb.image.h
\ No newline at end of file
../main/share/gb_common.h
\ No newline at end of file
../m4
\ No newline at end of file
../reconf
\ No newline at end of file
COMPONENT = gb.poppler
include $(top_srcdir)/component.am
gblib_LTLIBRARIES = gb.poppler.la
gb_poppler_la_LIBADD = @POPPLER_LIB@
gb_poppler_la_LDFLAGS = -module @LD_FLAGS@ @POPPLER_LDFLAGS@
gb_poppler_la_CPPFLAGS = @POPPLER_INC@
gb_poppler_la_SOURCES = main.h main.cpp \
c_pdf_document.h c_pdf_document.cpp
/***************************************************************************
c_pdf_document.cpp
gb.poppler component
(c) Benoît Minisini <g4mba5@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 1, 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.
***************************************************************************/
#define __C_PDF_DOCUMENT_CPP
#include "poppler/cpp/poppler-global.h"
#include "c_pdf_document.h"
static void return_ustring(poppler::ustring str)
{
poppler::byte_array utf8 = str.to_utf8();
int len = utf8.size();
if (len >= 1)
GB.ReturnNewString(utf8.data(), len);
else
GB.ReturnVoidString();
}
static poppler::rotation_enum conv_rotation(int angle)
{
if (angle < 0)
angle = 360 - (-angle) % 360;
else
angle = angle % 360;
switch (angle)
{
case 0: return poppler::rotate_0;
case 90: return poppler::rotate_90;
case 180: return poppler::rotate_180;
case 270: return poppler::rotate_270;
default: return poppler::rotate_0;
}
}
//--------------------------------------------------------------------------
static void free_image(GB_IMG *img, void *image)
{
delete (poppler::image *)image;
}
static void *temp_image(GB_IMG *img)
{
poppler::image *image;
if (!img->data)
image = new poppler::image(0, 0, poppler::image::format_argb32);
else
image = new poppler::image((char *)img->data, img->width, img->height, poppler::image::format_argb32);
return image;
}
static GB_IMG_OWNER _image_owner = {
"gb.poppler",
GB_IMAGE_BGRA,
free_image,
free_image,
temp_image,
NULL,
};
static void return_image(poppler::image *image)
{
GB_IMG *img;
static GB_CLASS class_id = 0;
if (!class_id)
class_id = GB.FindClass("Image");
img = (GB_IMG *)GB.New(class_id, NULL, NULL);
IMAGE.Take(img, &_image_owner, image, image->width(), image->height(), (uchar *)image->const_data());
GB.ReturnObject(img);
}
//--------------------------------------------------------------------------
BEGIN_METHOD(PdfDocument_new, GB_STRING path; GB_STRING owner; GB_STRING password)
char *buf;
int len;
std::string owner;
std::string password;
if (GB.LoadFile(STRING(path), LENGTH(path), &buf, &len))
return;
if (!MISSING(owner))
owner = std::string(STRING(owner), LENGTH(owner));
if (!MISSING(password))
password = std::string(STRING(password), LENGTH(password));
THIS->doc = poppler::document::load_from_raw_data(buf, len, owner, password);
THIS->renderer = new poppler::page_renderer;
THIS->resolution = 300.0;
END_METHOD
BEGIN_METHOD_VOID(PdfDocument_free)
int i;
if (THIS->pages)
{
for (i = 0; i < THIS->doc->pages(); i++)
delete THIS->pages[i];
GB.Free(POINTER(&THIS->pages));
}
delete THIS->renderer;
delete THIS->doc;
END_METHOD
BEGIN_PROPERTY(PdfDocument_Count)
GB.ReturnInteger(THIS->doc->pages());
END_PROPERTY
#define IMPLEMENT_DOC_PROP(_name, _func) \
BEGIN_PROPERTY(PdfDocument_##_name) \
return_ustring(THIS->doc->_func()); \
END_PROPERTY
IMPLEMENT_DOC_PROP(Author, get_author)
IMPLEMENT_DOC_PROP(Creator, get_creator)
IMPLEMENT_DOC_PROP(Producer, get_producer)
IMPLEMENT_DOC_PROP(Subject, get_subject)
IMPLEMENT_DOC_PROP(Title, get_title)
BEGIN_METHOD(PdfDocument_get, GB_INTEGER index)
int index = VARG(index);
if (index < 0 || index >= THIS->doc->pages())
{
GB.Error(GB_ERR_BOUND);
return;
}
if (!THIS->pages)
GB.AllocZero(POINTER(&THIS->pages), sizeof(void *) * THIS->doc->pages());
if (!THIS->pages[index])
THIS->pages[index] = THIS->doc->create_page(index);
THIS->current = THIS->pages[index];
RETURN_SELF();
END_METHOD
BEGIN_PROPERTY(PdfDocument_Resolution)
if (READ_PROPERTY)
GB.ReturnFloat(THIS->resolution);
else
{
double res = VPROP(GB_FLOAT);
if (res <= 0)
{
GB.Error(GB_ERR_ARG);
return;
}
THIS->resolution = res;
}
END_PROPERTY
BEGIN_PROPERTY(PdfDocument_Rotation)
if (READ_PROPERTY)
GB.ReturnInteger(THIS->rotation);
else
THIS->rotation = VPROP(GB_INTEGER);
END_PROPERTY
#define IMPLEMENT_HINT_PROP(_name, _const) \
BEGIN_PROPERTY(PdfDocument_##_name) \
if (READ_PROPERTY) \
GB.ReturnBoolean(THIS->renderer->render_hints() & poppler::page_renderer::_const); \
else \
THIS->renderer->set_render_hint(poppler::page_renderer::_const, VPROP(GB_BOOLEAN)); \
END_PROPERTY
IMPLEMENT_HINT_PROP(Antialiasing, antialiasing)
IMPLEMENT_HINT_PROP(TextAntialiasing, text_antialiasing)
IMPLEMENT_HINT_PROP(TextHinting, text_hinting)
//--------------------------------------------------------------------------
BEGIN_PROPERTY(PdfPage_Orientation)
GB.ReturnInteger(THIS->current->orientation());
END_PROPERTY
BEGIN_METHOD(PdfPage_Render, GB_INTEGER x; GB_INTEGER y; GB_INTEGER width; GB_INTEGER height; GB_INTEGER rotation; GB_FLOAT res)
int rotation = VARGOPT(rotation, THIS->rotation);
double res = VARGOPT(res, THIS->resolution);
int x = VARGOPT(x, -1);
int y = VARGOPT(y, -1);
int w = VARGOPT(width, -1);
int h = VARGOPT(height, -1);
poppler::image *image = new poppler::image;
*image = THIS->renderer->render_page(THIS->current, res, res, x, y, w, h, conv_rotation(rotation));
return_image(image);
END_METHOD
//--------------------------------------------------------------------------
GB_DESC PdfPageDesc[] =
{
GB_DECLARE_VIRTUAL(".PdfPage"),
GB_PROPERTY_READ("Orientation", "i", PdfPage_Orientation),
GB_METHOD("Render", "Image", PdfPage_Render, "[(X)i(Y)i(Width)i(Height)i(Rotation)i(Resolution)f]"),
GB_END_DECLARE
};
GB_DESC PdfDocumentDesc[] =
{
GB_DECLARE("PdfDocument", sizeof(CPDFDOCUMENT)),
/*GB_CONSTANT("Unknown","i",actionUnknown),
GB_CONSTANT("Goto","i",actionGoTo),
GB_CONSTANT("GotoRemote","i",actionGoToR),
GB_CONSTANT("Launch","i",actionLaunch),
GB_CONSTANT("Uri","i",actionURI),
GB_CONSTANT("Named","i",actionNamed),
GB_CONSTANT("Movie","i",actionMovie),
GB_CONSTANT("Normal","i",0),
GB_CONSTANT("Sideways","i",90),
GB_CONSTANT("Inverted","i",180),
GB_CONSTANT("SidewaysInverted","i",270),*/
GB_METHOD("_new", 0, PdfDocument_new, "(Path)s[(Owner)s(Password)s]"),
GB_METHOD("_free", 0, PdfDocument_free, 0),
GB_METHOD("_get", ".PdfPage", PdfDocument_get, "(Index)i"),
//GB_PROPERTY("Zoom", "f", PDFDOCUMENT_scale),
//GB_PROPERTY("Orientation", "i", PDFDOCUMENT_rotation),
//GB_PROPERTY_READ("Ready","b",PDFDOCUMENT_ready),
GB_PROPERTY_READ("Count","i",PdfDocument_Count),
//GB_PROPERTY_READ("HasIndex","b",PDFDOCUMENT_has_index),
//GB_PROPERTY_READ("Index",".PdfDocument.Index",PDFDOCUMENT_index),
//GB_PROPERTY_READ("Info",".PdfDocument.Info",PDFDOCUMENT_info),
GB_PROPERTY_READ("Author", "s", PdfDocument_Author),
GB_PROPERTY_READ("Creator", "s", PdfDocument_Creator),
GB_PROPERTY_READ("Producer", "s", PdfDocument_Producer),
GB_PROPERTY_READ("Subject", "s", PdfDocument_Subject),
GB_PROPERTY_READ("Title", "s", PdfDocument_Title),
GB_PROPERTY("Resolution", "f", PdfDocument_Resolution),
GB_PROPERTY("Rotation", "i", PdfDocument_Rotation),
GB_PROPERTY("Antialiasing", "b", PdfDocument_Antialiasing),
GB_PROPERTY("TextAntialiasing", "b", PdfDocument_TextAntialiasing),
GB_PROPERTY("TextHinting", "b", PdfDocument_TextHinting),
GB_END_DECLARE
};
GB_DESC PdfDesc[] =
{
GB_DECLARE_STATIC("Pdf"),
GB_CONSTANT("Landscape", "i", poppler::page::landscape),
GB_CONSTANT("Portrait", "i", poppler::page::portrait),
GB_CONSTANT("Seascape", "i", poppler::page::seascape),
GB_CONSTANT("UpsideDown", "i", poppler::page::upside_down),
GB_END_DECLARE
};
/***************************************************************************
c_pdf_document.h
gb.poppler component
(c) Benoît Minisini <g4mba5@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 1, 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.
***************************************************************************/
#ifndef __C_PDF_DOCUMENT_H
#define __C_PDF_DOCUMENT_H
#include "poppler/cpp/poppler-document.h"
#include "poppler/cpp/poppler-page.h"
#include "poppler/cpp/poppler-page-renderer.h"
#include "poppler/cpp/poppler-image.h"
#include "main.h"
#ifndef __C_PDF_DOCUMENT_CPP
extern GB_DESC PdfDocumentDesc[];
extern GB_DESC PdfPageDesc[];
#endif
typedef
struct {
GB_BASE ob;
poppler::document *doc;
poppler::page **pages;
poppler::page *current;
poppler::page_renderer *renderer;
double resolution;
int rotation;
}
CPDFDOCUMENT;
#define THIS ((CPDFDOCUMENT *)_object)
#endif /* __C_PDF_DOCUMENT_H */
[Component]
Author=Benoît Minisini
Requires=gb.image
State=Unstable
/***************************************************************************
main.cpp
gb.poppler component
(c) Benoît Minisini <g4mba5@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 1, 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.
***************************************************************************/
#define __MAIN_CPP
#include "c_pdf_document.h"
#include "main.h"
extern "C"
{
GB_INTERFACE GB EXPORT;
IMAGE_INTERFACE IMAGE EXPORT;
GB_DESC *GB_CLASSES[] EXPORT =
{
PdfPageDesc,
PdfDocumentDesc,
NULL
};
int EXPORT GB_INIT(void)
{
GB.GetInterface("gb.image", IMAGE_INTERFACE_VERSION, &IMAGE);
return 0;
}
void EXPORT GB_EXIT()
{