/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
 * This file is part of the libpict project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include "Pict2Parser.h"
#include "libpict_utils.h"
#include <librevenge/librevenge.h>
#include <librevenge/librevenge.h>

Pict2Parser::Pict2Parser(librevenge::RVNGInputStream *input, librevenge::RVNGDrawingInterface *painter):
  PictXParser(input, painter),
  m_recordSize(0)
{
}

bool Pict2Parser::parse()
{
  typedef void (Pict2Parser::*Method)();

  struct RecordHandler
  {
    int type;
    const char *name;
    Method handler;
    int size;
  };

  static const struct RecordHandler handlers[] =
  {
    { 0x00, "NOP",             &Pict2Parser::handleNOP,              2 },
    { 0x01, "clipRgn",         &Pict2Parser::handleClipRgn,         -1 },
    { 0x02, "bkPat",           &Pict2Parser::handleBkPat,           10 },
    { 0x03, "txFont",          &Pict2Parser::handleTxFont,           4 },
    { 0x04, "txFace",          &Pict2Parser::handleTxFace,           3 },
    { 0x05, "txMode",          &Pict2Parser::handleTxMode,           4 },
    { 0x06, "spExtra",         &Pict2Parser::handleSpExtra,          6 },
    { 0x07, "pnSize",          &Pict2Parser::handlePnSize,           6 },
    { 0x08, "pnMode",          &Pict2Parser::handlePnMode,           4 },
    { 0x09, "pnPat",           &Pict2Parser::handlePnPat,           10 },
    { 0x0a, "thePat",          &Pict2Parser::handleThePat,          10 },
    { 0x0b, "owSize",          &Pict2Parser::handleOwSize,           6 },
    { 0x0c, "origin",          &Pict2Parser::handleOrigin,           6 },
    { 0x0d, "txSize",          &Pict2Parser::handleTxSize,           4 },
    { 0x0e, "fgColor",         &Pict2Parser::handleFgColor,          6 },
    { 0x0f, "bkColor",         &Pict2Parser::handleBkColor,          6 },
    { 0x10, "txRatio",         &Pict2Parser::handleTxRatio,         10 },
    { 0x11, "picVersion",      &Pict2Parser::handlePicVersion,       4 },
    { 0x12, "BkPixPat",        &Pict2Parser::handleBkPixPat,        -1 },
    { 0x13, "PnPixPat",        &Pict2Parser::handlePnPixPat,        -1 },
    { 0x14, "FillPixPat",      &Pict2Parser::handleFillPixPat,      -1 },
    { 0x15, "PnLocHFrac",      &Pict2Parser::handlePnLocHFrac,       4 },
    { 0x16, "ChExtra",         &Pict2Parser::handleChExtra,          4 },

    { 0x1a, "RGBFgCol",        &Pict2Parser::handleRGBFgCol,         8 },
    { 0x1b, "RGBBkCol",        &Pict2Parser::handleRGBBkCol,         8 },
    { 0x1c, "HiliteMode",      &Pict2Parser::handleHiliteMode,       2 },
    { 0x1d, "HiliteColor",     &Pict2Parser::handleHiliteColor,      8 },
    { 0x1e, "DefHilite",       &Pict2Parser::handleDefHilite,        2 },
    { 0x1f, "OpColor",         &Pict2Parser::handleOpColor,          8 },
    { 0x20, "line",            &Pict2Parser::handleLine,            10 },
    { 0x21, "line from",       &Pict2Parser::handleLineFrom,         6 },
    { 0x22, "short line",      &Pict2Parser::handleShortLine,        8 },
    { 0x23, "short line from", &Pict2Parser::handleShortLineFrom,    4 },
    { 0x24, "Reserved",        &Pict2Parser::skipData,              -1 },
    { 0x25, "Reserved",        &Pict2Parser::skipData,              -1 },
    { 0x26, "Reserved",        &Pict2Parser::skipData,              -1 },
    { 0x27, "Reserved",        &Pict2Parser::skipData,              -1 },
    { 0x28, "long text",       &Pict2Parser::handleLongText,        -1 },
    { 0x29, "DH text",         &Pict2Parser::handleDHText,          -1 },
    { 0x2a, "DV text",         &Pict2Parser::handleDVText,          -1 },
    { 0x2b, "DHDV text",       &Pict2Parser::handleDHDVText,        -1 },
    { 0x2c, "fontName",        &Pict2Parser::handleFontName,        -1 },
    { 0x2d, "lineJustify",     &Pict2Parser::handleLineJustify,     12 },
    { 0x2e, "glyphState",      &Pict2Parser::handleGlyphState,      10 },
    { 0x2f, "Reserved",        &Pict2Parser::skipData,              -1 },
    { 0x30, "frameRect",       &Pict2Parser::handleFrameRect,       10 },
    { 0x31, "paintRect",       &Pict2Parser::handlePaintRect,       10 },
    { 0x32, "eraseRect",       &Pict2Parser::handleEraseRect,       10 },
    { 0x33, "invertRect",      &Pict2Parser::handleInvertRect,      10 },
    { 0x34, "fillRect",        &Pict2Parser::handleFillRect,        10 },
    { 0x35, "Reserved",        &Pict2Parser::handleNOP,             10 },
    { 0x36, "Reserved",        &Pict2Parser::handleNOP,             10 },
    { 0x38, "frameSameRect",   &Pict2Parser::handleFrameSameRect,    2 },
    { 0x39, "paintSameRect",   &Pict2Parser::handlePaintSameRect,    2 },
    { 0x3a, "eraseSameRect",   &Pict2Parser::handleEraseSameRect,    2 },
    { 0x3b, "invertSameRect",  &Pict2Parser::handleInvertSameRect,   2 },
    { 0x3c, "fillSameRect",    &Pict2Parser::handleFillSameRect,     2 },
    { 0x3d, "Reserved",        &Pict2Parser::handleNOP,              2 },
    { 0x3e, "Reserved",        &Pict2Parser::handleNOP,              2 },
    { 0x3f, "Reserved",        &Pict2Parser::handleNOP,              2 },
    { 0x40, "frameRRect",      &Pict2Parser::handleFrameRRect,      10 },
    { 0x41, "paintRRect",      &Pict2Parser::handlePaintRRect,      10 },
    { 0x42, "eraseRRect",      &Pict2Parser::handleEraseRRect,      10 },
    { 0x43, "invertRRect",     &Pict2Parser::handleInvertRRect,     10 },
    { 0x44, "fillRRect",       &Pict2Parser::handleFillRRect,       10 },
    { 0x45, "Reserved",        &Pict2Parser::handleNOP,             10 },
    { 0x46, "Reserved",        &Pict2Parser::handleNOP,             10 },
    { 0x47, "Reserved",        &Pict2Parser::handleNOP,             10 },
    { 0x48, "frameSameRRect",  &Pict2Parser::handleFrameSameRRect,   2 },
    { 0x49, "paintSameRRect",  &Pict2Parser::handlePaintSameRRect,   2 },
    { 0x4a, "eraseSameRRect",  &Pict2Parser::handleEraseSameRRect,   2 },
    { 0x4b, "invertSameRRect", &Pict2Parser::handleInvertSameRRect,  2 },
    { 0x4c, "fillSameRRect",   &Pict2Parser::handleFillSameRRect,    2 },
    { 0x4d, "Reserved",        &Pict2Parser::handleNOP,              2 },
    { 0x4e, "Reserved",        &Pict2Parser::handleNOP,              2 },
    { 0x4f, "Reserved",        &Pict2Parser::handleNOP,              2 },
    { 0x50, "frameOval",       &Pict2Parser::handleFrameOval,       10 },
    { 0x51, "paintOval",       &Pict2Parser::handlePaintOval,       10 },
    { 0x52, "eraseOval",       &Pict2Parser::handleEraseOval,       10 },
    { 0x53, "invertOval",      &Pict2Parser::handleInsertOval,      10 },
    { 0x54, "fillOval",        &Pict2Parser::handleFillOval,        10 },
    { 0x55, "Reserved",        &Pict2Parser::handleNOP,             10 },
    { 0x56, "Reserved",        &Pict2Parser::handleNOP,             10 },
    { 0x57, "Reserved",        &Pict2Parser::handleNOP,             10 },
    { 0x58, "frameSameOval",   &Pict2Parser::handleFrameSameOval,    2 },
    { 0x59, "paintSameOval",   &Pict2Parser::handlePaintSameOval,    2 },
    { 0x5a, "eraseSameOval",   &Pict2Parser::handleEraseSameOval,    2 },
    { 0x5b, "invertSameOval",  &Pict2Parser::handleInsertSameOval,   2 },
    { 0x5c, "fillSameOval",    &Pict2Parser::handleFillSameOval,     2 },
    { 0x5d, "Reserved",        &Pict2Parser::handleNOP,              2 },
    { 0x5e, "Reserved",        &Pict2Parser::handleNOP,              2 },
    { 0x5f, "Reserved",        &Pict2Parser::handleNOP,              2 },
    { 0x60, "frameArc",        &Pict2Parser::handleFrameArc,        14 },
    { 0x61, "paintArc",        &Pict2Parser::handlePaintArc,        14 },
    { 0x62, "eraseArc",        &Pict2Parser::handleEraseArc,        14 },
    { 0x63, "invertArc",       &Pict2Parser::handleInsertArc,       14 },
    { 0x64, "fillArc",         &Pict2Parser::handleFillArc,         14 },
    { 0x65, "Reserved",        &Pict2Parser::handleNOP,             14 },
    { 0x66, "Reserved",        &Pict2Parser::handleNOP,             14 },
    { 0x67, "Reserved",        &Pict2Parser::handleNOP,             14 },
    { 0x68, "frameSameArc",    &Pict2Parser::handleFrameSameArc,     6 },
    { 0x69, "paintSameArc",    &Pict2Parser::handlePaintSameArc,     6 },
    { 0x6a, "eraseSameArc",    &Pict2Parser::handleEraseSameArc,     6 },
    { 0x6b, "inverSameArc",    &Pict2Parser::handleInsertSameArc,    6 },
    { 0x6c, "fillSameArc",     &Pict2Parser::handleFillSameArc,      6 },
    { 0x6d, "Reserved",        &Pict2Parser::handleNOP,              6 },
    { 0x6e, "Reserved",        &Pict2Parser::handleNOP,              6 },
    { 0x6f, "Reserved",        &Pict2Parser::handleNOP,              6 },
    { 0x70, "framePoly",       &Pict2Parser::handleFramePoly,       -1 },
    { 0x71, "paintPoly",       &Pict2Parser::handlePaintPoly,       -1 },
    { 0x72, "erasePoly",       &Pict2Parser::handleErasePoly,       -1 },
    { 0x73, "invertPoly",      &Pict2Parser::handleInvertPoly,      -1 },
    { 0x74, "fillPoly",        &Pict2Parser::handleFillPoly,        -1 },
    { 0x75, "Reserved",        &Pict2Parser::skipData,              -1 },
    { 0x76, "Reserved",        &Pict2Parser::skipData,              -1 },
    { 0x77, "Reserved",        &Pict2Parser::skipData,              -1 },
    { 0x78, "frameSamePoly",   &Pict2Parser::handleFrameSamePoly,    2 },
    { 0x79, "paintSamePoly",   &Pict2Parser::handlePaintSamePoly,    2 },
    { 0x7a, "eraseSamePoly",   &Pict2Parser::handleEraseSamePoly,    2 },
    { 0x7b, "invertSamePoly",  &Pict2Parser::handleInvertSamePoly,   2 },
    { 0x7c, "fillSamePoly",    &Pict2Parser::handleFillSamePoly,     2 },
    { 0x7d, "Reserved",        &Pict2Parser::handleNOP,              2 },
    { 0x7e, "Reserved",        &Pict2Parser::handleNOP,              2 },
    { 0x7f, "Reserved",        &Pict2Parser::handleNOP,              2 },
    { 0x80, "frameRgn",        &Pict2Parser::handleFrameRgn,        -1 },
    { 0x81, "paintRgn",        &Pict2Parser::handlePaintRgn,        -1 },
    { 0x82, "eraseRgn",        &Pict2Parser::handleEraseRgn,        -1 },
    { 0x83, "invertRgn",       &Pict2Parser::handleInvertRgn,       -1 },
    { 0x84, "fillRgn",         &Pict2Parser::handleFillRgn,         -1 },
    { 0x85, "Reserved",        &Pict2Parser::skipData,              -1 },
    { 0x86, "Reserved",        &Pict2Parser::skipData,              -1 },
    { 0x87, "Reserved",        &Pict2Parser::skipData,              -1 },
    { 0x88, "frameSameRgn",    &Pict2Parser::handleFrameSameRgn,     2 },
    { 0x89, "paintSameRgn",    &Pict2Parser::handlePaintSameRgn,     2 },
    { 0x8a, "eraseSameRgn",    &Pict2Parser::handleEraseSameRgn,     2 },
    { 0x8b, "invertSameRgn",   &Pict2Parser::handleInvertSameRgn,    2 },
    { 0x8c, "fillSameRgn",     &Pict2Parser::handleFillSameRgn,      2 },
    { 0x8d, "Reserved",        &Pict2Parser::handleNOP,              2 },
    { 0x8e, "Reserved",        &Pict2Parser::handleNOP,              2 },
    { 0x8f, "Reserved",        &Pict2Parser::handleNOP,              2 },
    { 0x90, "BitsRect",        &Pict2Parser::handleBitsRect,        -1 },
    { 0x91, "BitsRgn",         &Pict2Parser::handleBitsRgn,         -1 },
    { 0x92, "Reserved",        &Pict2Parser::skipData,              -1 },
    { 0x93, "Reserved",        &Pict2Parser::skipData,              -1 },
    { 0x94, "Reserved",        &Pict2Parser::skipData,              -1 },
    { 0x95, "Reserved",        &Pict2Parser::skipData,              -1 },
    { 0x96, "Reserved",        &Pict2Parser::skipData,              -1 },
    { 0x97, "Reserved",        &Pict2Parser::skipData,              -1 },
    { 0x98, "PackBitsRect",    &Pict2Parser::handlePackBitsRect,    -1 },
    { 0x99, "PackBitsRgn",     &Pict2Parser::handlePackBitsRgn,     -1 },
    { 0x9a, "DirectBitsRect",  &Pict2Parser::handleDirectBitsRect,  -1 },
    { 0x9b, "DirectBitsRgn",   &Pict2Parser::handleDirectBitsRgn,   -1 },
    { 0x9c, "Reserved",        &Pict2Parser::skipData,              -1 },
    { 0x9d, "Reserved",        &Pict2Parser::skipData,              -1 },
    { 0x9e, "Reserved",        &Pict2Parser::skipData,              -1 },
    { 0x9f, "Reserved",        &Pict2Parser::skipData,              -1 },
    { 0xa0, "shortComment",    &Pict2Parser::handleShortComment,     4 },
    { 0xa1, "longComment",     &Pict2Parser::handleLongComment,     -1 },

    { 0xff, "EndOfPicture",    &Pict2Parser::handleEndOfPicture,     2 }
  };

  while (!m_input->isEnd())
  {
    m_recordSize = -1;
    long initialPosition = m_input->tell();
    // Opcodes are aligned to 2 bytes
    if (initialPosition % 2)
      m_input->seek((int)(++initialPosition), librevenge::RVNG_SEEK_SET);
    int recordType = readU16();
    if (recordType == 0x00ff)
      break;
    else if ((recordType >= 0x00a2) && (recordType <= 0x00af))
      skipData();
    else if ((recordType >= 0x00b0) && (recordType <= 0x00cf))
      m_recordSize = 2;
    else if ((recordType >= 0x00d0) && (recordType <= 0x00fe))
      skipLongData();
    else if ((recordType >= 0x0100) && (recordType <= 0x01ff))
      m_recordSize = 4;
    else if (recordType == 0x0200)
      m_recordSize = 6;
    else if (recordType == 0x02ff)
      m_recordSize = 4;
    else if (recordType == 0x0bff)
      m_recordSize = 24;
    else if (recordType == 0x0c00)
      m_recordSize = 26;
    else if (recordType == 0x0c01)
      m_recordSize = 24;
    /* Add other skipped opcodes here */
    else
    {
      // search function to handler this record
      int index = -1;
      for (int i=0; i < (int)(sizeof(handlers)/sizeof(RecordHandler)); i++)
      {
        if (handlers[i].type == recordType)
        {
          index = i;
          break;
        }
      }

      if (index >= 0)
      {
        PICT_DEBUG_MSG(("Position: 0x%.8x, Opcode: 0x%.2x, Opcode Name: %s\n", (int)initialPosition, recordType, handlers[index].name));
        m_recordSize = handlers[index].size;
        Method recordHandler = handlers[index].handler;
        if (recordHandler)
        {
          // invoke the handler for this record
          (this->*recordHandler)();
        }
      }
    }

    if (m_recordSize <= 0) // we were not able to compute variable record size
      return false;
    else
      m_input->seek(initialPosition + m_recordSize, librevenge::RVNG_SEEK_SET);
  }
  return true;
}

