src/shape_path.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <cairo.h>
#include "mb_types.h"
#include "mb_redraw_man.h"
#include <math.h>

Go to the source code of this file.

Classes

struct  _sh_path
 Implement respective objects for SVG path tag. More...

Defines

#define RESERVED_AIXS   sizeof(co_aix[2])
#define ASSERT(x)
#define SKIP_SPACE(x)   while(*(x) && (isspace(*(x)) || *(x) == ',')) { (x)++; }
#define SKIP_NUM(x)
#define OK   0
#define ERR   -1
#define PI   3.1415926
#define TAKE_NUM(r)
#define INNER(x1, y1, x2, y2)   ((x1) * (x2) + (y1) * (y2))
#define CROSS(x1, y1, x2, y2)   ((x1) * (y2) - (y1) * (x2))
#define TO_ABSX   islower(cmd)? x + atof(old): atof(old)
#define TO_ABSY   islower(cmd)? y + atof(old): atof(old)

Typedefs

typedef struct _sh_path sh_path_t
 Implement respective objects for SVG path tag.

Functions

static int calc_center_and_x_aix (co_aix x0, co_aix y0, co_aix x, co_aix y, co_aix rx, co_aix ry, co_aix x_rotate, int large, int sweep, co_aix *cx, co_aix *cy, co_aix *xx, co_aix *xy)
 Calculate center of the ellipse of an arc.
static int sh_path_arc_cmd_arg_fill (char cmd, char **cmds_p, const char **data_p, co_aix **args_p, int **fix_args_p)
void sh_path_arc_path (cairo_t *cr, const co_aix **args_p, const int **fix_args_p)
 Make path for arcs in a path.
static void sh_path_free (shape_t *shape)
static int sh_path_cmd_arg_cnt (char *data, int *cmd_cntp, int *arg_cntp, int *fix_arg_cntp)
 Count number of arguments.
static int sh_path_cmd_arg_fill (char *data, sh_path_t *path)
shape_trdman_shape_path_new (redraw_man_t *rdman, char *data)
 Create a path from value of 'data' of SVG path.
void sh_path_transform (shape_t *shape)
 Transform a path from user space to device space.
static void sh_path_path (shape_t *shape, cairo_t *cr)
void sh_path_draw (shape_t *shape, cairo_t *cr)


Define Documentation

#define ASSERT (  ) 

Definition at line 29 of file shape_path.c.

#define CROSS ( x1,
y1,
x2,
y2   )     ((x1) * (y2) - (y1) * (x2))

Definition at line 220 of file shape_path.c.

#define ERR   -1

Definition at line 42 of file shape_path.c.

#define INNER ( x1,
y1,
x2,
y2   )     ((x1) * (x2) + (y1) * (y2))

Definition at line 219 of file shape_path.c.

#define OK   0

Definition at line 41 of file shape_path.c.

#define PI   3.1415926

Definition at line 43 of file shape_path.c.

#define RESERVED_AIXS   sizeof(co_aix[2])

Definition at line 27 of file shape_path.c.

#define SKIP_NUM (  ) 

Value:

while(*(x) &&                                   \
          (isdigit(*(x)) ||                             \
           *(x) == 'e' ||                               \
           *(x) == 'E' ||                               \
           *(x) == '-' ||                               \
           *(x) == '+' ||                               \
           *(x) == '.'))  {                                     \
        (x)++;                                          \
    }

Definition at line 31 of file shape_path.c.

#define SKIP_SPACE (  )     while(*(x) && (isspace(*(x)) || *(x) == ',')) { (x)++; }

Definition at line 30 of file shape_path.c.

#define TAKE_NUM (  ) 

Value:

do {                    \
        SKIP_SPACE(p);                          \
        old = p;                                \
        SKIP_NUM(p);                            \
        if(p == old)                            \
            return ERR;                         \
        r = atof(old);                          \
    } while(0);

Definition at line 146 of file shape_path.c.

#define TO_ABSX   islower(cmd)? x + atof(old): atof(old)

Definition at line 487 of file shape_path.c.

#define TO_ABSY   islower(cmd)? y + atof(old): atof(old)

Definition at line 488 of file shape_path.c.


Typedef Documentation

typedef struct _sh_path sh_path_t

Implement respective objects for SVG path tag.

In user_data or dev_data, 0x00 bytes are padding after commands. No commands other than 0x00 can resident after 0x00 itself. It means command processing code can skip commands after a 0x00.

Shapes should check if shape_t::geo is assigned. Once transformation matrics are changed, shape objects should update shape_t::geo if it is assigned.


Function Documentation

static int calc_center_and_x_aix ( co_aix  x0,
co_aix  y0,
co_aix  x,
co_aix  y,
co_aix  rx,
co_aix  ry,
co_aix  x_rotate,
int  large,
int  sweep,
co_aix cx,
co_aix cy,
co_aix xx,
co_aix xy 
) [static]

Calculate center of the ellipse of an arc.

  • ux0 = x0 / rx
  • uy0 = y0 / ry
  • ux = x / rx
  • uy = y / rx ux0, uy0, ux, yu are got by transforming (x0, y0) and (x, y) into points on the unit circle. The center of unit circle are (ucx, ucy):
  • umx = (ux0 + ux) / 2
  • umy = (uy0 + uy) / 2
  • udcx = ucx - umx
  • udcy = ucy - umy
  • udx = ux - umx
  • udy = uy - umy

  • udx * udcx + udy * udcy = 0

  • udl2 = udx ** 2 + udy ** 2;
  • udx * udcy - udy * udcx = sqrt((1 - udl2) * udl2)

  • udcy = -udcx * udx / udy
  • -udcx * (udx ** 2) / udy - udy * udcx = sqrt((1 - udl2) * udl2)
  • -udcx * ((udx ** 2) / udy + udy) = sqrt((1 - udl2) * udl2)
  • udcx = -sqrt((1 - udl2) * udl2) / ((udx ** 2) / udy + udy) or
  • udcx = -udcy * udy / udx
  • udx * udcy + udcy * (udy ** 2) / udx = sqrt((1 - udl2) * udl2)
  • udcy * (udx + (udy ** 2) / udx) = sqrt((1 - udl2) * udl2)
  • udcy = sqrt((1 - udl2) * udl2) / (udx + (udy ** 2) / udx)

  • cx = rx * ucx
  • cx = rx * (udcx + umx)
  • cy = ry * ucy
  • cy = ry * (udcy + umy)

Definition at line 84 of file shape_path.c.

static int sh_path_arc_cmd_arg_fill ( char  cmd,
char **  cmds_p,
const char **  data_p,
co_aix **  args_p,
int **  fix_args_p 
) [static]

Definition at line 155 of file shape_path.c.

void sh_path_arc_path ( cairo_t *  cr,
const co_aix **  args_p,
const int **  fix_args_p 
)

Make path for arcs in a path.

Note:
Why we calculate these numbers there? If we compute it when filling arguments, sh_path_arc_cmd_arg_fill(), we can avoid to recompute it for every drawing. But, transforming of coordinate can effect value of the numbers.

Definition at line 224 of file shape_path.c.

static int sh_path_cmd_arg_cnt ( char *  data,
int *  cmd_cntp,
int *  arg_cntp,
int *  fix_arg_cntp 
) [static]

Count number of arguments.

Todo:
Notify programmers that syntax or value error of path data.

Todo:
cmd_cnt should be increased for each implicit repeating.

Definition at line 311 of file shape_path.c.

static int sh_path_cmd_arg_fill ( char *  data,
sh_path_t path 
) [static]

Todo:
implement h, H, v, V comamnds for path.

Definition at line 490 of file shape_path.c.

static void sh_path_free ( shape_t shape  )  [static]

Definition at line 300 of file shape_path.c.

static void sh_path_path ( shape_t shape,
cairo_t *  cr 
) [static]

Definition at line 752 of file shape_path.c.

SourceForge.net Logo