4571: RTL support in fan chart
gramps/gui/utilscairo.py:
new file, currently holds just the warpPath() function,
taken from /usr/share/doc/python-cairo/examples/warpedtext.py,
with explanatory docs added.
gramps/gui/widgets/fanchart.py, class FanChartBaseWidget:
draw_text() method:
previous logic using cairo toy text API didn't support CTL text.
It has been removed, and replaced with a call to a new
method, draw_arc_text().
Flagged a subtle Unicode issue in the remaining old code,
for radial-oriented text, with a FIXME, I'll probably fix it
later as a separate issue.
create_map_rect_to_sector() static method:
create a transform to use with gui.utilscairo.warpPath(),
currently used in draw_arc_text().
Following Benny's code review I have annotated the algorithm
and made it hopefully clear, but I guess it could be reworked
into a better form if re-expressed with stacked transforms /
complex numbers / matrices for easier later maintenance.
Meanwhile I have used the same approach as the older code
in the file, good enough for a patch under this feature request.
The only issue remaining from the code review is whether
the create_map_rect_to_sector() function should be moved
to gui.utilscairo; see the bug thread.
svn: r22548
2013-06-21 14:13:40 +00:00
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2001-2007 Donald N. Allingham, Martin Hawlisch
|
|
|
|
# Copyright (C) 2009 Douglas S. Blank
|
|
|
|
# Copyright (C) 2012 Benny Malengier
|
|
|
|
# Copyright (C) 2013 Vassilii Khachaturov
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
2015-08-23 18:42:07 +01:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
4571: RTL support in fan chart
gramps/gui/utilscairo.py:
new file, currently holds just the warpPath() function,
taken from /usr/share/doc/python-cairo/examples/warpedtext.py,
with explanatory docs added.
gramps/gui/widgets/fanchart.py, class FanChartBaseWidget:
draw_text() method:
previous logic using cairo toy text API didn't support CTL text.
It has been removed, and replaced with a call to a new
method, draw_arc_text().
Flagged a subtle Unicode issue in the remaining old code,
for radial-oriented text, with a FIXME, I'll probably fix it
later as a separate issue.
create_map_rect_to_sector() static method:
create a transform to use with gui.utilscairo.warpPath(),
currently used in draw_arc_text().
Following Benny's code review I have annotated the algorithm
and made it hopefully clear, but I guess it could be reworked
into a better form if re-expressed with stacked transforms /
complex numbers / matrices for easier later maintenance.
Meanwhile I have used the same approach as the older code
in the file, good enough for a patch under this feature request.
The only issue remaining from the code review is whether
the create_map_rect_to_sector() function should be moved
to gui.utilscairo; see the bug thread.
svn: r22548
2013-06-21 14:13:40 +00:00
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
2014-08-08 19:29:07 -07:00
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
4571: RTL support in fan chart
gramps/gui/utilscairo.py:
new file, currently holds just the warpPath() function,
taken from /usr/share/doc/python-cairo/examples/warpedtext.py,
with explanatory docs added.
gramps/gui/widgets/fanchart.py, class FanChartBaseWidget:
draw_text() method:
previous logic using cairo toy text API didn't support CTL text.
It has been removed, and replaced with a call to a new
method, draw_arc_text().
Flagged a subtle Unicode issue in the remaining old code,
for radial-oriented text, with a FIXME, I'll probably fix it
later as a separate issue.
create_map_rect_to_sector() static method:
create a transform to use with gui.utilscairo.warpPath(),
currently used in draw_arc_text().
Following Benny's code review I have annotated the algorithm
and made it hopefully clear, but I guess it could be reworked
into a better form if re-expressed with stacked transforms /
complex numbers / matrices for easier later maintenance.
Meanwhile I have used the same approach as the older code
in the file, good enough for a patch under this feature request.
The only issue remaining from the code review is whether
the create_map_rect_to_sector() function should be moved
to gui.utilscairo; see the bug thread.
svn: r22548
2013-06-21 14:13:40 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#from gi.repository import Pango
|
|
|
|
#from gi.repository import GObject
|
|
|
|
#from gi.repository import Gdk
|
|
|
|
#from gi.repository import Gtk
|
|
|
|
#from gi.repository import PangoCairo
|
|
|
|
import cairo
|
|
|
|
#import math
|
|
|
|
#import colorsys
|
2015-03-14 19:11:09 +00:00
|
|
|
#import pickle
|
4571: RTL support in fan chart
gramps/gui/utilscairo.py:
new file, currently holds just the warpPath() function,
taken from /usr/share/doc/python-cairo/examples/warpedtext.py,
with explanatory docs added.
gramps/gui/widgets/fanchart.py, class FanChartBaseWidget:
draw_text() method:
previous logic using cairo toy text API didn't support CTL text.
It has been removed, and replaced with a call to a new
method, draw_arc_text().
Flagged a subtle Unicode issue in the remaining old code,
for radial-oriented text, with a FIXME, I'll probably fix it
later as a separate issue.
create_map_rect_to_sector() static method:
create a transform to use with gui.utilscairo.warpPath(),
currently used in draw_arc_text().
Following Benny's code review I have annotated the algorithm
and made it hopefully clear, but I guess it could be reworked
into a better form if re-expressed with stacked transforms /
complex numbers / matrices for easier later maintenance.
Meanwhile I have used the same approach as the older code
in the file, good enough for a patch under this feature request.
The only issue remaining from the code review is whether
the create_map_rect_to_sector() function should be moved
to gui.utilscairo; see the bug thread.
svn: r22548
2013-06-21 14:13:40 +00:00
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Functions
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def warpPath(ctx, function):
|
|
|
|
"""Transform a path given a 2D transformation function.
|
|
|
|
|
|
|
|
ctx -- a cairo.Context, on which the path is set
|
|
|
|
function -- a 2D transform (x,y) |-> (x_new,y_new)
|
|
|
|
|
|
|
|
The transformed path replaces the original one on the context.
|
|
|
|
|
|
|
|
Taken from /usr/share/doc/python-cairo/examples/warpedtext.py
|
|
|
|
According to /usr/share/doc/python-cairo/copyright, licensed
|
|
|
|
under MOZILLA PUBLIC LICENSE 1.1, see that file for more detail.
|
|
|
|
"""
|
|
|
|
|
|
|
|
first = True
|
|
|
|
|
|
|
|
for type, points in ctx.copy_path():
|
|
|
|
if type == cairo.PATH_MOVE_TO:
|
|
|
|
if first:
|
|
|
|
ctx.new_path()
|
|
|
|
first = False
|
|
|
|
x, y = function(*points)
|
|
|
|
ctx.move_to(x, y)
|
|
|
|
|
|
|
|
elif type == cairo.PATH_LINE_TO:
|
|
|
|
x, y = function(*points)
|
|
|
|
ctx.line_to(x, y)
|
|
|
|
|
|
|
|
elif type == cairo.PATH_CURVE_TO:
|
|
|
|
x1, y1, x2, y2, x3, y3 = points
|
|
|
|
x1, y1 = function(x1, y1)
|
|
|
|
x2, y2 = function(x2, y2)
|
|
|
|
x3, y3 = function(x3, y3)
|
|
|
|
ctx.curve_to(x1, y1, x2, y2, x3, y3)
|
|
|
|
|
|
|
|
elif type == cairo.PATH_CLOSE_PATH:
|
|
|
|
ctx.close_path()
|