Exemple #1
0
def get_flattened_path(obj, trafo, tolerance=0.5):
    if obj.cache_paths is None:
        obj.update()
    if obj.cache_paths is None:
        return None
    paths = apply_trafo_to_paths(obj.cache_paths, trafo)
    return flat_paths(paths, tolerance)
Exemple #2
0
def get_flattened_path(obj, trafo, tolerance=0.5):
    if obj.cache_paths is None:
        obj.update()
    if obj.cache_paths is None:
        return None
    paths = apply_trafo_to_paths(obj.cache_paths, trafo)
    return flat_paths(paths, tolerance)
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
Exemple #4
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
Exemple #5
0
def get_flattened_paths(curve_obj, trafo=NORMAL_TRAFO, tolerance=0.1):
    paths = flat_paths(curve_obj.paths, tolerance)
    paths = apply_trafo_to_paths(paths, curve_obj.trafo)
    if trafo != NORMAL_TRAFO:
        paths = apply_trafo_to_paths(paths, trafo)
    return paths