void Pict2Parser::handleNOP()
{
}

void Pict2Parser::handleClipRgn()
{
  m_recordSize = (int)readU16() + 1;
  PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}

void Pict2Parser::handleBkPat()
{
}

void Pict2Parser::handleTxFont()
{
}

void Pict2Parser::handleTxFace()
{
}

void Pict2Parser::handleTxMode()
{
}

void Pict2Parser::handleSpExtra()
{
}

void Pict2Parser::handlePnSize()
{
}

void Pict2Parser::handlePnMode()
{
}

void Pict2Parser::handlePnPat()
{
}

void Pict2Parser::handleThePat()
{
}

void Pict2Parser::handleOwSize()
{
}

void Pict2Parser::handleOrigin()
{
}

void Pict2Parser::handleTxSize()
{
}

void Pict2Parser::handleFgColor()
{
}

void Pict2Parser::handleBkColor()
{
}

void Pict2Parser::handleTxRatio()
{
}

void Pict2Parser::handlePicVersion()
{
}

void Pict2Parser::handleBkPixPat()
{
}

void Pict2Parser::handlePnPixPat()
{
}

void Pict2Parser::handleFillPixPat()
{
}

void Pict2Parser::handlePnLocHFrac()
{
}

void Pict2Parser::handleChExtra()
{
}

