Commit f64a6d22 authored by Weblate's avatar Weblate

Merge remote-tracking branch 'origin/master'

parents 01c3ace6 faea4917
......@@ -2,6 +2,9 @@
branch = True
omit =
*migrations*
settings_*
jenkins_cleanup*
wsgi*
[paths]
source = .
......
......@@ -24,12 +24,12 @@ before_install:
- sudo apt-get install git libcairo2-dev libgtk2.0-dev libglib2.0-dev libtool libpango1.0-dev libatk1.0-dev libffi-dev libpq-dev libmysqlclient-dev
# commands to install dependencies
install:
- pip install --use-mirrors Django==$DJANGO_VERSION
- pip install --use-mirrors -r requirements.txt
- pip install --use-mirrors mysql-python psycopg2
- pip install --use-mirrors pep8
- pip install --use-mirrors coveralls
- if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then pip install --use-mirrors -r requirements-2.6.txt ; fi
- pip install Django==$DJANGO_VERSION
- pip install -r requirements.txt
- pip install mysql-python psycopg2
- pip install pep8
- pip install coveralls
- if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then pip install -r requirements-2.6.txt ; fi
# Environment setup
- export VIRT_ROOT=/home/travis/virtualenv/python$TRAVIS_PYTHON_VERSION
- export PKG_CONFIG_PATH=$VIRT_ROOT/lib/pkgconfig
......
......@@ -345,6 +345,13 @@ SITE_TITLE
Site title to be used in website and emails as well.
.. setting:: TTF_FONT
TTF_FONT
--------
TrueType font to be used for widgets and charts.
.. setting:: WHOOSH_INDEX
WHOOSH_INDEX
......
......@@ -22,6 +22,8 @@ Whoosh
http://bitbucket.org/mchaput/whoosh/
PyCairo
http://cairographics.org/pycairo/
PIL or Pillow library
http://python-imaging.github.io/
PyGtk
http://www.pygtk.org/
south
......
......@@ -5,3 +5,4 @@ django-registration==0.8
Whoosh>=2.3
Translate-Toolkit>=1.10.0
lxml>=3.1.0
Pillow
......@@ -19,6 +19,8 @@
#
from distutils.version import LooseVersion
import importlib
def get_version_module(module, name, url, optional=False):
......@@ -27,7 +29,7 @@ def get_version_module(module, name, url, optional=False):
exception with name and URL.
'''
try:
mod = __import__(module)
mod = importlib.import_module(module)
except ImportError:
if optional:
return None
......@@ -173,6 +175,16 @@ def get_versions():
'0.7',
))
name = 'Pillow (PIL)'
url = 'http://python-imaging.github.io/'
mod = get_version_module('PIL.Image', name, url)
result.append((
name,
url,
mod.VERSION,
'1.1.6',
))
return result
......
......@@ -24,16 +24,14 @@ Charting library for Weblate.
from trans.models import Change
from lang.models import Language
from trans.views.helper import get_project_translation
from weblate import appsettings
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.http import HttpResponse
from django.contrib.auth.models import User
from cStringIO import StringIO
from django.core.urlresolvers import reverse
import cairo
import pango
import pangocairo
import math
from PIL import Image, ImageDraw, ImageFont
def render_activity(activity):
......@@ -45,48 +43,24 @@ def render_activity(activity):
step = 780.0 / len(activity)
width = step / 2
# Prepare cairo surface and context
surface = cairo.ImageSurface(cairo.FORMAT_RGB24, 800, 100)
ctx = cairo.Context(surface)
# Render background
ctx.set_source_rgb(1, 1, 1)
ctx.rectangle(0, 0, 800, 100)
ctx.fill()
# Prepare image
image = Image.new('RGB', (800, 100), 'white')
draw = ImageDraw.Draw(image)
# Render axises
ctx.new_path()
ctx.set_line_width(1)
ctx.set_source_rgb(0, 0, 0)
ctx.move_to(15, 5)
ctx.line_to(15, 85)
ctx.line_to(795, 85)
ctx.stroke()
# Context for text rendering
pangocairo_context = pangocairo.CairoContext(ctx)
pangocairo_context.set_antialias(cairo.ANTIALIAS_SUBPIXEL)
font = pango.FontDescription('Sans 8')
# Rotate context for vertical text
ctx.rotate(-math.pi / 2)
# Create Y axis label
layout = pangocairo_context.create_layout()
layout.set_width(80)
layout.set_alignment(pango.ALIGN_RIGHT)
layout.set_font_description(font)
layout.set_text(str(maximum))
draw.line(((15, 5), (15, 85), (795, 85)), fill='black')
# Render Y axis label
ctx.move_to(-5, 0)
ctx.set_source_rgb(0, 0, 0)
pangocairo_context.update_layout(layout)
pangocairo_context.show_layout(layout)
# Load font
font = ImageFont.truetype(appsettings.TTF_FONT, 11)
# Rotate context back
ctx.rotate(math.pi / 2)
# Create Y axis label
y_label = str(maximum)
text = Image.new('L', font.getsize(y_label), 'white')
draw_txt = ImageDraw.Draw(text)
draw_txt.text((0, 0), y_label, font=font, fill='black')
text = text.transpose(Image.ROTATE_90)
image.paste(text, (2, 5))
# Counter for rendering ticks
last = -40
......@@ -96,35 +70,31 @@ def render_activity(activity):
current = offset * step
# Render bar
ctx.new_path()
ctx.set_source_rgb(0, 67.0 / 255, 118.0 / 255)
ctx.rectangle(
draw.rectangle(
(
20 + current,
84,
width,
- 1.0 - value[1] * 78.0 / maximum
20 + current + width,
84 - value[1] * 78.0 / maximum
),
fill=(0, 67, 118)
)
ctx.fill()
# Skip axis labels if they are too frequent
if current < last + 40:
continue
last = current
# Create text
layout = pangocairo_context.create_layout()
layout.set_font_description(font)
layout.set_text(value[0].strftime('%m/%d'))
# Render text
ctx.move_to(15 + current, 86)
ctx.set_source_rgb(0, 0, 0)
pangocairo_context.update_layout(layout)
pangocairo_context.show_layout(layout)
# X-Axis ticks
draw.text(
(15 + current, 86),
value[0].strftime('%m/%d'),
font=font, fill='black'
)
# Render surface to PNG
out = StringIO()
surface.write_to_png(out)
image.save(out, 'PNG')
# Return response
return HttpResponse(content_type='image/png', content=out.getvalue())
......
......@@ -139,3 +139,6 @@ PRE_COMMIT_SCRIPTS = get('PRE_COMMIT_SCRIPTS', ())
SCRIPT_CHOICES = [
(script, get_script_name(script)) for script in PRE_COMMIT_SCRIPTS
] + [('', '')]
# Font for charts and widgets
TTF_FONT = get('TTF_FONT', os.path.join(WEB_ROOT, 'ttf', 'DejaVuSans.ttf'))
Fonts are (c) Bitstream (see below). DejaVu changes are in public domain.
Glyphs imported from Arev fonts are (c) Tavmjong Bah (see below)
Bitstream Vera Fonts Copyright
------------------------------
Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera is
a trademark of Bitstream, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of the fonts accompanying this license ("Fonts") and associated
documentation files (the "Font Software"), to reproduce and distribute the
Font Software, including without limitation the rights to use, copy, merge,
publish, distribute, and/or sell copies of the Font Software, and to permit
persons to whom the Font Software is furnished to do so, subject to the
following conditions:
The above copyright and trademark notices and this permission notice shall
be included in all copies of one or more of the Font Software typefaces.
The Font Software may be modified, altered, or added to, and in particular
the designs of glyphs or characters in the Fonts may be modified and
additional glyphs or characters may be added to the Fonts, only if the fonts
are renamed to names not containing either the words "Bitstream" or the word
"Vera".
This License becomes null and void to the extent applicable to Fonts or Font
Software that has been modified and is distributed under the "Bitstream
Vera" names.
The Font Software may be sold as part of a larger software package but no
copy of one or more of the Font Software typefaces may be sold by itself.
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME
FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING
ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE
FONT SOFTWARE.
Except as contained in this notice, the names of Gnome, the Gnome
Foundation, and Bitstream Inc., shall not be used in advertising or
otherwise to promote the sale, use or other dealings in this Font Software
without prior written authorization from the Gnome Foundation or Bitstream
Inc., respectively. For further information, contact: fonts at gnome dot
org.
Arev Fonts Copyright
------------------------------
Copyright (c) 2006 by Tavmjong Bah. All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining
a copy of the fonts accompanying this license ("Fonts") and
associated documentation files (the "Font Software"), to reproduce
and distribute the modifications to the Bitstream Vera Font Software,
including without limitation the rights to use, copy, merge, publish,
distribute, and/or sell copies of the Font Software, and to permit
persons to whom the Font Software is furnished to do so, subject to
the following conditions:
The above copyright and trademark notices and this permission notice
shall be included in all copies of one or more of the Font Software
typefaces.
The Font Software may be modified, altered, or added to, and in
particular the designs of glyphs or characters in the Fonts may be
modified and additional glyphs or characters may be added to the
Fonts, only if the fonts are renamed to names not containing either
the words "Tavmjong Bah" or the word "Arev".
This License becomes null and void to the extent applicable to Fonts
or Font Software that has been modified and is distributed under the
"Tavmjong Bah Arev" names.
The Font Software may be sold as part of a larger software package but
no copy of one or more of the Font Software typefaces may be sold by
itself.
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL
TAVMJONG BAH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
Except as contained in this notice, the name of Tavmjong Bah shall not
be used in advertising or otherwise to promote the sale, use or other
dealings in this Font Software without prior written authorization
from Tavmjong Bah. For further information, contact: tavmjong @ free
. fr.
$Id: LICENSE 2133 2007-11-28 02:46:28Z lechimp $
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment