Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
bde17bbe
Commit
bde17bbe
authored
Dec 03, 2012
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fit text to widget if it is too big
parent
6f965e3f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
8 deletions
+27
-8
weblate/trans/widgets.py
weblate/trans/widgets.py
+27
-8
No files found.
weblate/trans/widgets.py
View file @
bde17bbe
...
...
@@ -203,6 +203,20 @@ def widgets(request, project):
'form'
:
form
,
}))
def
render_text
(
pangocairo_context
,
line
,
text
,
params
,
font_size
):
'''
Generates Pango layout for text.
'''
# Create pango layout and set font
layout
=
pangocairo_context
.
create_layout
()
font
=
pango
.
FontDescription
(
'%s %d'
%
(
line
[
'font'
],
font_size
))
layout
.
set_font_description
(
font
)
# Add text
layout
.
set_text
(
text
)
return
layout
@
cache_page
(
3600
)
def
render
(
request
,
project
,
widget
=
'287x66'
,
color
=
None
,
lang
=
None
):
obj
=
get_object_or_404
(
Project
,
slug
=
project
)
...
...
@@ -286,16 +300,21 @@ def render(request, project, widget = '287x66', color = None, lang = None):
text
=
text
.
replace
(
'English'
,
lang
.
name
)
text
=
text
%
params
# Create pango layout and set font
layout
=
pangocairo_context
.
create_layout
()
font
=
pango
.
FontDescription
(
'%s %d'
%
(
line
[
'font'
],
line
[
'font_size'
]))
layout
.
set_font_description
(
font
)
font_size
=
line
[
'font_size'
]
#
Set color and position
ctx
.
move_to
(
*
line
[
'pos'
]
)
#
Render text
layout
=
render_text
(
pangocairo_context
,
line
,
text
,
params
,
font_size
)
# Add text
layout
.
set_text
(
text
)
# Fit text to image if it is too big
extent
=
layout
.
get_pixel_extents
()
width
=
surface
.
get_width
()
while
extent
[
1
][
2
]
+
line
[
'pos'
][
0
]
>
width
and
font_size
>
4
:
font_size
-=
1
layout
=
render_text
(
pangocairo_context
,
line
,
text
,
params
,
font_size
)
extent
=
layout
.
get_pixel_extents
()
# Set position
ctx
.
move_to
(
*
line
[
'pos'
])
# Render to cairo context
pangocairo_context
.
update_layout
(
layout
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment