Esempio n. 1
0
def parseText(tmp_line):
    obj_type = 'text'

    # SubType: 0=left justified, 1=center justified, 2=right justified
    subtype = int(tmp_line[1])
    if    subtype == 0: subtype = 'left'
    elif  subtype == 1: subtype = 'center'
    elif  subtype == 2: subtype = 'right'
    else: e.die('subtype %s not supported' % subtype)

    color      = int(tmp_line[2])          # NOT USED
    depth      = int(tmp_line[3]) - 50     # default depth value
    penstyle   = int(tmp_line[4])          # NOT USED
    font       = int(tmp_line[5])          # NOT USED
    font_size  = float(tmp_line[6]) * 12.0 # a magic number
    angle      = float(tmp_line[7])
    font_flags = int(tmp_line[8])          # NOT USED, bit vector

    # text height and length
    height = float(tmp_line[9])
    length = float(tmp_line[10])

    # Position (of text anchor), depends on SubType
    # if SubType = 0 -> position is bottom left corner
    # if SubType = 1 -> position is bottom center
    # if SubType = 2 -> position is bottom right corner
    x, y = int(tmp_line[11]), int(tmp_line[12])

    string = ''
    for i in range(13, len(tmp_line)): string += tmp_line[i] + ' '
    string = string.strip()[:-4]

    if font_size > 1:
        e.avg_fontsize += font_size
        e.num_fontsize += 1

    res = {'type': obj_type,
           # 'depth': depth,
           # 'subtype': subtype,
           # 'align': subtype,
           # 'fontsize': font_size,
           # 'angle': angle,
           # 'height': height,
           # 'length': length,
           'pos': [x, y],
           'string': string}

    if depth   != 0:        res['depth'] = depth
    if angle   != 0.0:      res['angle'] = int(angle * 180 / pi)
    if subtype != 'center': res['align'] = subtype
    return res
Esempio n. 2
0
def parse_object(line):
    tmpl = line.split(' ')

    if tmpl[0] == '#':
        res = parse_object(stdin.readline().strip())
        res['meta'] = tmpl[1]
        return res

    t = int(tmpl[0])

    if t == 2: return parse_polyline(tmpl)  # polyline, polygon, box
    elif t == 4: return parse_text(tmpl)  # text
    elif t == 6:  # compound
        res = {}
        res['type'] = 'compound'
        res['children'] = []
        for l in stdin:
            ls = l.strip()
            if ls == '-6': break  # end of compound
            res['children'] += [parse_object(ls)]
        return res
    else:
        die('type %s not supported' % typ)
