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

Generated by: LCOV version 1.10