← Back to team overview

qpdfview team mailing list archive

Re: Support other file formats

 

Actually, I think we could make it (almost) as easy as the attached
model interface...

Am 08.01.2013 15:35, schrieb Adam Reichold:
> Hello Alexander,
> 
> After thinking about it for some time, I'd say that I would be
> interested in supporting multiple formats in qpdfview if:
> * We agree to use an abstract document model separating data and
> presentation completely.
> * We agree that the interfaces are modelled on Poppler's interfaces in
> the beginning, generalizing them later on.
> * We support at least PDF, PS, and DjVu.
> * We take our time for the next version which will be 0.4 and no rush
> w.r.t. a new name... :-)
> 
> Modelling Poppler's interfaces will make it possible to keep the
> settings as they are even though some might not make sense for other
> backends. I attach some sample code on how I would like to proceed with
> the abstract model. Your thoughts?
> 
> Of course, the "fun" part will be adding (probably polymorphic)
> interfaces for annotations and form fields which is current missing. But
> maybe we just make them struct's containing their boundary on the page
> and a "handler object" derived from QDialog which should make it
> possible to use the current implementation with minimal changes.
> 
> Best regards, Adam.
> 
> Am 21.12.2012 12:50, schrieb Александр Волков:
>> Hello Adam,
>>
>>>> Ok, it makes sense to create intermediate intefaces for links and
>>>> maybe annotations, but there is no reason to do it for form
>>>> fields, as no other format supports them.
>>> While this is currently so, maybe we want to use a different
>>> PDF-backend in the future or there is a new format that does this. As
>>> I said, we have all the time in the world to do this right. If we
>>> decide to do it, that is.
>>
>> I don't think that it's right to put all format specific features to
>> core library. It looks like "early optimization" in code design.
>> You can spend a lot of time on the things that actually will never
>> be needed in the future.
>> I'd prefer to do first so that it just worked. And create common
>> interfaces only as you need them.
>> On the other hand it may be possible to create common ancestor
>> class for links, annotations and everything else and use it everywhere
>> instead of specific classes.
>>
>>> With "presentation-specific" code, I meant everything related to
>>> handling displaying content and interacting with it, i.e. most of
>>> DocumentView, PageItem and PresentationView.
>>
>> Sorry for the misunderstanding.
>>
>> Best regards, Alexander.
>>
>>
>>
>>
#ifndef DOCUMENTMODEL_H
#define DOCUMENTMODEL_H

#include <QtGlobal>
#include <QList>
#include <QRect>
#include <QRectF>
#include <QString>

class QImage;
class QSizeF;
class QStandardItemModel;

struct Link
{
    QRectF boundary;

    int page;
    qreal left;
    qreal top;

    QString url;

    Link() : boundary(), page(-1), left(0.0), top(0.0), url() {}
    Link(const QRectF& boundary, int page, qreal left, qreal top) : boundary(boundary), page(page), left(left), top(top), url() {}
    Link(const QRectF& boundary, const QString& url) : boundary(boundary), page(-1), left(0.0), top(0.0), url(url) {}

};

class Annotation
{
public:
    virtual ~Annotation() {}

    virtual QRectF boundary() const = 0;

    virtual void exec(const QPoint& screenPos) = 0;
};

class FormField
{
public:
    virtual ~FormField() {}

    virtual QRectF boundary() const = 0;

    virtual void exec(const QPoint& screenPos) = 0;
};

class Page
{
public:
    virtual ~Page() {}

    virtual QSizeF size() const = 0;

    enum Rotation
    {
        DoNotRotate = 0,
        RotateBy90 = 1,
        RotateBy180 = 2,
        RotateBy270 = 3
    };

    virtual QImage render(qreal horizontalResolution = 72.0, qreal verticalResolution = 72.0, Rotation rotation = DoNotRotate, const QRect& boundingRect = QRect()) const = 0;

    virtual QList< Link > links() const { return QList< Link >(); }

    virtual QList< Annotation* > annotations() const { return QList< Annotations* >(); }

    virtual Annotation* addTextAnnotation(const QRectF& boundary) { Q_UNUSED(boundary); return 0; }
    virtual Annotation* addHighlightAnnotation(const QRectF& boundary) { Q_UNUSED(boundary); return 0; }
    virtual void removeAnnotation(Annotation* annotation) { Q_UNUSED(annotation); }

    virtual QList< FormField* > formFields() const { return QList< FormFields* >(); }

};

class Document
{
public:
    static Document* load(const QString& filePath);

    virtual ~Document() {}

    virtual int numberOfPages() const = 0;

    virtual Page* page(int index) const = 0;

    virtual void setAntialiasing(bool on) { Q_UNUSED(on); }
    virtual void setTextAntialiasing(bool on) { Q_UNUSED(on); }
    virtual void setTextHinting(bool on) { Q_UNUSED(on); }

    virtual void loadOutline(QStandardItemModel* outlineModel) const { Q_UNUSED(outlineModel); }
    virtual void loadProperties(QStandardItemModel* propertiesModel) const { Q_UNUSED(propertiesModel); }

};

#endif // DOCUMENTMODEL_H

Follow ups

References