Logo Search packages:      
Sourcecode: codeblocks version File versions  Download package

pdfobjects.cpp

Go to the documentation of this file.
///////////////////////////////////////////////////////////////////////////////
// Name:        pdfobjects.cpp
// Purpose:     
// Author:      Ulrich Telle
// Modified by:
// Created:     2006-07-13
// RCS-ID:      $$
// Copyright:   (c) Ulrich Telle
// Licence:     wxWindows licence
///////////////////////////////////////////////////////////////////////////////

/// \file pdfobjects.cpp Implementation of PDF objects

// For compilers that support precompilation, includes <wx.h>.
#include <wx/wxprec.h>

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif

// includes

#include "wx/pdfdoc.h"
#include "wx/pdfobjects.h"

// --- Object queue for processing the resource tree

00032 wxPdfObjectQueue::wxPdfObjectQueue(int originalObjectId, int actualObjectId, wxPdfObject* object)
{
  m_originalObjectId = originalObjectId;
  m_actualObjectId = actualObjectId;
  m_object = object;
  m_next = NULL;
}

// --- Base object

00042 wxPdfObject::wxPdfObject(int type)
{
  m_type = type;
  m_objNum = -1;
  m_objGen = -1;
  m_indirect = false;
}

00050 wxPdfObject::~wxPdfObject()
{
}

void
00055 wxPdfObject::SetObjNum(int objNum, int objGen)
{
  m_objNum = objNum;
  m_objGen = objGen;
}

// --- Null object

00063 wxPdfNull::wxPdfNull()
  : wxPdfObject(OBJTYPE_NULL)
{
}

00068 wxPdfNull::~wxPdfNull()
{
}

// --- Indirect Reference

00074 wxPdfIndirectReference::wxPdfIndirectReference(int number, int generation)
  : wxPdfObject(OBJTYPE_INDIRECT)
{
  SetObjNum(number, generation);
}

00080 wxPdfIndirectReference::~wxPdfIndirectReference()
{
}

// --- Literal

00086 wxPdfLiteral::wxPdfLiteral(int type, const wxString& value)
  : wxPdfObject(type)
{
  m_value = value;
}

00092 wxPdfLiteral::~wxPdfLiteral()
{
}

// --- Boolean

00098 wxPdfBoolean::wxPdfBoolean(bool value)
: wxPdfObject(OBJTYPE_BOOLEAN)
{
  m_value = value;
}

00104 wxPdfBoolean::~wxPdfBoolean()
{
}

wxString
00109 wxPdfBoolean::GetAsString()
{
  return (m_value) ? _T("true") : _T("false");
}

// --- String / Hex string

00116 wxPdfString::wxPdfString(const wxString& value)
: wxPdfObject(OBJTYPE_STRING)
{
  m_value = value;
}

00122 wxPdfString::~wxPdfString()
{
}

// --- Number

00128 wxPdfNumber::wxPdfNumber(const wxString& value)
  : wxPdfObject(OBJTYPE_NUMBER)
{
  m_value = wxPdfDocument::String2Double(value);
  m_string = value;
}

00135 wxPdfNumber::wxPdfNumber(int value)
  : wxPdfObject(OBJTYPE_NUMBER)
{
  m_value = value;
  m_string = wxString::Format(_T("%d"), value);
}

00142 wxPdfNumber::wxPdfNumber(double value)
  : wxPdfObject(OBJTYPE_NUMBER)
{
  m_value = value;
  m_string = wxPdfDocument::Double2String(value, 3);
}

00149 wxPdfNumber::~wxPdfNumber()
{
}

// --- Name

00155 wxPdfName::wxPdfName()
  : wxPdfObject(OBJTYPE_NAME)
{
}

00160 wxPdfName::wxPdfName(const wxString& name)
  : wxPdfObject(OBJTYPE_NAME)
{
  m_name = name;
}

00166 wxPdfName::~wxPdfName()
{
}

// --- Array

00172 wxPdfArray::wxPdfArray()
  : wxPdfObject(OBJTYPE_ARRAY)
{
}

00177 wxPdfArray::~wxPdfArray()
{
  wxPdfObject* obj;
  size_t j;
  for (j = 0; j < m_array.GetCount(); j++)
  {
    obj = (wxPdfObject*) m_array.Item(j);
    if (obj != NULL)
    {
      delete obj;
    }
  }
  m_array.Clear();
}

void
00193 wxPdfArray::Add(wxPdfObject* obj)
{
  m_array.Add(obj);
}

void
00199 wxPdfArray::Add(int value)
{
  wxPdfNumber* obj = new wxPdfNumber(value);
  m_array.Add(obj);
}

void
00206 wxPdfArray::Add(double value)
{
  wxPdfNumber* obj = new wxPdfNumber(value);
  m_array.Add(obj);
}

wxPdfObject*
00213 wxPdfArray::Get(size_t index)
{
  wxPdfObject* obj = NULL;
  if (index >= 0 && index < m_array.GetCount())
  {
    obj = (wxPdfObject*) m_array.Item(index);
  }
  return obj;
}

// --- Dictionary

00225 wxPdfDictionary::wxPdfDictionary()
  : wxPdfObject(OBJTYPE_DICTIONARY)
{
  m_hashMap = new wxPdfDictionaryMap();
}

00231 wxPdfDictionary::~wxPdfDictionary()
{
  wxPdfDictionaryMap::iterator entry = m_hashMap->begin();
  for (entry = m_hashMap->begin(); entry != m_hashMap->end(); entry++)
  {
    wxPdfObject* obj = entry->second;
    delete obj;
  }
  delete m_hashMap;
}

void
00243 wxPdfDictionary::Put(wxPdfName* key, wxPdfObject* value)
{
  (*m_hashMap)[key->GetName()] = value;
}

wxPdfObject*
00249 wxPdfDictionary::Get(const wxString& key)
{
  wxPdfObject* value = NULL;
  wxPdfDictionaryMap::iterator entry = m_hashMap->find(key);
  if (entry != m_hashMap->end())
  {
    value = entry->second;
  }
  return value;
}

// --- Stream

00262 wxPdfStream::wxPdfStream()
  : wxPdfObject(OBJTYPE_STREAM)
{
  m_offset     = 0;
  m_dictionary = NULL;
  m_buffer     = NULL;
  m_hasObjOffsets = false;
}

00271 wxPdfStream::wxPdfStream(off_t offset)
  : wxPdfObject(OBJTYPE_STREAM)
{
  m_offset     = offset;
  m_dictionary = NULL;
  m_buffer     = NULL;
  m_hasObjOffsets = false;
}

00280 wxPdfStream::~wxPdfStream()
{
  if (m_dictionary != NULL)
  {
    delete m_dictionary;
  }
  if (m_buffer != NULL)
  {
    delete m_buffer;
  }
  m_objOffsets.Clear();
}

wxPdfObject*
00294 wxPdfStream::Get(const wxString& key)
{
  wxPdfObject* obj = (m_dictionary != NULL) ? m_dictionary->Get(key) : NULL;
  return obj;
}

  
int
00302 wxPdfStream::GetObjOffset(int index) const
{
  int objOffset = -1;
  if (index >= 0 && (size_t) index < m_objOffsets.GetCount())
  {
    objOffset = m_objOffsets[index];
  }
  return objOffset;
}

Generated by  Doxygen 1.6.0   Back to index