コード例 #1
0
def get_path_length(path, tolerance=0.5):
    fpath = flat_path(path, tolerance)
    ret = 0
    start = fpath[0]
    for item in fpath[1]:
        ret += distance(start, item)
        start = item
    return ret
コード例 #2
0
def set_text_on_path(path_obj, text_obj, data):
    curve = path_obj.to_curve()
    path = apply_trafo_to_paths(curve.paths, curve.trafo)[0]
    if data[2]:
        path = reverse_path(path)
    fpath = flat_path(path)
    fpath_len = get_path_length(fpath)

    pos_dict = {}
    xmin = xmax = 0
    index = 0
    for item in text_obj.cache_layout_data:
        if index < len(text_obj.cache_cpath) and \
                text_obj.cache_cpath[index]:
            x = item[0]
            y = item[4]
            xmin = min(xmin, x)
            xmax = max(xmax, x + item[2])
            pos_dict[index] = (x, y)
        index += 1
    text_len = abs(xmax - xmin)

    text_shift = fpath_len * data[0]
    strech = 1.0
    if data[1] == TEXT_ALIGN_CENTER:
        text_shift -= text_len / 2.0
    elif data[1] == TEXT_ALIGN_RIGHT:
        text_shift -= text_len
    elif data[1] == TEXT_ALIGN_JUSTIFY:
        text_shift = 0.0
        strech = fpath_len / text_len

    sx = 0.0 - xmin + text_shift

    trafos = {}
    for index in pos_dict.keys():
        x, y = pos_dict[index]
        shift = text_obj.cache_layout_data[index][2] / 2.0
        point, angle = _get_point_on_path(fpath, (x + sx + shift) * strech)

        center_x, center_y = x + shift, y
        m21 = math.sin(angle)
        m11 = m22 = math.cos(angle)
        m12 = -m21
        dx = center_x - m11 * center_x + m21 * center_y
        dy = center_y - m21 * center_x - m11 * center_y

        trafos[index] = [
            m11, m21, m12, m22, dx + point[0] - x - shift, dy + point[1] - y
        ]

    text_obj.trafos = trafos
コード例 #3
0
ファイル: bezier_ops.py プロジェクト: meiradarocha/sk1-wx
def get_path_length(path, tolerance=0.5):
    fpath = flat_path(path, tolerance)
    points = [fpath[0], ] + fpath[1]
    if fpath[2] == sk2const.CURVE_CLOSED:
        points += [fpath[0], ]
    ret = 0
    start = []
    for item in points:
        if not start:
            start = item
            continue
        ret += distance(start, item)
        start = item
    return ret
コード例 #4
0
ファイル: bezier_ops.py プロジェクト: sk1project/sk1-wx
def get_path_length(path, tolerance=0.5):
	fpath = flat_path(path, tolerance)
	points = [fpath[0], ] + fpath[1]
	if fpath[2] == sk2_const.CURVE_CLOSED:
		points += [fpath[0], ]
	ret = 0
	start = []
	for item in points:
		if not start:
			start = item
			continue
		ret += distance(start, item)
		start = item
	return ret
コード例 #5
0
ファイル: text_on_path.py プロジェクト: sk1project/sk1-wx
def set_text_on_path(path_obj, text_obj, data):
	curve = path_obj.to_curve()
	path = apply_trafo_to_paths(curve.paths, curve.trafo)[0]
	if data[2]: path = reverse_path(path)
	fpath = flat_path(path)
	fpath_len = get_path_length(fpath)

	pos_dict = {}
	xmin = xmax = 0
	index = 0
	for item in text_obj.cache_layout_data:
		if index < len(text_obj.cache_cpath) and \
		text_obj.cache_cpath[index]:
			x = item[0]
			y = item[4]
			xmin = min(xmin, x)
			xmax = max(xmax, x + item[2])
			pos_dict[index] = (x, y)
		index += 1
	text_len = abs(xmax - xmin)

	text_shift = fpath_len * data[0]
	strech = 1.0
	if data[1] == TEXT_ALIGN_CENTER:
		text_shift -= text_len / 2.0
	elif data[1] == TEXT_ALIGN_RIGHT:
		text_shift -= text_len
	elif data[1] == TEXT_ALIGN_JUSTIFY:
		text_shift = 0.0
		strech = fpath_len / text_len

	sx = 0.0 - xmin + text_shift

	trafos = {}
	for index in pos_dict.keys():
		x, y = pos_dict[index]
		shift = text_obj.cache_layout_data[index][2] / 2.0
		point, angle = _get_point_on_path(fpath, (x + sx + shift) * strech)

		center_x, center_y = x + shift, y
		m21 = math.sin(angle)
		m11 = m22 = math.cos(angle)
		m12 = -m21
		dx = center_x - m11 * center_x + m21 * center_y;
		dy = center_y - m21 * center_x - m11 * center_y;

		trafos[index] = [m11, m21, m12, m22,
						dx + point[0] - x - shift, dy + point[1] - y]

	text_obj.trafos = trafos