[poppler] poppler/qt4/src: Makefile.am, 1.13, 1.14 poppler-link.cc, 1.4, 1.5 poppler-link.h, 1.3, 1.4 poppler-page.cc, 1.26, 1.27 poppler-qt4.h, 1.34, 1.35 poppler-sound.cc, NONE, 1.1

Albert Astals Cid aacid at kemper.freedesktop.org
Sun Oct 8 13:38:49 PDT 2006


Update of /cvs/poppler/poppler/qt4/src
In directory kemper:/tmp/cvs-serv16976/qt4/src

Modified Files:
	Makefile.am poppler-link.cc poppler-link.h poppler-page.cc 
	poppler-qt4.h 
Added Files:
	poppler-sound.cc 
Log Message:
        * poppler/Link.cc:
        * poppler/Link.h:
        * poppler/Makefile.am:
        * poppler/Page.cc:
        * poppler/Page.h:
        * poppler/Sound.cc:
        * poppler/Sound.h: Make poppler able to read Sound objects, Sound
        actions and Opening/Closing page actions. Patch by Pino Toscano.

        * qt4/src/Makefile.am:
        * qt4/src/poppler-link.cc:
        * qt4/src/poppler-link.h:
        * qt4/src/poppler-qt4.h:
        * qt4/src/poppler-page.cc:
        * qt4/src/poppler-sound.cc: Support for sounds, sound links and page
        actions in the Qt4 backend. Patch by Pino Toscano.



Index: Makefile.am
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/Makefile.am,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- Makefile.am	25 Sep 2006 20:43:18 -0000	1.13
+++ Makefile.am	8 Oct 2006 20:38:47 -0000	1.14
@@ -25,6 +25,7 @@
 	poppler-link.cc				\
 	poppler-annotation.cc			\
 	../../qt/poppler-page-transition.cc	\
+	poppler-sound.cc			\
 	poppler-annotation-helper.h		\
 	poppler-private.h
 

Index: poppler-link.cc
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-link.cc,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- poppler-link.cc	19 May 2006 17:24:19 -0000	1.4
+++ poppler-link.cc	8 Oct 2006 20:38:47 -0000	1.5
@@ -247,6 +247,41 @@
 		return Action;
 	}
 
+	// LinkSound
+	LinkSound::LinkSound( const QRectF &linkArea, double volume, bool sync, bool repeat, bool mix, SoundObject *sound ) : Link(linkArea), m_volume(volume), m_sync(sync), m_repeat(repeat), m_mix(mix), m_sound(sound)
+	{
+	}
+	
+	Link::LinkType LinkSound::linkType() const
+	{
+		return Sound;
+	}
+
+	double LinkSound::volume() const
+	{
+		return m_volume;
+	}
+
+	bool LinkSound::synchronous() const
+	{
+		return m_sync;
+	}
+
+	bool LinkSound::repeat() const
+	{
+		return m_repeat;
+	}
+
+	bool LinkSound::mix() const
+	{
+		return m_mix;
+	}
+
+	SoundObject *LinkSound::sound() const
+	{
+		return m_sound;
+	}
+
 	// LinkMovie
 	LinkMovie::LinkMovie( const QRectF &linkArea ) : Link(linkArea)
 	{

Index: poppler-link.h
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-link.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- poppler-link.h	13 May 2006 11:14:24 -0000	1.3
+++ poppler-link.h	8 Oct 2006 20:38:47 -0000	1.4
@@ -27,6 +27,7 @@
 namespace Poppler {
 
 class LinkDestinationData;
+class SoundObject;
 
 class LinkDestination
 {
@@ -83,7 +84,7 @@
 		Link( const QRectF &linkArea );
 		
 		// get link type (inherited classes mustreturn an unique identifier)
-		enum LinkType { None, Goto, Execute, Browse, Action, Movie };
+		enum LinkType { None, Goto, Execute, Browse, Action, Sound, Movie };
 		virtual LinkType linkType() const;
 
 		// virtual destructor
@@ -174,6 +175,29 @@
 		ActionType m_type;
 };
 
+/** Sound: a sound to be played **/
+class LinkSound : public Link
+{
+	public:
+		// create a Link_Sound
+		LinkSound( const QRectF &linkArea, double volume, bool sync, bool repeat, bool mix, SoundObject *sound );
+
+		LinkType linkType() const;
+
+		double volume() const;
+		bool synchronous() const;
+		bool repeat() const;
+		bool mix() const;
+		SoundObject *sound() const;
+
+	private:
+		double m_volume;
+		bool m_sync;
+		bool m_repeat;
+		bool m_mix;
+		SoundObject *m_sound;
+};
+
 /** Movie: Not yet defined -> think renaming to 'Media' link **/
 class LinkMovie : public Link
 // TODO this (Movie link)

Index: poppler-page.cc
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-page.cc,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- poppler-page.cc	30 Sep 2006 16:28:35 -0000	1.26
+++ poppler-page.cc	8 Oct 2006 20:38:47 -0000	1.27
@@ -123,6 +123,12 @@
     }
     break;
 
+    case actionSound:
+    {
+      ::LinkSound *ls = (::LinkSound *)a;
+      popplerLink = new LinkSound( linkArea, ls->getVolume(), ls->getSynchronous(), ls->getRepeat(), ls->getMix(), new SoundObject( ls->getSound() ) );
+    }
+
     case actionMovie:
 /*      TODO this (Movie link)
           m_type = Movie;
@@ -366,6 +372,32 @@
   return m_page->transition;
 }
 
+Link *Page::action( PageAction act ) const
+{
+  if ( act == Page::Opening || act == Page::Closing )
+  {
+    ::Page *p = m_page->parentDoc->m_doc->doc.getCatalog()->getPage(m_page->index + 1);
+    Object o;
+    p->getActions(&o);
+    if (!o.isDict())
+    {
+      o.free();
+      return 0;
+    }
+    Dict *dict = o.getDict();
+    Object o2;
+    const char *key = act == Page::Opening ? "O" : "C";
+    dict->lookup(key, &o2);
+    ::LinkAction *act = ::LinkAction::parseAction(&o2, m_page->parentDoc->m_doc->doc.getCatalog()->getBaseURI() );
+    o2.free();
+    Link *popplerLink = NULL;
+    if (act != NULL)
+      popplerLink = m_page->convertLinkActionToLink(act, QRectF(), m_page->parentDoc->m_doc);
+    return popplerLink;
+  }
+  return 0;
+}
+
 QSizeF Page::pageSizeF() const
 {
   ::Page *p;

Index: poppler-qt4.h
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-qt4.h,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- poppler-qt4.h	25 Jun 2006 16:59:31 -0000	1.34
+++ poppler-qt4.h	8 Oct 2006 20:38:47 -0000	1.35
@@ -33,6 +33,7 @@
 #include <poppler-page-transition.h>
 
 class EmbFile;
+class Sound;
 
 /**
    The Poppler Qt bindings
@@ -224,6 +225,14 @@
 
 	enum Rotation { Rotate0 = 0, Rotate90 = 1, Rotate180 = 2, Rotate270 = 3 };
 
+	/**
+	   The kinds of page actions
+	*/
+	enum PageAction {
+	    Opening,   ///< The action when a page is "opened"
+	    Closing    ///< The action when a page is "closed"
+	};
+
 	/** 
 	   Render the page to a QImage using the Splash renderer
 	   
@@ -376,6 +385,11 @@
 	PageTransition *transition() const;
 	
 	/**
+	  Gets the page action specified, or NULL if there is no action
+	**/
+	Link *action( PageAction act ) const;
+	
+	/**
 	   Types of orientations that are possible
 	*/
 	enum Orientation {
@@ -710,6 +724,79 @@
     */
     QDateTime convertDate( char *dateString );
 
+    class SoundData;
+    /**
+       Container class for a sound file in a PDF document.
+
+       A sound can be either External (in that case should be loaded the file
+       whose url is represented by url() ), or Embedded, and the player has to
+       play the data contained in data().
+    */
+    class SoundObject {
+    public:
+	/**
+	   The type of sound
+	*/
+	enum SoundType {
+	    External,     ///< The real sound file is external
+	    Embedded      ///< The sound is contained in the data
+	};
+
+	/**
+	   The encoding format used for the sound
+	*/
+	enum SoundEncoding {
+	    Raw,          ///< Raw encoding, with unspecified or unsigned values in the range [ 0, 2^B − 1 ]
+	    Signed,       ///< Twos-complement values
+	    muLaw,        ///< mu-law-encoded samples
+	    ALaw          ///< A-law-encoded samples
+	};
+
+	SoundObject(Sound *popplersound);
+	
+	SoundObject(const SoundObject &s);
+	
+	~SoundObject();
+
+	/**
+	   Is the sound embedded (@ref Embedded ) or external (@ref External )?
+	*/
+	SoundType soundType() const;
+
+	/**
+	   The URL of the sound file to be played, in case of @ref External
+	*/
+	QString url() const;
+
+	/**
+	   The data of the sound, in case of @ref Embedded
+	*/
+	QByteArray data() const;
+
+	/**
+	   The sampling rate of the sound
+	*/
+	double samplingRate() const;
+
+	/**
+	   The number of sound channels to use to play the sound
+	*/
+	int channels() const;
+
+	/**
+	   The number of bits per sample value per channel
+	*/
+	int bitsPerSample() const;
+
+	/**
+	   The encoding used for the sound
+	*/
+	SoundEncoding soundEncoding() const;
+
+    private:
+	SoundData *m_soundData;
+    };
+
 }
 #endif
 

--- NEW FILE: poppler-sound.cc ---
/* poppler-sound.cc: qt interface to poppler
 * Copyright (C) 2006, Pino Toscano <pino at kde.org>
 *
 * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#define UNSTABLE_POPPLER_QT4

#include <QtCore/QByteArray>
#include <QtCore/QString>
#include <QtCore/QVariant>

#include "Object.h"
#include "Dict.h"
#include "Stream.h"
#include "Sound.h"

#include "poppler-qt4.h"

namespace Poppler
{

class SoundData
{
public:
	SoundData()
	  : m_channels( 1 ), m_bitsPerSample( 8 ), m_soundEncoding( SoundObject::Raw ), m_soundObj( new Object() )
	{ m_soundObj->initNull(); }

	QVariant m_data;
	SoundObject::SoundType m_type;
	double m_samplingRate;
	int m_channels;
	int m_bitsPerSample;
	SoundObject::SoundEncoding m_soundEncoding;
	Object *m_soundObj;
};

SoundObject::SoundObject(Sound *popplersound)
{
	m_soundData = new SoundData();
	Dict *dict = popplersound->getStream()->getDict();
	Object tmp;
	// file specs / data
	dict->lookup("F", &tmp);
	if ( !tmp.isNull() )
	{
		// valid 'F' key -> external file
		m_soundData->m_type = SoundObject::External;
		// TODO read the file specifications
		m_soundData->m_data = QVariant( QString() );
	}
	else
	{
		// no file specification, then the sound data have to be
		// extracted from the stream
		m_soundData->m_type = SoundObject::Embedded;
		Stream *stream = popplersound->getStream();
		stream->reset();
		int dataLen = 0;
		QByteArray fileArray;
		int i;
		while ( (i = stream->getChar()) != EOF) {
			fileArray[dataLen] = (char)i;
			++dataLen;
		}
		fileArray.resize(dataLen);
		m_soundData->m_data = QVariant( fileArray );
	}
	tmp.free();
	// sampling rate
	dict->lookup( "R", &tmp );
	if ( tmp.isNum() )
	{
		m_soundData->m_samplingRate = tmp.getNum();
	}
	tmp.free();
	// sound channels
	dict->lookup( "C", &tmp );
	if ( tmp.isInt() )
	{
		m_soundData->m_channels = tmp.getInt();
	}
	tmp.free();
	// sound channels
	dict->lookup( "B", &tmp );
	if ( tmp.isInt() )
	{
		m_soundData->m_bitsPerSample = tmp.getInt();
	}
	tmp.free();
	// encoding format
	dict->lookup( "E", &tmp );
	if ( tmp.isName() )
	{
		const char *enc = tmp.getName();
		if ( !strcmp( "Raw", enc ) )
			m_soundData->m_soundEncoding = SoundObject::Raw;
		else if ( !strcmp( "Signed", enc ) )
			m_soundData->m_soundEncoding = SoundObject::Signed;
		if ( !strcmp( "muLaw", enc ) )
			m_soundData->m_soundEncoding = SoundObject::muLaw;
		if ( !strcmp( "ALaw", enc ) )
			m_soundData->m_soundEncoding = SoundObject::ALaw;
	}
	tmp.free();
	// at the end, copying the object
	popplersound->getObject()->copy(m_soundData->m_soundObj);
}

SoundObject::SoundObject(const SoundObject &s)
{
	m_soundData = new SoundData();
	m_soundData->m_type = s.m_soundData->m_type;
	m_soundData->m_data = s.m_soundData->m_data;
	m_soundData->m_type = s.m_soundData->m_type;
	m_soundData->m_samplingRate = s.m_soundData->m_samplingRate;
	m_soundData->m_channels = s.m_soundData->m_channels;
	m_soundData->m_bitsPerSample = s.m_soundData->m_bitsPerSample;
	m_soundData->m_soundEncoding = s.m_soundData->m_soundEncoding;
	s.m_soundData->m_soundObj->copy(m_soundData->m_soundObj);
}

SoundObject::~SoundObject()
{
	m_soundData->m_soundObj->free();
	delete m_soundData;
}

SoundObject::SoundType SoundObject::soundType() const
{
	return m_soundData->m_type;
}

QString SoundObject::url() const
{
	return m_soundData->m_type == SoundObject::External ? m_soundData->m_data.toString() : QString();
}

QByteArray SoundObject::data() const
{
	return m_soundData->m_type == SoundObject::Embedded ? m_soundData->m_data.toByteArray() : QByteArray();
};

double SoundObject::samplingRate() const
{
	return m_soundData->m_samplingRate;
}

int SoundObject::channels() const
{
	return m_soundData->m_channels;
}

int SoundObject::bitsPerSample() const
{
	return m_soundData->m_bitsPerSample;
}

SoundObject::SoundEncoding SoundObject::soundEncoding() const
{
	return m_soundData->m_soundEncoding;
}

}



More information about the poppler mailing list