void Pict2Parser::handleRGBFgCol()
{
}

void Pict2Parser::handleRGBBkCol()
{
}

void Pict2Parser::handleHiliteMode()
{
}

void Pict2Parser::handleHiliteColor()
{
}

void Pict2Parser::handleDefHilite()
{
}

void Pict2Parser::handleOpColor()
{
}

void Pict2Parser::handleLine()
{
}

void Pict2Parser::handleLineFrom()
{
}

void Pict2Parser::handleShortLine()
{
}

void Pict2Parser::handleShortLineFrom()
{
}

void Pict2Parser::handleLongText()
{
  m_input->seek(6, librevenge::RVNG_SEEK_CUR);
  m_recordSize = (int)readU16() + 6;
  PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}

void Pict2Parser::handleDHText()
{
  m_input->seek(2, librevenge::RVNG_SEEK_CUR);
  m_recordSize = (int)readU16() + 3;
  PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}

void Pict2Parser::handleDVText()
{
  m_input->seek(2, librevenge::RVNG_SEEK_CUR);
  m_recordSize = (int)readU16() + 3;
  PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}

void Pict2Parser::handleDHDVText()
{
  m_input->seek(3, librevenge::RVNG_SEEK_CUR);
  m_recordSize = (int)readU16() + 4;
  PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}