Esempio n. 3
0
def parse_polyline(tmp_line):  # polyline, polygon, box
    obj_type = 'polyline'

    # SubType: 1=polyline, 2=box, 3=polygon, 4=arc-box, 5=pic
    subtype = int(tmp_line[1])
    if subtype == 1: subtype = 'polyline'
    elif subtype == 2: subtype = 'box'
    elif subtype == 3: subtype = 'polygon'
    elif subtype == 4: subtype = 'arcbox'
    else: die('subtype %s not supported' % subtype)

    # LineStyle: -1=Default, 0=Solid, 1=Dashed, 2=Dotted, 3=Dash-dotted,
    #            4=Dash-double-dotted, 5=Dash-triple-dotted
    linestyle = int(tmp_line[2])
    if linestyle == -1: linestyle = 'default'
    elif linestyle == 0: linestyle = 'solid'
    else: die('linestyle %s not supported' % linestyle)

    thickness = int(tmp_line[3]) * 12
    if thickness == 0:
        visible = False
    else:
        visible = True

    pencolor = int(tmp_line[4])  # NOT USED
    fillcolor = int(tmp_line[5])  # NOT USED
    depth = int(tmp_line[6])  # USED: 0...999
    penstyle = int(tmp_line[7])  # NOT USED
    areafill = int(tmp_line[8])  # NOT USED, -1=not filled
    styleval = float(tmp_line[9])  # NOT USED

    # JoinStyle: 0=Miter, 1=Round, 2=Bevel
    joinstyle = int(tmp_line[10])  # NOT USED

    # ONLY FOR POLYLINE
    # CapStyle: 0=Butt, 1=Round, 2=Projecting
    capstyle = int(tmp_line[11])  # NOT USED

    # ONLY FOR ARCBOX
    # radius of arc-box
    radius = int(tmp_line[12]) * 12

    # ONLY FOR POLYLINE
    # ForwardArrow, BackwardArrow: 0=off, 1=on
    forwardarrow = bool(int(tmp_line[13]))
    backwardarrow = bool(int(tmp_line[14]))

    # NPoints: number of points in line
    npoints = int(tmp_line[15])  # USED ONLY HERE

    if subtype == 'polyline':
        # ignore arrow details, we'll draw them all the same
        if forwardarrow:
            for l in stdin:  # skip forwardarrow line
                break
        if backwardarrow:
            for l in stdin:  # skip backwardarrow line
                break

    total = 0
    points = []
    for tmp_points_line in stdin:
        points_line = tmp_points_line.strip().split(' ')

        i = 0
        while i < len(points_line):
            x = int(points_line[i])
            y = int(points_line[i + 1])

            points += [[x, y]]

            i += 2
            total += 2

        if (total / 2) == npoints:
            break

    if radius > 0:
        extra.avg_radius += radius
        extra.num_radius += 1

    if thickness > 0:
        extra.avg_thickness += thickness
        extra.num_thickness += 1

    res = {
        'type': subtype,
        # 'type': obj_type,
        # 'subtype': subtype,
        # 'linestyle': linestyle,
        # 'thickness': thickness,
        # 'visible': visible,
        # 'depth': depth,
        # 'radius': radius,
        # 'farrow': forwardarrow,
        # 'barrow': backwardarrow,
        'points': points
    }

    if forwardarrow: res['farrow'] = True
    if backwardarrow: res['barrow'] = True

    return res
Esempio n. 4
0
def parse_text(tmp_line):  # text
    obj_type = 'text'

    # SubType: 0=left justified, 1=center justified, 2=right justified
    subtype = int(tmp_line[1])
    if subtype == 0: subtype = 'left'
    elif subtype == 1: subtype = 'center'
    elif subtype == 2: subtype = 'right'
    else: die('subtype %s not supported' % subtype)

    color = int(tmp_line[2])

    depth = int(tmp_line[3])  # NOT USED: 0...999
    penstyle = int(tmp_line[4])  # NOT USED
    font = int(tmp_line[5])  # NOT USED
    font_size = float(tmp_line[6]) * 12.0
    angle = float(tmp_line[7])
    font_flags = int(tmp_line[8])  # NOT USED, bit vector

    # text height and length
    height = float(tmp_line[9])
    length = float(tmp_line[10])

    # Position (of text anchor), depends on SubType
    # if SubType = 0 -> position is bottom left corner
    # if SubType = 1 -> position is bottom center
    # if SubType = 2 -> position is bottom right corner
    x = int(tmp_line[11])
    y = int(tmp_line[12])

    string = ''
    i = 13
    while i < len(tmp_line):
        string += tmp_line[i] + ' '
        i += 1
    string = string.strip()[:-4]

    if font_size > 1:
        extra.avg_fontsize += font_size
        extra.num_fontsize += 1

    res = {
        'type': obj_type,
        # 'subtype': subtype,
        # 'align': subtype,
        # 'depth': depth,
        # 'fontsize': font_size,
        # 'angle': angle,
        # 'height': height,
        # 'length': length,
        'pos': [x, y],
        'string': string
    }

    if angle != 0.0:
        angle = int(angle * 180 / pi)
        res['angle'] = angle

    if subtype != 'center': res['align'] = subtype

    return res