[IMP] web_editor: use unicode number for FontAwesome controller

In some non-usual circumstances, using unicode in controllers can lead
to issue. For example on a terminal using C encoding (instead of the
mighty UTF-8) werkzeug might use sys.getfilesystemencoding to encode the
request URL which will fail with UTF-8 inside.

This commit change the URL character of the font awesome controller to
UTF-8, but keep the old way since every sent mail might still use it.

There is the overlap of character 0 to 9 which are overidden in this
commit by unicode code 0 to 9, but these were not used in font-awesome
anyway (or these are not even visible ASCII characters).

closes #9572
This commit is contained in:
Nicolas Lempereur
2016-01-06 15:31:03 +01:00
parent e6c35bc4de
commit dccecaf11f
2 changed files with 8 additions and 4 deletions
+7 -3
View File
@@ -74,9 +74,10 @@ class Web_Editor(http.Controller):
'/web_editor/font_to_img/<icon>/<color>/<int:size>/<int:alpha>',
], type='http', auth="none")
def export_icon_to_png(self, icon, color='#000', size=100, alpha=255, font='/web/static/lib/fontawesome/fonts/fontawesome-webfont.ttf'):
""" This method converts FontAwesom pictograms to Images and is Used only
for mass mailing becuase custom fonts are not supported in mail.
:param icon : character from FontAwesom cheatsheet
""" This method converts an unicode character to an image (using Font
Awesome font by default) and is used only for mass mailing because
custom fonts are not supported in mail.
:param icon : decimal encoding of unicode character
:param color : RGB code of the color
:param size : Pixels in integer
:param alpha : transparency of the image from 0 to 255
@@ -88,6 +89,9 @@ class Web_Editor(http.Controller):
addons_path = http.addons_manifest['web']['addons_path']
font_obj = ImageFont.truetype(addons_path + font, size)
# if received character is not a number, keep old behaviour (icon is character)
icon = unichr(int(icon)) if icon.isdigit() else icon
# Determine the dimensions of the icon
image = Image.new("RGBA", (size, size), color=(0, 0, 0, 0))
draw = ImageDraw.Draw(image)
@@ -107,7 +107,7 @@ var font_to_img = function ($editable) {
});
if (content) {
var color = $font.css("color").replace(/\s/g, '');
var src = _.str.sprintf('/web_editor/font_to_img/%s/%s/'+$font.height(), window.encodeURI(content), window.encodeURI(color));
var src = _.str.sprintf('/web_editor/font_to_img/%s/%s/'+$font.height(), content.charCodeAt(0), window.encodeURI(color));
var $img = $("<img/>").attr("src", src)
.attr("data-class", $font.attr("class"))
.attr("class", $font.attr("class").replace(new RegExp("(^|\\s+)" + icon + "(-[^\\s]+)?", "gi"), '')) // remove inline font-awsome style