void Pict2Parser::handleFrameRect()
{
}

void Pict2Parser::handlePaintRect()
{
}

void Pict2Parser::handleEraseRect()
{
}

void Pict2Parser::handleInvertRect()
{
}

void Pict2Parser::handleFillRect()
{
}

void Pict2Parser::handleFrameSameRect()
{
}

void Pict2Parser::handlePaintSameRect()
{
}

void Pict2Parser::handleEraseSameRect()
{
}

void Pict2Parser::handleInvertSameRect()
{
}

void Pict2Parser::handleFillSameRect()
{
}

void Pict2Parser::handleFrameRRect()
{
}

void Pict2Parser::handlePaintRRect()
{
}

void Pict2Parser::handleEraseRRect()
{
}

void Pict2Parser::handleInvertRRect()
{
}

void Pict2Parser::handleFillRRect()
{
}

void Pict2Parser::handleFrameSameRRect()
{
}

void Pict2Parser::handlePaintSameRRect()
{
}

void Pict2Parser::handleEraseSameRRect()
{
}

void Pict2Parser::handleInvertSameRRect()
{
}

void Pict2Parser::handleFillSameRRect()
{
}

void Pict2Parser::handleFrameOval()
{
}

void Pict2Parser::handlePaintOval()
{
}

void Pict2Parser::handleEraseOval()
{
}

