LCOV - code coverage report
Current view: top level - libreoffice/hwpfilter/source - drawing.h (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 285 0.0 %
Date: 2012-12-27 Functions: 0 21 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef _DRAWING_H_
      21             : #define _DRAWING_H_
      22             : 
      23             : #include "precompile.h"
      24             : 
      25             : #include <list>
      26             : #include <math.h>
      27             : 
      28             : #include <osl/diagnose.h>
      29             : 
      30             : #include <comphelper/newarray.hxx>
      31             : 
      32             : #include "hwplib.h"
      33             : #include "hwpfile.h"
      34             : #include "hiodev.h"
      35             : #include "hbox.h"
      36             : #include "drawdef.h"
      37             : 
      38             : enum
      39             : {
      40             :     OBJFUNC_LOAD,
      41             :     OBJFUNC_FREE,
      42             :     OBJFUNC_DISPLAY,
      43             :     OBJFUNC_NITEM
      44             : };
      45             : 
      46             : enum
      47             : {
      48             :     BEGIN_GRADATION = 0, LINEAR, RADIAL, CONICAL, SQUARE,
      49             :     END_GRADATION, BITMAP_PATTERN
      50             : };
      51             : 
      52             : #define OBJRET_FILE_OK           0
      53             : #define OBJRET_FILE_ERROR       (-1)
      54             : #define OBJRET_FILE_NO_PRIVATE_BLOCK    (-2)
      55             : #define OBJRET_FILE_NO_PRIVATE_BLOCK_2  (-3)
      56             : 
      57             : typedef int (*HWPDOFuncType) (int, HWPDrawingObject *, int, void *, int);
      58             : 
      59             : #define HWPDOFunc(hdo, cmd, argp, argv) \
      60             :     (HWPDOFuncTbl[(hdo)->type]((hdo)->type, (hdo), (cmd), (argp), (argv)))
      61             : #define HWPDOFunc2(type, cmd, argp, argv) \
      62             :     (HWPDOFuncTbl[(type)]((type), NULL, (cmd), (argp), (argv)))
      63             : 
      64             : static int HWPDOLineFunc(int, HWPDrawingObject *, int, void *, int);
      65             : static int HWPDORectFunc(int, HWPDrawingObject *, int, void *, int);
      66             : static int HWPDOEllipseFunc(int, HWPDrawingObject *, int, void *, int);
      67             : static int HWPDOArcFunc(int, HWPDrawingObject *, int, void *, int);
      68             : static int HWPDOFreeFormFunc(int, HWPDrawingObject *, int, void *, int);
      69             : static int HWPDOTextBoxFunc(int, HWPDrawingObject *, int, void *, int);
      70             : static int HWPDOEllipse2Func(int, HWPDrawingObject *, int, void *, int);
      71             : static int HWPDOArc2Func(int, HWPDrawingObject *, int, void *, int);
      72             : static int HWPDOContainerFunc(int, HWPDrawingObject *, int, void *, int);
      73             : static HWPPara *LoadParaList();
      74             : 
      75             : HWPDOFuncType HWPDOFuncTbl[] =
      76             : {
      77             :     HWPDOContainerFunc,
      78             :     HWPDOLineFunc,
      79             :     HWPDORectFunc,
      80             :     HWPDOEllipseFunc,
      81             :     HWPDOArcFunc,
      82             :     HWPDOFreeFormFunc,
      83             :     HWPDOTextBoxFunc,
      84             :     HWPDOFreeFormFunc,
      85             :     HWPDOEllipse2Func,
      86             :     HWPDOArc2Func,
      87             :     HWPDOFreeFormFunc,
      88             : };
      89             : 
      90             : static HMemIODev *hmem = 0;
      91             : 
      92             : static int count = 0;
      93             : 
      94             : inline bool HAVE_FCOLOR(HWPDrawingObject * hdo)
      95             : {
      96             :     return hdo->property.fill_color != HWPDO_COLOR_NONE;
      97             : }
      98             : 
      99             : 
     100             : inline bool HAVE_PATTERN(HWPDrawingObject * hdo)
     101             : {
     102             :     return (hdo->property.pattern_type & HWPDO_PAT_TYPE_BITS)
     103             :         != HWPDO_PAT_SOLID && hdo->property.pattern_color != HWPDO_COLOR_NONE;
     104             : }
     105             : 
     106             : 
     107             : inline bool HAVE_GRADATION(HWPDrawingObject * hdo)
     108             : {
     109             :     return hdo->property.gstyle > BEGIN_GRADATION &&
     110             :         hdo->property.gstyle < END_GRADATION &&
     111             :         hdo->property.fromcolor != HWPDO_COLOR_NONE &&
     112             :         hdo->property.tocolor != HWPDO_COLOR_NONE;
     113             : }
     114             : 
     115             : 
     116             : inline bool HAVE_BITMAP_PATTERN(HWPDrawingObject * hdo)
     117             : {
     118             :     return hdo->property.gstyle == BITMAP_PATTERN &&
     119             :         hdo->property.szPatternFile[0];
     120             : }
     121             : 
     122             : 
     123             : inline bool HAS_PAT(HWPDrawingObject * hdo)
     124             : {
     125             :     return HAVE_FCOLOR(hdo) || HAVE_PATTERN(hdo) ||
     126             :         HAVE_GRADATION(hdo) || HAVE_BITMAP_PATTERN(hdo);
     127             : }
     128             : 
     129             : 
     130           0 : static void SetHdoParallRgn(HWPDrawingObject * hdo, int width, int height)
     131             : {
     132           0 :     hdo->property.parall.pt[0].x = 0;
     133           0 :     hdo->property.parall.pt[0].y = 0;
     134           0 :     hdo->property.parall.pt[1].x = width;
     135           0 :     hdo->property.parall.pt[1].y = 0;
     136           0 :     hdo->property.parall.pt[2].x = width;
     137           0 :     hdo->property.parall.pt[2].y = height;
     138           0 : }
     139             : 
     140             : 
     141           0 : static bool SkipPrivateBlock(int type)
     142             : {
     143             :     int n;
     144             : 
     145           0 :     if (type == OBJRET_FILE_NO_PRIVATE_BLOCK)
     146             :     {
     147           0 :         n = hmem->read4b();
     148           0 :         if (hmem->state() || hmem->skipBlock(n) != n)
     149           0 :             return false;
     150             :     }
     151           0 :     n = hmem->read4b();
     152           0 :     if (hmem->state())
     153           0 :         return false;
     154           0 :     return hmem->skipBlock(n) == n;
     155             : }
     156             : 
     157             : 
     158             : static int SizeExpected;
     159             : static int SizeRead;
     160             : 
     161           0 : static int ReadSizeField(int size)
     162             : {
     163           0 :     SizeExpected = size;
     164           0 :     SizeRead = hmem->read4b();
     165           0 :     if (hmem->state())
     166           0 :         return -1;
     167           0 :     return SizeRead;
     168             : }
     169             : 
     170             : 
     171           0 : static bool SkipUnusedField(void)
     172             : {
     173             :     return (SizeExpected < SizeRead) ?
     174           0 :         hmem->skipBlock(SizeRead - SizeExpected) != 0 : true;
     175             : }
     176             : 
     177             : 
     178             : #define HDOFILE_HEADER_SIZE (2*4+16)              // 16=sizeof(ZZRect)
     179             : #define HDOFILE_COMMON_SIZE (7*4+16+44)
     180             : 
     181             : #define HDOFILE_HAS_NEXT    0x01
     182             : #define HDOFILE_HAS_CHILD   0x02
     183             : 
     184           0 : static bool LoadCommonHeader(HWPDrawingObject * hdo, WORD * link_info)
     185             : {
     186             :     uint size, common_size;
     187             : 
     188           0 :      if( !hmem )
     189           0 :          return FALSE;
     190           0 :     size = hmem->read4b();
     191           0 :     if (hmem->state())
     192             :     {
     193           0 :         return FALSE;
     194             :     }
     195           0 :     if (size < HDOFILE_COMMON_SIZE)
     196             :     {
     197           0 :         return FALSE;
     198             :     }
     199             : 
     200           0 :     common_size = HDOFILE_COMMON_SIZE;
     201           0 :     hdo->type = hmem->read2b();
     202           0 :     *link_info = sal::static_int_cast<WORD>(hmem->read2b());
     203           0 :     hdo->offset.x = hmem->read4b();
     204           0 :     hdo->offset.y = hmem->read4b();
     205           0 :     hdo->extent.w = hmem->read4b();
     206           0 :     hdo->extent.h = hmem->read4b();
     207           0 :     hdo->offset2.x = hmem->read4b();
     208           0 :     hdo->offset2.y = hmem->read4b();
     209             : 
     210           0 :     if (hmem->state())
     211           0 :         return FALSE;
     212             : 
     213           0 :     hdo->vrect.x = hmem->read4b();
     214           0 :     hdo->vrect.y = hmem->read4b();
     215           0 :     hdo->vrect.w = hmem->read4b();
     216           0 :     hdo->vrect.h = hmem->read4b();
     217             : 
     218             : // read bare property 44 bytes
     219           0 :     hdo->property.line_pstyle = hmem->read4b();
     220           0 :     hdo->property.line_hstyle = hmem->read4b();
     221           0 :     hdo->property.line_tstyle = hmem->read4b();
     222           0 :     hdo->property.line_color = hmem->read4b();
     223           0 :     hdo->property.line_width = (hunit) hmem->read4b();
     224           0 :     hdo->property.fill_color = hmem->read4b();
     225           0 :     hdo->property.pattern_type = hmem->read4b();
     226           0 :     hdo->property.pattern_color = hmem->read4b();
     227           0 :     hdo->property.hmargin = (hunit) hmem->read4b();
     228           0 :     hdo->property.vmargin = (hunit) hmem->read4b();
     229           0 :     hdo->property.flag = hmem->read4b();
     230             : // read ratation property 32 bytes
     231           0 :     if ((size >= common_size + 32)
     232             :         && (hdo->property.flag & HWPDO_FLAG_ROTATION))
     233             :     {
     234           0 :         hdo->property.rot_originx = hmem->read4b();
     235           0 :         hdo->property.rot_originy = hmem->read4b();
     236           0 :         for (int ii = 0; ii < 3; ii++)
     237             :         {
     238           0 :             hdo->property.parall.pt[ii].x = hmem->read4b();
     239           0 :             hdo->property.parall.pt[ii].y = hmem->read4b();
     240             :         }
     241           0 :         common_size += 32;
     242             :     }
     243             :     else
     244           0 :         SetHdoParallRgn(hdo, hdo->extent.w, hdo->extent.h);
     245             : 
     246             : // read gradient property 28 bytes
     247           0 :     if ((size >= common_size + 28) &&
     248             :         (hdo->property.flag & HWPDO_FLAG_GRADATION))
     249             :     {
     250           0 :         hdo->property.fromcolor = hmem->read4b();
     251           0 :         hdo->property.tocolor = hmem->read4b();
     252           0 :         hdo->property.gstyle = hmem->read4b();
     253           0 :         hdo->property.angle = hmem->read4b();
     254           0 :         hdo->property.center_x = hmem->read4b();
     255           0 :         hdo->property.center_y = hmem->read4b();
     256           0 :         hdo->property.nstep = hmem->read4b();
     257           0 :         common_size += 28;
     258             :     }
     259             : 
     260             : // read bitmap property 278 bytes
     261           0 :     if ((size >= common_size + 278) && \
     262             :         (hdo->property.flag & HWPDO_FLAG_BITMAP))
     263             :     {
     264           0 :         hdo->property.offset1.x = hmem->read4b();
     265           0 :         hdo->property.offset1.y = hmem->read4b();
     266           0 :         hdo->property.offset2.x = hmem->read4b();
     267           0 :         hdo->property.offset2.y = hmem->read4b();
     268           0 :         if (!hmem->readBlock(hdo->property.szPatternFile, 261))
     269           0 :             return FALSE;
     270           0 :         hdo->property.pictype = sal::static_int_cast<char>(hmem->read1b());
     271           0 :         common_size += 278;
     272             :     }
     273           0 :      if( ( size >= common_size + 3 ) && ( hdo->property.flag & HWPDO_FLAG_WATERMARK ) )
     274             :      //if( ( size >= common_size ) && ( hdo->property.flag >> 20 & 0x01 ) )
     275             :      {
     276           0 :           if( size - common_size >= 5 )
     277           0 :               hmem->skipBlock( 2 );
     278           0 :          hdo->property.luminance = hmem->read1b();
     279           0 :          hdo->property.contrast = hmem->read1b();
     280           0 :          hdo->property.greyscale = hmem->read1b();
     281           0 :          common_size += 5;
     282             :      }
     283             :     else{
     284           0 :          hdo->property.luminance = 0;
     285           0 :          hdo->property.contrast = 0;
     286           0 :          hdo->property.greyscale = 0;
     287             :     }
     288           0 :      hdo->property.pPara = 0L;
     289             : 
     290           0 :      if( ( size > common_size ) && (hdo->property.flag & HWPDO_FLAG_AS_TEXTBOX) )
     291             :      {
     292           0 :           hmem->skipBlock(8);
     293           0 :           hdo->property.pPara = LoadParaList();
     294           0 :           if( hdo->property.pPara )
     295           0 :                 return TRUE;
     296             :           else
     297           0 :                 return FALSE;
     298             :      }
     299             : 
     300           0 :      if( size <= common_size )
     301           0 :           return TRUE;
     302           0 :      return hmem->skipBlock(size - common_size ) != 0;
     303             : }
     304             : 
     305             : 
     306           0 : static HWPDrawingObject *LoadDrawingObject(void)
     307             : {
     308             :     HWPDrawingObject *hdo, *head, *prev;
     309             :     int res;
     310             : 
     311             :     WORD link_info;
     312             : 
     313           0 :     head = prev = NULL;
     314           0 :     do
     315             :     {
     316           0 :         if ((hdo = new HWPDrawingObject) == NULL)
     317             :         {
     318           0 :             goto error;
     319             :         }
     320           0 :         if (!LoadCommonHeader(hdo, &link_info))
     321             :         {
     322           0 :             goto error;
     323             :         }
     324           0 :         if (hdo->type < 0 || hdo->type >= HWPDO_NITEMS)
     325             :         {
     326           0 :             hdo->type = HWPDO_RECT;
     327           0 :             if (!SkipPrivateBlock(OBJRET_FILE_NO_PRIVATE_BLOCK))
     328             :             {
     329           0 :                 goto error;
     330             :             }
     331             :         }
     332             :         else
     333             :         {
     334           0 :             switch (res = HWPDOFunc(hdo, OBJFUNC_LOAD, NULL, 0))
     335             :             {
     336             :                 case OBJRET_FILE_ERROR:
     337           0 :                     goto error;
     338             :                 case OBJRET_FILE_OK:
     339           0 :                     break;
     340             :                 case OBJRET_FILE_NO_PRIVATE_BLOCK:
     341             :                 case OBJRET_FILE_NO_PRIVATE_BLOCK_2:
     342           0 :                     if (!SkipPrivateBlock(res))
     343           0 :                         goto error;
     344           0 :                     break;
     345             :             }
     346             :         }
     347           0 :         if (link_info & HDOFILE_HAS_CHILD)
     348             :         {
     349           0 :             hdo->child = LoadDrawingObject();
     350           0 :             if (hdo->child == NULL)
     351             :             {
     352           0 :                 goto error;
     353             :             }
     354             :         }
     355           0 :         if (prev == NULL)
     356           0 :             head = hdo;
     357             :         else
     358           0 :             prev->next = hdo;
     359           0 :         prev = hdo;
     360             :     }
     361             :     while (link_info & HDOFILE_HAS_NEXT);
     362             : 
     363           0 :     return head;
     364             :     error:
     365             : // drawing object can be list.
     366             : // hdo = current item, head = list;
     367             : 
     368           0 :     if (hdo != NULL)
     369             :     {
     370           0 :         HWPDOFunc(hdo, OBJFUNC_FREE, NULL, 0);
     371           0 :         delete hdo;
     372             :     }
     373           0 :     if( prev )
     374             :     {
     375           0 :         prev->next = NULL;
     376           0 :         return head;
     377             :     }
     378             :     else
     379           0 :         return 0;
     380             : }
     381             : 
     382             : 
     383           0 : static bool LoadDrawingObjectBlock(Picture * pic)
     384             : {
     385           0 :     int size = hmem->read4b();
     386             : 
     387           0 :     if (hmem->state() || size < HDOFILE_HEADER_SIZE)
     388           0 :         return false;
     389             : 
     390           0 :     pic->picinfo.picdraw.zorder = hmem->read4b();
     391           0 :     pic->picinfo.picdraw.mbrcnt = hmem->read4b();
     392           0 :     pic->picinfo.picdraw.vrect.x = hmem->read4b();
     393           0 :     pic->picinfo.picdraw.vrect.y = hmem->read4b();
     394           0 :     pic->picinfo.picdraw.vrect.w = hmem->read4b();
     395           0 :     pic->picinfo.picdraw.vrect.h = hmem->read4b();
     396             : 
     397           0 :     if (size > HDOFILE_HEADER_SIZE &&
     398           0 :         !hmem->skipBlock(size - HDOFILE_HEADER_SIZE))
     399           0 :         return false;
     400             : 
     401           0 :     pic->picinfo.picdraw.hdo = LoadDrawingObject();
     402           0 :     if (pic->picinfo.picdraw.hdo == 0)
     403           0 :         return false;
     404           0 :     return true;
     405             : }
     406             : 
     407             : 
     408             : // object manipulation function
     409             : 
     410             : static int
     411           0 : HWPDODefaultFunc(int , HWPDrawingObject * , int cmd, void *, int)
     412             : {
     413           0 :     if (cmd == OBJFUNC_LOAD)
     414           0 :         return OBJRET_FILE_NO_PRIVATE_BLOCK;
     415           0 :     return true;
     416             : }
     417             : 
     418             : 
     419             : static int
     420           0 : HWPDOLineFunc(int type, HWPDrawingObject * hdo, int cmd, void *argp, int argv)
     421             : {
     422           0 :     int ret = true;
     423           0 :     switch (cmd)
     424             :     {
     425             :         case OBJFUNC_LOAD:
     426           0 :             if (ReadSizeField(4) < 4)
     427           0 :                 return OBJRET_FILE_ERROR;
     428           0 :             hdo->u.line_arc.flip = hmem->read4b();
     429           0 :             if (hmem->state())
     430           0 :                 return OBJRET_FILE_ERROR;
     431           0 :             if (!SkipUnusedField())
     432           0 :                 return OBJRET_FILE_ERROR;
     433           0 :             ret = OBJRET_FILE_NO_PRIVATE_BLOCK_2;
     434           0 :             break;
     435             :         default:
     436           0 :             ret = HWPDODefaultFunc(type, hdo, cmd, argp, argv);
     437           0 :             break;
     438             :     }
     439           0 :     return ret;
     440             : }
     441             : 
     442             : 
     443             : // rectangle
     444             : 
     445             : static int
     446           0 : HWPDORectFunc(int type, HWPDrawingObject * hdo, int cmd, void *argp, int argv)
     447             : {
     448           0 :     return HWPDODefaultFunc(type, hdo, cmd, argp, argv);
     449             : }
     450             : 
     451             : 
     452             : // ellipse
     453             : 
     454             : static int
     455           0 : HWPDOEllipseFunc(int type, HWPDrawingObject * hdo,
     456             : int cmd, void *argp, int argv)
     457             : {
     458           0 :     return HWPDODefaultFunc(type, hdo, cmd, argp, argv);
     459             : }
     460             : 
     461             : #define WTMM(x)     ((double)(x) / 1800. * 25.4)
     462             : static int
     463           0 : HWPDOEllipse2Func(int type, HWPDrawingObject * hdo,
     464             : int cmd, void *argp, int argv)
     465             : {
     466           0 :     switch (cmd)
     467             :     {
     468             :         case OBJFUNC_LOAD:
     469           0 :             if (ReadSizeField(16) < 16)
     470           0 :                 return OBJRET_FILE_ERROR;
     471           0 :             hdo->u.arc.radial[0].x = hmem->read4b();
     472           0 :             hdo->u.arc.radial[0].y = hmem->read4b();
     473           0 :             hdo->u.arc.radial[1].x = hmem->read4b();
     474           0 :             hdo->u.arc.radial[1].y = hmem->read4b();
     475             : 
     476           0 :             if (ReadSizeField(0) < 0)
     477           0 :                 return OBJRET_FILE_ERROR;
     478           0 :             break;
     479             :         default:
     480           0 :             return HWPDODefaultFunc(type, hdo, cmd, argp, argv);
     481             :     }
     482           0 :     return true;
     483             : }
     484             : 
     485             : 
     486             : // arc
     487             : 
     488             : static int
     489           0 : HWPDOArcFunc(int type, HWPDrawingObject * hdo, int cmd, void *argp, int argv)
     490             : {
     491           0 :     switch (cmd)
     492             :     {
     493             :         case OBJFUNC_LOAD:
     494           0 :             if (ReadSizeField(4) < 4)
     495           0 :                 return OBJRET_FILE_ERROR;
     496           0 :             hdo->u.line_arc.flip = hmem->read4b();
     497           0 :             if (hmem->state())
     498           0 :                 return OBJRET_FILE_ERROR;
     499           0 :             if (!SkipUnusedField())
     500           0 :                 return OBJRET_FILE_ERROR;
     501           0 :             break;
     502             :         default:
     503           0 :             return HWPDODefaultFunc(type, hdo, cmd, argp, argv);
     504             :     }
     505           0 :     return true;
     506             : }
     507             : 
     508             : 
     509             : static int
     510           0 : HWPDOArc2Func(int type, HWPDrawingObject * hdo, int cmd, void *argp, int argv)
     511             : {
     512           0 :     int ret = true;
     513           0 :     switch (cmd)
     514             :     {
     515             :         case OBJFUNC_LOAD:
     516           0 :             ret = OBJRET_FILE_NO_PRIVATE_BLOCK;
     517           0 :             break;
     518             :         default:
     519           0 :             ret = HWPDODefaultFunc(type, hdo, cmd, argp, argv);
     520           0 :             break;
     521             :     }
     522           0 :     return ret;
     523             : }
     524             : 
     525             : 
     526             : static int
     527           0 : HWPDOFreeFormFunc(int type, HWPDrawingObject * hdo,
     528             : int cmd, void *argp, int argv)
     529             : {
     530           0 :     switch (cmd)
     531             :     {
     532             :         case OBJFUNC_LOAD:
     533             :         {
     534           0 :             hdo->u.freeform.pt = 0;
     535           0 :             if (ReadSizeField(4) < 4)
     536           0 :                 return OBJRET_FILE_ERROR;
     537           0 :             hdo->u.freeform.npt = hmem->read4b();
     538           0 :             if (hmem->state())
     539           0 :                 return OBJRET_FILE_ERROR;
     540           0 :             if (!SkipUnusedField())
     541           0 :                 return OBJRET_FILE_ERROR;
     542             : 
     543           0 :             int size = hdo->u.freeform.npt * sizeof(ZZPoint);
     544             : 
     545           0 :             if (ReadSizeField(size) < size)
     546           0 :                 return OBJRET_FILE_ERROR;
     547           0 :             if (hdo->u.freeform.npt)
     548             :             {
     549             :                 hdo->u.freeform.pt =
     550           0 :                     ::comphelper::newArray_null<ZZPoint>(hdo->u.freeform.npt);
     551           0 :                 if (hdo->u.freeform.pt == NULL)
     552             :                 {
     553           0 :                     hdo->u.freeform.npt = 0;
     554           0 :                     return OBJRET_FILE_ERROR;
     555             :                 }
     556           0 :                 for (int ii = 0; ii < hdo->u.freeform.npt; ii++)
     557             :                 {
     558           0 :                     hdo->u.freeform.pt[ii].x = hmem->read4b();
     559           0 :                     hdo->u.freeform.pt[ii].y = hmem->read4b();
     560           0 :                     if (hmem->state())
     561             :                     {
     562           0 :                         delete[]hdo->u.freeform.pt;
     563           0 :                         hdo->u.freeform.npt = 0;
     564           0 :                         return OBJRET_FILE_ERROR;
     565             :                     }
     566             :                 }
     567             :             }
     568           0 :             if (!SkipUnusedField())
     569           0 :                 return OBJRET_FILE_ERROR;
     570           0 :             return OBJRET_FILE_OK;
     571             :         }
     572             :         case OBJFUNC_FREE:
     573           0 :             if (hdo->u.freeform.pt)
     574           0 :                 delete[]hdo->u.freeform.pt;
     575           0 :             break;
     576             :         default:
     577           0 :             return HWPDODefaultFunc(type, hdo, cmd, argp, argv);
     578             :     }
     579           0 :     return true;
     580             : }
     581             : 
     582             : 
     583             : // text box
     584             : 
     585           0 : static void FreeParaList(HWPPara * para)
     586             : {
     587           0 :     if (para->Next())
     588           0 :         FreeParaList(para->Next());
     589           0 :     delete para;
     590           0 : }
     591             : 
     592             : 
     593           0 : static HWPPara *LoadParaList()
     594             : {
     595           0 :     if (!hmem)
     596           0 :         return 0;
     597             : 
     598           0 :     HWPFile *hwpf = GetCurrentDoc();
     599           0 :     HIODev *hio = hwpf->SetIODevice(hmem);
     600             : 
     601           0 :     std::list < HWPPara* > plist;
     602             : 
     603           0 :     hwpf->ReadParaList(plist);
     604           0 :     hwpf->SetIODevice(hio);
     605             : 
     606           0 :     return plist.size()? plist.front() : 0;
     607             : }
     608             : 
     609             : 
     610             : static int
     611           0 : HWPDOTextBoxFunc(int type, HWPDrawingObject * hdo,
     612             : int cmd, void *argp, int argv)
     613             : {
     614           0 :     switch (cmd)
     615             :     {
     616             :         case OBJFUNC_LOAD:
     617           0 :             if (ReadSizeField(0) < 0 || !SkipUnusedField())
     618           0 :                 return OBJRET_FILE_ERROR;
     619           0 :             if (ReadSizeField(0) < 0)
     620           0 :                 return OBJRET_FILE_ERROR;
     621           0 :             hdo->u.textbox.h = LoadParaList();
     622           0 :             return hdo->u.textbox.h ? OBJRET_FILE_OK : OBJRET_FILE_ERROR;
     623             :         case OBJFUNC_FREE:
     624           0 :             if (hdo->u.textbox.h)
     625             :             {
     626           0 :                 FreeParaList(hdo->u.textbox.h);
     627           0 :                 hdo->u.textbox.h = NULL;
     628             :             }
     629           0 :             break;
     630             :         default:
     631           0 :             return HWPDODefaultFunc(type, hdo, cmd, argp, argv);
     632             :     }
     633           0 :     return true;
     634             : }
     635             : 
     636             : 
     637             : 
     638             : static int
     639           0 : HWPDOContainerFunc(int type, HWPDrawingObject * hdo,
     640             : int cmd, void *argp, int argv)
     641             : {
     642           0 :     return HWPDODefaultFunc(type, hdo, cmd, argp, argv);
     643             : }
     644             : 
     645             : 
     646           0 : HWPDrawingObject::HWPDrawingObject()
     647             : {
     648           0 :     memset(this, 0, sizeof(HWPDrawingObject));
     649           0 :     index = ++count;
     650           0 : }
     651             : 
     652             : 
     653           0 : HWPDrawingObject::~HWPDrawingObject()
     654             : {
     655           0 :     if (child)
     656           0 :         delete child;
     657             : 
     658           0 :     if (next)
     659           0 :         delete next;
     660             : 
     661           0 :     HWPDOFunc(this, OBJFUNC_FREE, NULL, 0);
     662           0 : }
     663             : #endif
     664             : 
     665             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10