summaryrefslogtreecommitdiff
path: root/addons/web_editor/controllers
diff options
context:
space:
mode:
authorNicolas Lempereur <nle@odoo.com>2015-11-13 16:57:40 +0100
committerNicolas Lempereur <nle@odoo.com>2016-01-06 15:31:03 +0100
commitdccecaf11f575db1f9b58ee1df334cd89bdd8479 (patch)
treeb0550447f69466aad1d099713d26f69d35f10438 /addons/web_editor/controllers
parente6c35bc4de034fe420c8b6d3d602464210d52201 (diff)
[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
Diffstat (limited to 'addons/web_editor/controllers')
-rw-r--r--addons/web_editor/controllers/main.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/addons/web_editor/controllers/main.py b/addons/web_editor/controllers/main.py
index 24fb6064dcb..bd4fd66bcb8 100644
--- a/addons/web_editor/controllers/main.py
+++ b/addons/web_editor/controllers/main.py
@@ -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)