void Pict2Parser::handleInsertOval()
{
}

void Pict2Parser::handleFillOval()
{
}

void Pict2Parser::handleFrameSameOval()
{
}

void Pict2Parser::handlePaintSameOval()
{
}

void Pict2Parser::handleEraseSameOval()
{
}

void Pict2Parser::handleInsertSameOval()
{
}

void Pict2Parser::handleFillSameOval()
{
}

void Pict2Parser::handleFrameArc()
{
}

void Pict2Parser::handlePaintArc()
{
}

void Pict2Parser::handleEraseArc()
{
}

void Pict2Parser::handleInsertArc()
{
}

void Pict2Parser::handleFillArc()
{
}

void Pict2Parser::handleFrameSameArc()
{
}

void Pict2Parser::handlePaintSameArc()
{
}

void Pict2Parser::handleEraseSameArc()
{
}

void Pict2Parser::handleInsertSameArc()
{
}

void Pict2Parser::handleFillSameArc()
{
}

void Pict2Parser::handleFramePoly()
{
  m_recordSize = (int)readU16() + 1;
  PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}

void Pict2Parser::handlePaintPoly()
{
  m_recordSize = (int)readU16() + 1;
  PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}

void Pict2Parser::handleErasePoly()
{
  m_recordSize = (int)readU16() + 1;
  PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}

