%% options copyright owner = Dirk Krause copyright year = 2018-xxxx SPDX-License-Identifier: BSD-3-Clause %% header /** @file wxdobj.h Drawing objects initialization. */ #ifndef WXDTYPES_H_INCLUDED #include "wxdtypes.h" #endif #ifndef WXD2LAT_H_INCLUDED #include "wxd2lat.h" #endif #ifdef __cplusplus extern "C" { #endif /** Initialize drawing object. @param optr Drawing object to initialize. @param ot Object type. */ void wxd2lat_object_initialize(wxd_object_t *optr, int8_t ot); /** Allocate memory for a new object and initialize it. @param ot Object type. @return Pointer to new object on success, NULL on error (not enough memory). */ wxd_object_t * wxd2lat_object_new(int8_t ot); /** Delete one drawing object, release resources. @param obj Object to delete. */ void wxd2lat_object_delete(wxd_object_t *obj); /** Get object line width. @param pobj Object to find line width for. @param pdrw Drawing structure. @param pjob Job structure. @return Object line width in bp. */ double wxd2lat_object_linewidth( wxd_object_t *pobj, wxd_drawing_t *pdrw, wxd2lat_job_t *pjob ); #ifdef __cplusplus } #endif %% module #include "wxd2lat.h" $!trace-include void wxd2lat_object_delete(wxd_object_t *obj) { $? "+ wxd_object_delete" if (NULL != obj) { $? ". lineno = %lu", (unsigned long)(obj->lino) switch (obj->ot) { case WXD_OT_TEXT : { $? ". text" $? ". export text = \"%!8s\"", TR_8STR(obj->det.t.t) $? ". screen text = \"%!8s\"", TR_8STR(obj->det.t.tsc) $? ". x = %g", obj->det.t.x $? ". y = %g", obj->det.t.y $? ". a = %g", obj->det.t.a $? ". f = %u", (unsigned)(obj->det.t.find) $? ". sz = %u", (unsigned)(obj->det.t.fsz) dk4mem_release(obj->det.t.t); dk4mem_release(obj->det.t.tsc); } break; case WXD_OT_POLYLINE : { $? ". polyline" #if TRACE_DEBUG $? ". points %u", (unsigned)(obj->det.p.n) { uint16_t i; for (i = 0; i < obj->det.p.n; i++) { $? ". x = %g", (obj->det.p.p)[i].x $? ". y = %g", (obj->det.p.p)[i].y } } #endif dk4mem_release(obj->det.p.p); } break; case WXD_OT_O_SPLINE : { $? ". spline" #if TRACE_DEBUG $? ". points %u", (unsigned)(obj->det.s.n) { uint16_t i; for (i = 0; i < obj->det.s.n; i++) { $? ". x = %g", (obj->det.s.p)[i].x $? ". y = %g", (obj->det.s.p)[i].y $? ". s = %g", (obj->det.s.p)[i].s } } #endif dk4mem_release(obj->det.s.p); dk4mem_release(obj->det.s.sl); } break; case WXD_OT_O_ARC : { $? ". arc" /* No dynamic components */ #if TRACE_DEBUG $? ". x = %ld", (long)(obj->det.a.x) $? ". y = %ld", (long)(obj->det.a.y) $? ". r = %lu", (unsigned long)(obj->det.a.r) $? ". a = %lg", obj->det.a.a $? ". b = %lg", obj->det.a.b #endif } break; case WXD_OT_POLYGON : { $? ". polygon" #if TRACE_DEBUG $? ". points %u", (unsigned)(obj->det.p.n) { uint16_t i; for (i = 0; i < obj->det.p.n; i++) { $? ". x = %g", (obj->det.p.p)[i].x $? ". y = %g", (obj->det.p.p)[i].y } } #endif dk4mem_release(obj->det.p.p); } break; case WXD_OT_C_SPLINE : { $? ". c spline" #if TRACE_DEBUG $? ". points %u", (unsigned)(obj->det.s.n) { uint16_t i; for (i = 0; i < obj->det.s.n; i++) { $? ". x = %g", (obj->det.s.p)[i].x $? ". y = %g", (obj->det.s.p)[i].y $? ". s = %g", (obj->det.s.p)[i].s } } #endif dk4mem_release(obj->det.s.p); dk4mem_release(obj->det.s.sl); } break; case WXD_OT_C_ARC : { $? ". c arc" #if TRACE_DEBUG $? ". x = %ld", (long)(obj->det.a.x) $? ". y = %ld", (long)(obj->det.a.y) $? ". r = %lu", (unsigned long)(obj->det.a.r) $? ". a = %lg", obj->det.a.a $? ". b = %lg", obj->det.a.b #endif /* No dynamic components */ } break; case WXD_OT_CIRCLE : { $? ". circle" #if TRACE_DEBUG $? ". x = %ld", (long)(obj->det.a.x) $? ". y = %ld", (long)(obj->det.a.y) $? ". r = %lu", (unsigned long)(obj->det.a.r) #endif /* No dynamic components */ } break; case WXD_OT_ELLIPSE : { $? ". ellipse" #if TRACE_DEBUG $? ". x = %g", obj->det.e.x $? ". y = %g", obj->det.e.y $? ". r = %g", obj->det.e.rx $? ". r = %g", obj->det.e.ry $? ". a = %g", obj->det.e.a #endif /* No dynamic components */ } break; case WXD_OT_BOX : { $? ". box" #if TRACE_DEBUG $? ". xl = %g", obj->det.b.xl $? ". xr = %g", obj->det.b.xr $? ". yb = %g", obj->det.b.yb $? ". yt = %g", obj->det.b.yt #endif /* No dynamic components */ } break; case WXD_OT_IMAGE : { $? ". image" #if TRACE_DEBUG $? ". fn = \"%!8s\"", TR_8STR(obj->det.i.fn) $? ". x = %g", obj->det.i.x $? ". y = %g", obj->det.i.y $? ". w = %g", obj->det.i.w $? ". h = %g", obj->det.i.h $? ". fl = %u", (unsigned)(obj->det.i.fl) #endif dk4mem_release(obj->det.i.fn); } break; case WXD_OT_DOT_FILLED : { $? ". dot filled" #if TRACE_DEBUG $? ". x = %g", obj->det.d.x $? ". y = %g", obj->det.d.y $? ". r = %g", obj->det.d.d $? ". l = %g", obj->lw #endif /* No dynamic components */ } break; case WXD_OT_DOT_WHITE : { $? ". dot white" #if TRACE_DEBUG $? ". x = %g", obj->det.d.x $? ". y = %g", obj->det.d.y $? ". r = %g", obj->det.d.d $? ". l = %g", obj->lw #endif /* No dynamic components */ } break; } dk4mem_free(obj); } $? "- wxd_object_delete" } void wxd2lat_object_initialize(wxd_object_t *optr, int8_t ot) { if (NULL != optr) { DK4_MEMRES(optr,sizeof(wxd_object_t)); optr->lay = 0; optr->lw = 0.0; optr->fc[0] = optr->fc[1] = optr->fc[2] = 255U; optr->sc[0] = optr->sc[1] = optr->sc[2] = 0U; if (WXD_OC_CLOSED == wxd2lat_object_category(ot)) { optr->csfs = WXD_FS_PURE; } else { optr->csfs = WXD_LC_BUTTED; } optr->ls = WXD_LS_SOLID; optr->sl = 1U; optr->js = WXD_LJ_MITERED; optr->ml = 8U; $? ". ml = 8" optr->af.type = 0U; optr->af.length = 0U; optr->af.width = 0U; optr->af.offset = 0.0; optr->af.cut = 0.0; optr->af.cuttol = 0.0; optr->ab.type = 0U; optr->ab.length = 0U; optr->ab.width = 0U; optr->ab.offset = 0.0; optr->ab.cut = 0.0; optr->ab.cuttol = 0.0; optr->ot = ot; switch (ot) { case WXD_OT_GROUP_BEGIN : { /* Empty by intension */ } break; case WXD_OT_TEXT : { optr->det.t.t = NULL; optr->det.t.tsc = NULL; optr->det.t.a = 0.0; optr->det.t.x = 0.0; optr->det.t.y = 0.0; optr->det.t.fsz = 0.0; optr->det.t.find = 0U; optr->det.t.al = 0U; optr->det.t.fl = 0U; } break; case WXD_OT_POLYLINE : case WXD_OT_POLYGON : { optr->det.p.p = NULL; optr->det.p.n = 0U; } break; case WXD_OT_O_SPLINE : case WXD_OT_C_SPLINE : { optr->det.s.p = NULL; optr->det.s.sl = NULL; optr->det.s.suml = -1.0; optr->det.s.n = 0U; optr->det.s.ts = 0.0; optr->det.s.te = 0.0; } break; case WXD_OT_O_ARC : case WXD_OT_C_ARC : { optr->det.a.a = 0.0; optr->det.a.b = 0.0; optr->det.a.x = 0L; optr->det.a.y = 0L; optr->det.a.r = 0UL; } break; case WXD_OT_CIRCLE : case WXD_OT_ELLIPSE : { optr->det.e.a = 0.0; optr->det.e.x = 0.0; optr->det.e.y = 0.0; optr->det.e.rx = 0.0; optr->det.e.ry = 0.0; } break; case WXD_OT_BOX : { optr->det.b.xl = 0.0; optr->det.b.xr = 0.0; optr->det.b.yb = 0.0; optr->det.b.yt = 0.0; optr->det.b.r = -1.0; } break; case WXD_OT_IMAGE : { optr->det.i.fn = NULL; optr->det.i.x = 0.0; optr->det.i.y = 0.0; optr->det.i.w = 0.0; optr->det.i.h = 0.0; optr->det.i.fl = 0U; optr->det.i.r2g = -1L; } break; } } } wxd_object_t * wxd2lat_object_new(int8_t ot) { wxd_object_t *back = NULL; back = dk4mem_new(wxd_object_t,1,NULL); if (NULL != back) { wxd2lat_object_initialize(back, ot); } return back; } double wxd2lat_object_linewidth( wxd_object_t *pobj, wxd_drawing_t *pdrw, wxd2lat_job_t *pjob ) { double back = 0.45; if ((NULL != pjob) && (0.0 < pjob->baselw)) { back = pjob->baselw; } else { if ( (NULL != pdrw) && (0.0 < pdrw->baselw) ) { back = pdrw->baselw; } } back = back * pobj->lw; return back; } /* vim: set ai sw=4 ts=4 : */