void Pict2Parser::handleInvertPoly()
{
  m_recordSize = (int)readU16() + 1;
  PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}

void Pict2Parser::handleFillPoly()
{
  m_recordSize = (int)readU16() + 1;
  PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}

void Pict2Parser::handleFrameSamePoly()
{
}

void Pict2Parser::handlePaintSamePoly()
{
}

void Pict2Parser::handleEraseSamePoly()
{
}

void Pict2Parser::handleInvertSamePoly()
{
}

void Pict2Parser::handleFillSamePoly()
{
}

void Pict2Parser::handleFrameRgn()
{
  m_recordSize = (int)readU16() + 1;
  PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}

void Pict2Parser::handlePaintRgn()
{
  m_recordSize = (int)readU16() + 1;
  PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}

void Pict2Parser::handleEraseRgn()
{
  m_recordSize = (int)readU16() + 1;
  PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}

void Pict2Parser::handleInvertRgn()
{
  m_recordSize = (int)readU16() + 1;
  PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}

void Pict2Parser::handleFillRgn()
{
  m_recordSize = (int)readU16() + 1;
  PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}


void Pict2Parser::handleFrameSameRgn()
{
}

void Pict2Parser::handlePaintSameRgn()
{
}

void Pict2Parser::handleEraseSameRgn()
{
}

void Pict2Parser::handleInvertSameRgn()
{
}

void Pict2Parser::handleFillSameRgn()
{
}

void Pict2Parser::handleBitsRect()
{
  unsigned short rowBytes = readU16();
  PICT_DEBUG_MSG(("Row bytes: %i\n", rowBytes));
  unsigned short bounds_top = readU16();
  PICT_DEBUG_MSG(("Bounds.top: %i\n", bounds_top));
  readU16();
  unsigned short bounds_bottom = readU16();
  PICT_DEBUG_MSG(("Bounds.bottom: %i\n", bounds_bottom));
  readU16();
  m_input->seek(18, librevenge::RVNG_SEEK_CUR);
  m_recordSize = 29 + (0x7fff & rowBytes)*((bounds_bottom > bounds_top) ? bounds_bottom - bounds_top : bounds_top - bounds_bottom);
  PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}

void Pict2Parser::handleBitsRgn()
{
  unsigned short rowBytes = readU16();
  PICT_DEBUG_MSG(("Row bytes: %i\n", rowBytes));
  unsigned short bounds_top = readU16();
  PICT_DEBUG_MSG(("Bounds.top: %i\n", bounds_top));
  readU16();
  unsigned short bounds_bottom = readU16();
  PICT_DEBUG_MSG(("Bounds.bottom: %i\n", bounds_bottom));
  readU16();
  m_input->seek(18, librevenge::RVNG_SEEK_CUR);
  m_recordSize = 29 + (0x7fff & rowBytes)*((bounds_bottom > bounds_top) ? (int)(bounds_bottom - bounds_top) : (int)(bounds_top - bounds_bottom));
  m_recordSize += readU16();
  PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}

void Pict2Parser::handlePackBitsRect()
{
#ifdef DEBUG
  unsigned short rowBytes = readU16();
  PICT_DEBUG_MSG(("Row bytes: %i\n", rowBytes));
  unsigned short bounds_top = readU16();
  PICT_DEBUG_MSG(("Bounds.top: %i\n", bounds_top));
  readU16();
  unsigned short bounds_bottom = readU16();
  PICT_DEBUG_MSG(("Bounds.bottom: %i\n", bounds_bottom));
#else
  readU16();
  readU16();
  readU16();
  readU16();
#endif
  readU16();
  m_input->seek(18, librevenge::RVNG_SEEK_CUR);
#if 0
  m_recordSize = 29 + (0x7fff & rowBytes)*((bounds_bottom > bounds_top) ? bounds_bottom - bounds_top : bounds_top - bounds_bottom);
#endif
  PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}

void Pict2Parser::handlePackBitsRgn()
{
#ifdef DEBUG
  unsigned short rowBytes = readU16();
  PICT_DEBUG_MSG(("Row bytes: %i\n", rowBytes));
  unsigned short bounds_top = readU16();
  PICT_DEBUG_MSG(("Bounds.top: %i\n", bounds_top));
  readU16();
  unsigned short bounds_bottom = readU16();
  PICT_DEBUG_MSG(("Bounds.bottom: %i\n", bounds_bottom));
#else
  readU16();
  readU16();
  readU16();
  readU16();
#endif
  readU16();
  m_input->seek(18, librevenge::RVNG_SEEK_CUR);
#if 0
  m_recordSize = 29 + (0x7fff & rowBytes)*((bounds_bottom > bounds_top) ? bounds_bottom - bounds_top : bounds_top - bounds_bottom);
  m_recordSize += readU16();
#endif
  PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}

void Pict2Parser::handleShortComment()
{
}

void Pict2Parser::handleLongComment()
{
}

void Pict2Parser::handleEndOfPicture()
{
}

void Pict2Parser::handleFontName()
{
}

void Pict2Parser::handleLineJustify()
{
}

void Pict2Parser::handleGlyphState()
{
}

void Pict2Parser::handleDirectBitsRect()
{
}

void Pict2Parser::handleDirectBitsRgn()
{
}

void Pict2Parser::skipData()
{
  m_recordSize = (int)readU16() + 2 + 2;
  PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}

void Pict2Parser::skipLongData()
{
  m_recordSize = (int)readU32() + 4 + 2;
  PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */