##// END OF EJS Templates
add configuration of RMagcik font for CJK (Chinese, Japanese and Korean) (#4787)...
Toshi MARUYAMA -
r10663:c7ee26b14437
parent child
Show More
@@ -1,175 +1,197
1 1 # = Redmine configuration file
2 2 #
3 3 # Each environment has it's own configuration options. If you are only
4 4 # running in production, only the production block needs to be configured.
5 5 # Environment specific configuration options override the default ones.
6 6 #
7 7 # Note that this file needs to be a valid YAML file.
8 8 # DO NOT USE TABS! Use 2 spaces instead of tabs for identation.
9 9 #
10 10 # == Outgoing email settings (email_delivery setting)
11 11 #
12 12 # === Common configurations
13 13 #
14 14 # ==== Sendmail command
15 15 #
16 16 # production:
17 17 # email_delivery:
18 18 # delivery_method: :sendmail
19 19 #
20 20 # ==== Simple SMTP server at localhost
21 21 #
22 22 # production:
23 23 # email_delivery:
24 24 # delivery_method: :smtp
25 25 # smtp_settings:
26 26 # address: "localhost"
27 27 # port: 25
28 28 #
29 29 # ==== SMTP server at example.com using LOGIN authentication and checking HELO for foo.com
30 30 #
31 31 # production:
32 32 # email_delivery:
33 33 # delivery_method: :smtp
34 34 # smtp_settings:
35 35 # address: "example.com"
36 36 # port: 25
37 37 # authentication: :login
38 38 # domain: 'foo.com'
39 39 # user_name: 'myaccount'
40 40 # password: 'password'
41 41 #
42 42 # ==== SMTP server at example.com using PLAIN authentication
43 43 #
44 44 # production:
45 45 # email_delivery:
46 46 # delivery_method: :smtp
47 47 # smtp_settings:
48 48 # address: "example.com"
49 49 # port: 25
50 50 # authentication: :plain
51 51 # domain: 'example.com'
52 52 # user_name: 'myaccount'
53 53 # password: 'password'
54 54 #
55 55 # ==== SMTP server at using TLS (GMail)
56 56 #
57 57 # This might require some additional configuration. See the guides at:
58 58 # http://www.redmine.org/projects/redmine/wiki/EmailConfiguration
59 59 #
60 60 # production:
61 61 # email_delivery:
62 62 # delivery_method: :smtp
63 63 # smtp_settings:
64 64 # enable_starttls_auto: true
65 65 # address: "smtp.gmail.com"
66 66 # port: 587
67 67 # domain: "smtp.gmail.com" # 'your.domain.com' for GoogleApps
68 68 # authentication: :plain
69 69 # user_name: "your_email@gmail.com"
70 70 # password: "your_password"
71 71 #
72 72 #
73 73 # === More configuration options
74 74 #
75 75 # See the "Configuration options" at the following website for a list of the
76 76 # full options allowed:
77 77 #
78 78 # http://wiki.rubyonrails.org/rails/pages/HowToSendEmailsWithActionMailer
79 79
80 80
81 81 # default configuration options for all environments
82 82 default:
83 83 # Outgoing emails configuration (see examples above)
84 84 email_delivery:
85 85 delivery_method: :smtp
86 86 smtp_settings:
87 87 address: smtp.example.net
88 88 port: 25
89 89 domain: example.net
90 90 authentication: :login
91 91 user_name: "redmine@example.net"
92 92 password: "redmine"
93 93
94 94 # Absolute path to the directory where attachments are stored.
95 95 # The default is the 'files' directory in your Redmine instance.
96 96 # Your Redmine instance needs to have write permission on this
97 97 # directory.
98 98 # Examples:
99 99 # attachments_storage_path: /var/redmine/files
100 100 # attachments_storage_path: D:/redmine/files
101 101 attachments_storage_path:
102 102
103 103 # Configuration of the autologin cookie.
104 104 # autologin_cookie_name: the name of the cookie (default: autologin)
105 105 # autologin_cookie_path: the cookie path (default: /)
106 106 # autologin_cookie_secure: true sets the cookie secure flag (default: false)
107 107 autologin_cookie_name:
108 108 autologin_cookie_path:
109 109 autologin_cookie_secure:
110 110
111 111 # Configuration of SCM executable command.
112 112 #
113 113 # Absolute path (e.g. /usr/local/bin/hg) or command name (e.g. hg.exe, bzr.exe)
114 114 # On Windows + CRuby, *.cmd, *.bat (e.g. hg.cmd, bzr.bat) does not work.
115 115 #
116 116 # On Windows + JRuby 1.6.2, path which contains spaces does not work.
117 117 # For example, "C:\Program Files\TortoiseHg\hg.exe".
118 118 # If you want to this feature, you need to install to the path which does not contains spaces.
119 119 # For example, "C:\TortoiseHg\hg.exe".
120 120 #
121 121 # Examples:
122 122 # scm_subversion_command: svn # (default: svn)
123 123 # scm_mercurial_command: C:\Program Files\TortoiseHg\hg.exe # (default: hg)
124 124 # scm_git_command: /usr/local/bin/git # (default: git)
125 125 # scm_cvs_command: cvs # (default: cvs)
126 126 # scm_bazaar_command: bzr.exe # (default: bzr)
127 127 # scm_darcs_command: darcs-1.0.9-i386-linux # (default: darcs)
128 128 #
129 129 scm_subversion_command:
130 130 scm_mercurial_command:
131 131 scm_git_command:
132 132 scm_cvs_command:
133 133 scm_bazaar_command:
134 134 scm_darcs_command:
135 135
136 136 # Key used to encrypt sensitive data in the database (SCM and LDAP passwords).
137 137 # If you don't want to enable data encryption, just leave it blank.
138 138 # WARNING: losing/changing this key will make encrypted data unreadable.
139 139 #
140 140 # If you want to encrypt existing passwords in your database:
141 141 # * set the cipher key here in your configuration file
142 142 # * encrypt data using 'rake db:encrypt RAILS_ENV=production'
143 143 #
144 144 # If you have encrypted data and want to change this key, you have to:
145 145 # * decrypt data using 'rake db:decrypt RAILS_ENV=production' first
146 146 # * change the cipher key here in your configuration file
147 147 # * encrypt data using 'rake db:encrypt RAILS_ENV=production'
148 148 database_cipher_key:
149 149
150 150 # Set this to false to disable plugins' assets mirroring on startup.
151 151 # You can use `rake redmine:plugins:assets` to manually mirror assets
152 152 # to public/plugin_assets when you install/upgrade a Redmine plugin.
153 153 #
154 154 #mirror_plugins_assets_on_startup: false
155 155
156 156 # Your secret key for verifying cookie session data integrity. If you
157 157 # change this key, all old sessions will become invalid! Make sure the
158 158 # secret is at least 30 characters and all random, no regular words or
159 159 # you'll be exposed to dictionary attacks.
160 160 #
161 161 # If you have a load-balancing Redmine cluster, you have to use the
162 162 # same secret token on each machine.
163 163 #secret_token: 'change it to a long random string'
164 164
165 165 # Absolute path (e.g. /usr/bin/convert, c:/im/convert.exe) to
166 166 # the ImageMagick's `convert` binary. Used to generate attachment thumbnails.
167 167 #imagemagick_convert_command:
168 168
169 # Configuration of RMagcik font.
170 #
171 # Redmine uses RMagcik in order to export gantt png.
172 # You don't need this setting if you don't install RMagcik.
173 #
174 # In CJK (Chinese, Japanese and Korean),
175 # in order to show CJK characters correctly,
176 # you need to set this configuration.
177 #
178 # Because there is no standard font across platforms in non CJK,
179 # you need to set a font installed in your server.
180 #
181 # This setting is not necessary in non CJK.
182 #
183 # Examples for Japanese:
184 # Windows:
185 # rmagick_font_path: C:\windows\fonts\msgothic.ttc
186 # Linux:
187 # rmagick_font_path: /usr/share/fonts/ipa-mincho/ipam.ttf
188 #
189 rmagick_font_path:
190
169 191 # specific configuration options for production environment
170 192 # that overrides the default ones
171 193 production:
172 194
173 195 # specific configuration options for development environment
174 196 # that overrides the default ones
175 197 development:
@@ -1,882 +1,883
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 module Redmine
19 19 module Helpers
20 20 # Simple class to handle gantt chart data
21 21 class Gantt
22 22 include ERB::Util
23 23 include Redmine::I18n
24 24 include Redmine::Utils::DateCalculation
25 25
26 26 # :nodoc:
27 27 # Some utility methods for the PDF export
28 28 class PDF
29 29 MaxCharactorsForSubject = 45
30 30 TotalWidth = 280
31 31 LeftPaneWidth = 100
32 32
33 33 def self.right_pane_width
34 34 TotalWidth - LeftPaneWidth
35 35 end
36 36 end
37 37
38 38 attr_reader :year_from, :month_from, :date_from, :date_to, :zoom, :months, :truncated, :max_rows
39 39 attr_accessor :query
40 40 attr_accessor :project
41 41 attr_accessor :view
42 42
43 43 def initialize(options={})
44 44 options = options.dup
45 45 if options[:year] && options[:year].to_i >0
46 46 @year_from = options[:year].to_i
47 47 if options[:month] && options[:month].to_i >=1 && options[:month].to_i <= 12
48 48 @month_from = options[:month].to_i
49 49 else
50 50 @month_from = 1
51 51 end
52 52 else
53 53 @month_from ||= Date.today.month
54 54 @year_from ||= Date.today.year
55 55 end
56 56 zoom = (options[:zoom] || User.current.pref[:gantt_zoom]).to_i
57 57 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
58 58 months = (options[:months] || User.current.pref[:gantt_months]).to_i
59 59 @months = (months > 0 && months < 25) ? months : 6
60 60 # Save gantt parameters as user preference (zoom and months count)
61 61 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] ||
62 62 @months != User.current.pref[:gantt_months]))
63 63 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
64 64 User.current.preference.save
65 65 end
66 66 @date_from = Date.civil(@year_from, @month_from, 1)
67 67 @date_to = (@date_from >> @months) - 1
68 68 @subjects = ''
69 69 @lines = ''
70 70 @number_of_rows = nil
71 71 @issue_ancestors = []
72 72 @truncated = false
73 73 if options.has_key?(:max_rows)
74 74 @max_rows = options[:max_rows]
75 75 else
76 76 @max_rows = Setting.gantt_items_limit.blank? ? nil : Setting.gantt_items_limit.to_i
77 77 end
78 78 end
79 79
80 80 def common_params
81 81 { :controller => 'gantts', :action => 'show', :project_id => @project }
82 82 end
83 83
84 84 def params
85 85 common_params.merge({:zoom => zoom, :year => year_from,
86 86 :month => month_from, :months => months})
87 87 end
88 88
89 89 def params_previous
90 90 common_params.merge({:year => (date_from << months).year,
91 91 :month => (date_from << months).month,
92 92 :zoom => zoom, :months => months})
93 93 end
94 94
95 95 def params_next
96 96 common_params.merge({:year => (date_from >> months).year,
97 97 :month => (date_from >> months).month,
98 98 :zoom => zoom, :months => months})
99 99 end
100 100
101 101 # Returns the number of rows that will be rendered on the Gantt chart
102 102 def number_of_rows
103 103 return @number_of_rows if @number_of_rows
104 104 rows = projects.inject(0) {|total, p| total += number_of_rows_on_project(p)}
105 105 rows > @max_rows ? @max_rows : rows
106 106 end
107 107
108 108 # Returns the number of rows that will be used to list a project on
109 109 # the Gantt chart. This will recurse for each subproject.
110 110 def number_of_rows_on_project(project)
111 111 return 0 unless projects.include?(project)
112 112 count = 1
113 113 count += project_issues(project).size
114 114 count += project_versions(project).size
115 115 count
116 116 end
117 117
118 118 # Renders the subjects of the Gantt chart, the left side.
119 119 def subjects(options={})
120 120 render(options.merge(:only => :subjects)) unless @subjects_rendered
121 121 @subjects
122 122 end
123 123
124 124 # Renders the lines of the Gantt chart, the right side
125 125 def lines(options={})
126 126 render(options.merge(:only => :lines)) unless @lines_rendered
127 127 @lines
128 128 end
129 129
130 130 # Returns issues that will be rendered
131 131 def issues
132 132 @issues ||= @query.issues(
133 133 :include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
134 134 :order => "#{Project.table_name}.lft ASC, #{Issue.table_name}.id ASC",
135 135 :limit => @max_rows
136 136 )
137 137 end
138 138
139 139 # Return all the project nodes that will be displayed
140 140 def projects
141 141 return @projects if @projects
142 142 ids = issues.collect(&:project).uniq.collect(&:id)
143 143 if ids.any?
144 144 # All issues projects and their visible ancestors
145 145 @projects = Project.visible.all(
146 146 :joins => "LEFT JOIN #{Project.table_name} child ON #{Project.table_name}.lft <= child.lft AND #{Project.table_name}.rgt >= child.rgt",
147 147 :conditions => ["child.id IN (?)", ids],
148 148 :order => "#{Project.table_name}.lft ASC"
149 149 ).uniq
150 150 else
151 151 @projects = []
152 152 end
153 153 end
154 154
155 155 # Returns the issues that belong to +project+
156 156 def project_issues(project)
157 157 @issues_by_project ||= issues.group_by(&:project)
158 158 @issues_by_project[project] || []
159 159 end
160 160
161 161 # Returns the distinct versions of the issues that belong to +project+
162 162 def project_versions(project)
163 163 project_issues(project).collect(&:fixed_version).compact.uniq
164 164 end
165 165
166 166 # Returns the issues that belong to +project+ and are assigned to +version+
167 167 def version_issues(project, version)
168 168 project_issues(project).select {|issue| issue.fixed_version == version}
169 169 end
170 170
171 171 def render(options={})
172 172 options = {:top => 0, :top_increment => 20,
173 173 :indent_increment => 20, :render => :subject,
174 174 :format => :html}.merge(options)
175 175 indent = options[:indent] || 4
176 176 @subjects = '' unless options[:only] == :lines
177 177 @lines = '' unless options[:only] == :subjects
178 178 @number_of_rows = 0
179 179 Project.project_tree(projects) do |project, level|
180 180 options[:indent] = indent + level * options[:indent_increment]
181 181 render_project(project, options)
182 182 break if abort?
183 183 end
184 184 @subjects_rendered = true unless options[:only] == :lines
185 185 @lines_rendered = true unless options[:only] == :subjects
186 186 render_end(options)
187 187 end
188 188
189 189 def render_project(project, options={})
190 190 subject_for_project(project, options) unless options[:only] == :lines
191 191 line_for_project(project, options) unless options[:only] == :subjects
192 192 options[:top] += options[:top_increment]
193 193 options[:indent] += options[:indent_increment]
194 194 @number_of_rows += 1
195 195 return if abort?
196 196 issues = project_issues(project).select {|i| i.fixed_version.nil?}
197 197 sort_issues!(issues)
198 198 if issues
199 199 render_issues(issues, options)
200 200 return if abort?
201 201 end
202 202 versions = project_versions(project)
203 203 versions.each do |version|
204 204 render_version(project, version, options)
205 205 end
206 206 # Remove indent to hit the next sibling
207 207 options[:indent] -= options[:indent_increment]
208 208 end
209 209
210 210 def render_issues(issues, options={})
211 211 @issue_ancestors = []
212 212 issues.each do |i|
213 213 subject_for_issue(i, options) unless options[:only] == :lines
214 214 line_for_issue(i, options) unless options[:only] == :subjects
215 215 options[:top] += options[:top_increment]
216 216 @number_of_rows += 1
217 217 break if abort?
218 218 end
219 219 options[:indent] -= (options[:indent_increment] * @issue_ancestors.size)
220 220 end
221 221
222 222 def render_version(project, version, options={})
223 223 # Version header
224 224 subject_for_version(version, options) unless options[:only] == :lines
225 225 line_for_version(version, options) unless options[:only] == :subjects
226 226 options[:top] += options[:top_increment]
227 227 @number_of_rows += 1
228 228 return if abort?
229 229 issues = version_issues(project, version)
230 230 if issues
231 231 sort_issues!(issues)
232 232 # Indent issues
233 233 options[:indent] += options[:indent_increment]
234 234 render_issues(issues, options)
235 235 options[:indent] -= options[:indent_increment]
236 236 end
237 237 end
238 238
239 239 def render_end(options={})
240 240 case options[:format]
241 241 when :pdf
242 242 options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top])
243 243 end
244 244 end
245 245
246 246 def subject_for_project(project, options)
247 247 case options[:format]
248 248 when :html
249 249 html_class = ""
250 250 html_class << 'icon icon-projects '
251 251 html_class << (project.overdue? ? 'project-overdue' : '')
252 252 s = view.link_to_project(project).html_safe
253 253 subject = view.content_tag(:span, s,
254 254 :class => html_class).html_safe
255 255 html_subject(options, subject, :css => "project-name")
256 256 when :image
257 257 image_subject(options, project.name)
258 258 when :pdf
259 259 pdf_new_page?(options)
260 260 pdf_subject(options, project.name)
261 261 end
262 262 end
263 263
264 264 def line_for_project(project, options)
265 265 # Skip versions that don't have a start_date or due date
266 266 if project.is_a?(Project) && project.start_date && project.due_date
267 267 options[:zoom] ||= 1
268 268 options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom]
269 269 coords = coordinates(project.start_date, project.due_date, nil, options[:zoom])
270 270 label = h(project)
271 271 case options[:format]
272 272 when :html
273 273 html_task(options, coords, :css => "project task", :label => label, :markers => true)
274 274 when :image
275 275 image_task(options, coords, :label => label, :markers => true, :height => 3)
276 276 when :pdf
277 277 pdf_task(options, coords, :label => label, :markers => true, :height => 0.8)
278 278 end
279 279 else
280 280 ActiveRecord::Base.logger.debug "Gantt#line_for_project was not given a project with a start_date"
281 281 ''
282 282 end
283 283 end
284 284
285 285 def subject_for_version(version, options)
286 286 case options[:format]
287 287 when :html
288 288 html_class = ""
289 289 html_class << 'icon icon-package '
290 290 html_class << (version.behind_schedule? ? 'version-behind-schedule' : '') << " "
291 291 html_class << (version.overdue? ? 'version-overdue' : '')
292 292 s = view.link_to_version(version).html_safe
293 293 subject = view.content_tag(:span, s,
294 294 :class => html_class).html_safe
295 295 html_subject(options, subject, :css => "version-name")
296 296 when :image
297 297 image_subject(options, version.to_s_with_project)
298 298 when :pdf
299 299 pdf_new_page?(options)
300 300 pdf_subject(options, version.to_s_with_project)
301 301 end
302 302 end
303 303
304 304 def line_for_version(version, options)
305 305 # Skip versions that don't have a start_date
306 306 if version.is_a?(Version) && version.start_date && version.due_date
307 307 options[:zoom] ||= 1
308 308 options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom]
309 309 coords = coordinates(version.start_date,
310 310 version.due_date, version.completed_pourcent,
311 311 options[:zoom])
312 312 label = "#{h version} #{h version.completed_pourcent.to_i.to_s}%"
313 313 label = h("#{version.project} -") + label unless @project && @project == version.project
314 314 case options[:format]
315 315 when :html
316 316 html_task(options, coords, :css => "version task", :label => label, :markers => true)
317 317 when :image
318 318 image_task(options, coords, :label => label, :markers => true, :height => 3)
319 319 when :pdf
320 320 pdf_task(options, coords, :label => label, :markers => true, :height => 0.8)
321 321 end
322 322 else
323 323 ActiveRecord::Base.logger.debug "Gantt#line_for_version was not given a version with a start_date"
324 324 ''
325 325 end
326 326 end
327 327
328 328 def subject_for_issue(issue, options)
329 329 while @issue_ancestors.any? && !issue.is_descendant_of?(@issue_ancestors.last)
330 330 @issue_ancestors.pop
331 331 options[:indent] -= options[:indent_increment]
332 332 end
333 333 output = case options[:format]
334 334 when :html
335 335 css_classes = ''
336 336 css_classes << ' issue-overdue' if issue.overdue?
337 337 css_classes << ' issue-behind-schedule' if issue.behind_schedule?
338 338 css_classes << ' icon icon-issue' unless Setting.gravatar_enabled? && issue.assigned_to
339 339 s = "".html_safe
340 340 if issue.assigned_to.present?
341 341 assigned_string = l(:field_assigned_to) + ": " + issue.assigned_to.name
342 342 s << view.avatar(issue.assigned_to,
343 343 :class => 'gravatar icon-gravatar',
344 344 :size => 10,
345 345 :title => assigned_string).to_s.html_safe
346 346 end
347 347 s << view.link_to_issue(issue).html_safe
348 348 subject = view.content_tag(:span, s, :class => css_classes).html_safe
349 349 html_subject(options, subject, :css => "issue-subject",
350 350 :title => issue.subject) + "\n"
351 351 when :image
352 352 image_subject(options, issue.subject)
353 353 when :pdf
354 354 pdf_new_page?(options)
355 355 pdf_subject(options, issue.subject)
356 356 end
357 357 unless issue.leaf?
358 358 @issue_ancestors << issue
359 359 options[:indent] += options[:indent_increment]
360 360 end
361 361 output
362 362 end
363 363
364 364 def line_for_issue(issue, options)
365 365 # Skip issues that don't have a due_before (due_date or version's due_date)
366 366 if issue.is_a?(Issue) && issue.due_before
367 367 coords = coordinates(issue.start_date, issue.due_before, issue.done_ratio, options[:zoom])
368 368 label = "#{issue.status.name} #{issue.done_ratio}%"
369 369 case options[:format]
370 370 when :html
371 371 html_task(options, coords,
372 372 :css => "task " + (issue.leaf? ? 'leaf' : 'parent'),
373 373 :label => label, :issue => issue,
374 374 :markers => !issue.leaf?)
375 375 when :image
376 376 image_task(options, coords, :label => label)
377 377 when :pdf
378 378 pdf_task(options, coords, :label => label)
379 379 end
380 380 else
381 381 ActiveRecord::Base.logger.debug "GanttHelper#line_for_issue was not given an issue with a due_before"
382 382 ''
383 383 end
384 384 end
385 385
386 386 # Generates a gantt image
387 387 # Only defined if RMagick is avalaible
388 388 def to_image(format='PNG')
389 389 date_to = (@date_from >> @months) - 1
390 390 show_weeks = @zoom > 1
391 391 show_days = @zoom > 2
392 392 subject_width = 400
393 393 header_height = 18
394 394 # width of one day in pixels
395 395 zoom = @zoom * 2
396 396 g_width = (@date_to - @date_from + 1) * zoom
397 397 g_height = 20 * number_of_rows + 30
398 398 headers_height = (show_weeks ? 2 * header_height : header_height)
399 399 height = g_height + headers_height
400 400 imgl = Magick::ImageList.new
401 401 imgl.new_image(subject_width + g_width + 1, height)
402 402 gc = Magick::Draw.new
403 gc.font = Redmine::Configuration['rmagick_font_path'] || ""
403 404 # Subjects
404 405 gc.stroke('transparent')
405 406 subjects(:image => gc, :top => (headers_height + 20), :indent => 4, :format => :image)
406 407 # Months headers
407 408 month_f = @date_from
408 409 left = subject_width
409 410 @months.times do
410 411 width = ((month_f >> 1) - month_f) * zoom
411 412 gc.fill('white')
412 413 gc.stroke('grey')
413 414 gc.stroke_width(1)
414 415 gc.rectangle(left, 0, left + width, height)
415 416 gc.fill('black')
416 417 gc.stroke('transparent')
417 418 gc.stroke_width(1)
418 419 gc.text(left.round + 8, 14, "#{month_f.year}-#{month_f.month}")
419 420 left = left + width
420 421 month_f = month_f >> 1
421 422 end
422 423 # Weeks headers
423 424 if show_weeks
424 425 left = subject_width
425 426 height = header_height
426 427 if @date_from.cwday == 1
427 428 # date_from is monday
428 429 week_f = date_from
429 430 else
430 431 # find next monday after date_from
431 432 week_f = @date_from + (7 - @date_from.cwday + 1)
432 433 width = (7 - @date_from.cwday + 1) * zoom
433 434 gc.fill('white')
434 435 gc.stroke('grey')
435 436 gc.stroke_width(1)
436 437 gc.rectangle(left, header_height, left + width, 2 * header_height + g_height - 1)
437 438 left = left + width
438 439 end
439 440 while week_f <= date_to
440 441 width = (week_f + 6 <= date_to) ? 7 * zoom : (date_to - week_f + 1) * zoom
441 442 gc.fill('white')
442 443 gc.stroke('grey')
443 444 gc.stroke_width(1)
444 445 gc.rectangle(left.round, header_height, left.round + width, 2 * header_height + g_height - 1)
445 446 gc.fill('black')
446 447 gc.stroke('transparent')
447 448 gc.stroke_width(1)
448 449 gc.text(left.round + 2, header_height + 14, week_f.cweek.to_s)
449 450 left = left + width
450 451 week_f = week_f + 7
451 452 end
452 453 end
453 454 # Days details (week-end in grey)
454 455 if show_days
455 456 left = subject_width
456 457 height = g_height + header_height - 1
457 458 wday = @date_from.cwday
458 459 (date_to - @date_from + 1).to_i.times do
459 460 width = zoom
460 461 gc.fill(non_working_week_days.include?(wday) ? '#eee' : 'white')
461 462 gc.stroke('#ddd')
462 463 gc.stroke_width(1)
463 464 gc.rectangle(left, 2 * header_height, left + width, 2 * header_height + g_height - 1)
464 465 left = left + width
465 466 wday = wday + 1
466 467 wday = 1 if wday > 7
467 468 end
468 469 end
469 470 # border
470 471 gc.fill('transparent')
471 472 gc.stroke('grey')
472 473 gc.stroke_width(1)
473 474 gc.rectangle(0, 0, subject_width + g_width, headers_height)
474 475 gc.stroke('black')
475 476 gc.rectangle(0, 0, subject_width + g_width, g_height + headers_height - 1)
476 477 # content
477 478 top = headers_height + 20
478 479 gc.stroke('transparent')
479 480 lines(:image => gc, :top => top, :zoom => zoom,
480 481 :subject_width => subject_width, :format => :image)
481 482 # today red line
482 483 if Date.today >= @date_from and Date.today <= date_to
483 484 gc.stroke('red')
484 485 x = (Date.today - @date_from + 1) * zoom + subject_width
485 486 gc.line(x, headers_height, x, headers_height + g_height - 1)
486 487 end
487 488 gc.draw(imgl)
488 489 imgl.format = format
489 490 imgl.to_blob
490 491 end if Object.const_defined?(:Magick)
491 492
492 493 def to_pdf
493 494 pdf = ::Redmine::Export::PDF::ITCPDF.new(current_language)
494 495 pdf.SetTitle("#{l(:label_gantt)} #{project}")
495 496 pdf.alias_nb_pages
496 497 pdf.footer_date = format_date(Date.today)
497 498 pdf.AddPage("L")
498 499 pdf.SetFontStyle('B', 12)
499 500 pdf.SetX(15)
500 501 pdf.RDMCell(PDF::LeftPaneWidth, 20, project.to_s)
501 502 pdf.Ln
502 503 pdf.SetFontStyle('B', 9)
503 504 subject_width = PDF::LeftPaneWidth
504 505 header_height = 5
505 506 headers_height = header_height
506 507 show_weeks = false
507 508 show_days = false
508 509 if self.months < 7
509 510 show_weeks = true
510 511 headers_height = 2 * header_height
511 512 if self.months < 3
512 513 show_days = true
513 514 headers_height = 3 * header_height
514 515 end
515 516 end
516 517 g_width = PDF.right_pane_width
517 518 zoom = (g_width) / (self.date_to - self.date_from + 1)
518 519 g_height = 120
519 520 t_height = g_height + headers_height
520 521 y_start = pdf.GetY
521 522 # Months headers
522 523 month_f = self.date_from
523 524 left = subject_width
524 525 height = header_height
525 526 self.months.times do
526 527 width = ((month_f >> 1) - month_f) * zoom
527 528 pdf.SetY(y_start)
528 529 pdf.SetX(left)
529 530 pdf.RDMCell(width, height, "#{month_f.year}-#{month_f.month}", "LTR", 0, "C")
530 531 left = left + width
531 532 month_f = month_f >> 1
532 533 end
533 534 # Weeks headers
534 535 if show_weeks
535 536 left = subject_width
536 537 height = header_height
537 538 if self.date_from.cwday == 1
538 539 # self.date_from is monday
539 540 week_f = self.date_from
540 541 else
541 542 # find next monday after self.date_from
542 543 week_f = self.date_from + (7 - self.date_from.cwday + 1)
543 544 width = (7 - self.date_from.cwday + 1) * zoom-1
544 545 pdf.SetY(y_start + header_height)
545 546 pdf.SetX(left)
546 547 pdf.RDMCell(width + 1, height, "", "LTR")
547 548 left = left + width + 1
548 549 end
549 550 while week_f <= self.date_to
550 551 width = (week_f + 6 <= self.date_to) ? 7 * zoom : (self.date_to - week_f + 1) * zoom
551 552 pdf.SetY(y_start + header_height)
552 553 pdf.SetX(left)
553 554 pdf.RDMCell(width, height, (width >= 5 ? week_f.cweek.to_s : ""), "LTR", 0, "C")
554 555 left = left + width
555 556 week_f = week_f + 7
556 557 end
557 558 end
558 559 # Days headers
559 560 if show_days
560 561 left = subject_width
561 562 height = header_height
562 563 wday = self.date_from.cwday
563 564 pdf.SetFontStyle('B', 7)
564 565 (self.date_to - self.date_from + 1).to_i.times do
565 566 width = zoom
566 567 pdf.SetY(y_start + 2 * header_height)
567 568 pdf.SetX(left)
568 569 pdf.RDMCell(width, height, day_name(wday).first, "LTR", 0, "C")
569 570 left = left + width
570 571 wday = wday + 1
571 572 wday = 1 if wday > 7
572 573 end
573 574 end
574 575 pdf.SetY(y_start)
575 576 pdf.SetX(15)
576 577 pdf.RDMCell(subject_width + g_width - 15, headers_height, "", 1)
577 578 # Tasks
578 579 top = headers_height + y_start
579 580 options = {
580 581 :top => top,
581 582 :zoom => zoom,
582 583 :subject_width => subject_width,
583 584 :g_width => g_width,
584 585 :indent => 0,
585 586 :indent_increment => 5,
586 587 :top_increment => 5,
587 588 :format => :pdf,
588 589 :pdf => pdf
589 590 }
590 591 render(options)
591 592 pdf.Output
592 593 end
593 594
594 595 private
595 596
596 597 def coordinates(start_date, end_date, progress, zoom=nil)
597 598 zoom ||= @zoom
598 599 coords = {}
599 600 if start_date && end_date && start_date < self.date_to && end_date > self.date_from
600 601 if start_date > self.date_from
601 602 coords[:start] = start_date - self.date_from
602 603 coords[:bar_start] = start_date - self.date_from
603 604 else
604 605 coords[:bar_start] = 0
605 606 end
606 607 if end_date < self.date_to
607 608 coords[:end] = end_date - self.date_from
608 609 coords[:bar_end] = end_date - self.date_from + 1
609 610 else
610 611 coords[:bar_end] = self.date_to - self.date_from + 1
611 612 end
612 613 if progress
613 614 progress_date = start_date + (end_date - start_date + 1) * (progress / 100.0)
614 615 if progress_date > self.date_from && progress_date > start_date
615 616 if progress_date < self.date_to
616 617 coords[:bar_progress_end] = progress_date - self.date_from
617 618 else
618 619 coords[:bar_progress_end] = self.date_to - self.date_from + 1
619 620 end
620 621 end
621 622 if progress_date < Date.today
622 623 late_date = [Date.today, end_date].min
623 624 if late_date > self.date_from && late_date > start_date
624 625 if late_date < self.date_to
625 626 coords[:bar_late_end] = late_date - self.date_from + 1
626 627 else
627 628 coords[:bar_late_end] = self.date_to - self.date_from + 1
628 629 end
629 630 end
630 631 end
631 632 end
632 633 end
633 634 # Transforms dates into pixels witdh
634 635 coords.keys.each do |key|
635 636 coords[key] = (coords[key] * zoom).floor
636 637 end
637 638 coords
638 639 end
639 640
640 641 # Sorts a collection of issues by start_date, due_date, id for gantt rendering
641 642 def sort_issues!(issues)
642 643 issues.sort! { |a, b| gantt_issue_compare(a, b) }
643 644 end
644 645
645 646 # TODO: top level issues should be sorted by start date
646 647 def gantt_issue_compare(x, y)
647 648 if x.root_id == y.root_id
648 649 x.lft <=> y.lft
649 650 else
650 651 x.root_id <=> y.root_id
651 652 end
652 653 end
653 654
654 655 def current_limit
655 656 if @max_rows
656 657 @max_rows - @number_of_rows
657 658 else
658 659 nil
659 660 end
660 661 end
661 662
662 663 def abort?
663 664 if @max_rows && @number_of_rows >= @max_rows
664 665 @truncated = true
665 666 end
666 667 end
667 668
668 669 def pdf_new_page?(options)
669 670 if options[:top] > 180
670 671 options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top])
671 672 options[:pdf].AddPage("L")
672 673 options[:top] = 15
673 674 options[:pdf].Line(15, options[:top] - 0.1, PDF::TotalWidth, options[:top] - 0.1)
674 675 end
675 676 end
676 677
677 678 def html_subject(params, subject, options={})
678 679 style = "position: absolute;top:#{params[:top]}px;left:#{params[:indent]}px;"
679 680 style << "width:#{params[:subject_width] - params[:indent]}px;" if params[:subject_width]
680 681 output = view.content_tag('div', subject,
681 682 :class => options[:css], :style => style,
682 683 :title => options[:title])
683 684 @subjects << output
684 685 output
685 686 end
686 687
687 688 def pdf_subject(params, subject, options={})
688 689 params[:pdf].SetY(params[:top])
689 690 params[:pdf].SetX(15)
690 691 char_limit = PDF::MaxCharactorsForSubject - params[:indent]
691 692 params[:pdf].RDMCell(params[:subject_width] - 15, 5,
692 693 (" " * params[:indent]) +
693 694 subject.to_s.sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'),
694 695 "LR")
695 696 params[:pdf].SetY(params[:top])
696 697 params[:pdf].SetX(params[:subject_width])
697 698 params[:pdf].RDMCell(params[:g_width], 5, "", "LR")
698 699 end
699 700
700 701 def image_subject(params, subject, options={})
701 702 params[:image].fill('black')
702 703 params[:image].stroke('transparent')
703 704 params[:image].stroke_width(1)
704 705 params[:image].text(params[:indent], params[:top] + 2, subject)
705 706 end
706 707
707 708 def html_task(params, coords, options={})
708 709 output = ''
709 710 # Renders the task bar, with progress and late
710 711 if coords[:bar_start] && coords[:bar_end]
711 712 width = coords[:bar_end] - coords[:bar_start] - 2
712 713 style = ""
713 714 style << "top:#{params[:top]}px;"
714 715 style << "left:#{coords[:bar_start]}px;"
715 716 style << "width:#{width}px;"
716 717 output << view.content_tag(:div, '&nbsp;'.html_safe,
717 718 :style => style,
718 719 :class => "#{options[:css]} task_todo")
719 720 if coords[:bar_late_end]
720 721 width = coords[:bar_late_end] - coords[:bar_start] - 2
721 722 style = ""
722 723 style << "top:#{params[:top]}px;"
723 724 style << "left:#{coords[:bar_start]}px;"
724 725 style << "width:#{width}px;"
725 726 output << view.content_tag(:div, '&nbsp;'.html_safe,
726 727 :style => style,
727 728 :class => "#{options[:css]} task_late")
728 729 end
729 730 if coords[:bar_progress_end]
730 731 width = coords[:bar_progress_end] - coords[:bar_start] - 2
731 732 style = ""
732 733 style << "top:#{params[:top]}px;"
733 734 style << "left:#{coords[:bar_start]}px;"
734 735 style << "width:#{width}px;"
735 736 output << view.content_tag(:div, '&nbsp;'.html_safe,
736 737 :style => style,
737 738 :class => "#{options[:css]} task_done")
738 739 end
739 740 end
740 741 # Renders the markers
741 742 if options[:markers]
742 743 if coords[:start]
743 744 style = ""
744 745 style << "top:#{params[:top]}px;"
745 746 style << "left:#{coords[:start]}px;"
746 747 style << "width:15px;"
747 748 output << view.content_tag(:div, '&nbsp;'.html_safe,
748 749 :style => style,
749 750 :class => "#{options[:css]} marker starting")
750 751 end
751 752 if coords[:end]
752 753 style = ""
753 754 style << "top:#{params[:top]}px;"
754 755 style << "left:#{coords[:end] + params[:zoom]}px;"
755 756 style << "width:15px;"
756 757 output << view.content_tag(:div, '&nbsp;'.html_safe,
757 758 :style => style,
758 759 :class => "#{options[:css]} marker ending")
759 760 end
760 761 end
761 762 # Renders the label on the right
762 763 if options[:label]
763 764 style = ""
764 765 style << "top:#{params[:top]}px;"
765 766 style << "left:#{(coords[:bar_end] || 0) + 8}px;"
766 767 style << "width:15px;"
767 768 output << view.content_tag(:div, options[:label],
768 769 :style => style,
769 770 :class => "#{options[:css]} label")
770 771 end
771 772 # Renders the tooltip
772 773 if options[:issue] && coords[:bar_start] && coords[:bar_end]
773 774 s = view.content_tag(:span,
774 775 view.render_issue_tooltip(options[:issue]).html_safe,
775 776 :class => "tip")
776 777 style = ""
777 778 style << "position: absolute;"
778 779 style << "top:#{params[:top]}px;"
779 780 style << "left:#{coords[:bar_start]}px;"
780 781 style << "width:#{coords[:bar_end] - coords[:bar_start]}px;"
781 782 style << "height:12px;"
782 783 output << view.content_tag(:div, s.html_safe,
783 784 :style => style,
784 785 :class => "tooltip")
785 786 end
786 787 @lines << output
787 788 output
788 789 end
789 790
790 791 def pdf_task(params, coords, options={})
791 792 height = options[:height] || 2
792 793 # Renders the task bar, with progress and late
793 794 if coords[:bar_start] && coords[:bar_end]
794 795 params[:pdf].SetY(params[:top] + 1.5)
795 796 params[:pdf].SetX(params[:subject_width] + coords[:bar_start])
796 797 params[:pdf].SetFillColor(200, 200, 200)
797 798 params[:pdf].RDMCell(coords[:bar_end] - coords[:bar_start], height, "", 0, 0, "", 1)
798 799 if coords[:bar_late_end]
799 800 params[:pdf].SetY(params[:top] + 1.5)
800 801 params[:pdf].SetX(params[:subject_width] + coords[:bar_start])
801 802 params[:pdf].SetFillColor(255, 100, 100)
802 803 params[:pdf].RDMCell(coords[:bar_late_end] - coords[:bar_start], height, "", 0, 0, "", 1)
803 804 end
804 805 if coords[:bar_progress_end]
805 806 params[:pdf].SetY(params[:top] + 1.5)
806 807 params[:pdf].SetX(params[:subject_width] + coords[:bar_start])
807 808 params[:pdf].SetFillColor(90, 200, 90)
808 809 params[:pdf].RDMCell(coords[:bar_progress_end] - coords[:bar_start], height, "", 0, 0, "", 1)
809 810 end
810 811 end
811 812 # Renders the markers
812 813 if options[:markers]
813 814 if coords[:start]
814 815 params[:pdf].SetY(params[:top] + 1)
815 816 params[:pdf].SetX(params[:subject_width] + coords[:start] - 1)
816 817 params[:pdf].SetFillColor(50, 50, 200)
817 818 params[:pdf].RDMCell(2, 2, "", 0, 0, "", 1)
818 819 end
819 820 if coords[:end]
820 821 params[:pdf].SetY(params[:top] + 1)
821 822 params[:pdf].SetX(params[:subject_width] + coords[:end] - 1)
822 823 params[:pdf].SetFillColor(50, 50, 200)
823 824 params[:pdf].RDMCell(2, 2, "", 0, 0, "", 1)
824 825 end
825 826 end
826 827 # Renders the label on the right
827 828 if options[:label]
828 829 params[:pdf].SetX(params[:subject_width] + (coords[:bar_end] || 0) + 5)
829 830 params[:pdf].RDMCell(30, 2, options[:label])
830 831 end
831 832 end
832 833
833 834 def image_task(params, coords, options={})
834 835 height = options[:height] || 6
835 836 # Renders the task bar, with progress and late
836 837 if coords[:bar_start] && coords[:bar_end]
837 838 params[:image].fill('#aaa')
838 839 params[:image].rectangle(params[:subject_width] + coords[:bar_start],
839 840 params[:top],
840 841 params[:subject_width] + coords[:bar_end],
841 842 params[:top] - height)
842 843 if coords[:bar_late_end]
843 844 params[:image].fill('#f66')
844 845 params[:image].rectangle(params[:subject_width] + coords[:bar_start],
845 846 params[:top],
846 847 params[:subject_width] + coords[:bar_late_end],
847 848 params[:top] - height)
848 849 end
849 850 if coords[:bar_progress_end]
850 851 params[:image].fill('#00c600')
851 852 params[:image].rectangle(params[:subject_width] + coords[:bar_start],
852 853 params[:top],
853 854 params[:subject_width] + coords[:bar_progress_end],
854 855 params[:top] - height)
855 856 end
856 857 end
857 858 # Renders the markers
858 859 if options[:markers]
859 860 if coords[:start]
860 861 x = params[:subject_width] + coords[:start]
861 862 y = params[:top] - height / 2
862 863 params[:image].fill('blue')
863 864 params[:image].polygon(x - 4, y, x, y - 4, x + 4, y, x, y + 4)
864 865 end
865 866 if coords[:end]
866 867 x = params[:subject_width] + coords[:end] + params[:zoom]
867 868 y = params[:top] - height / 2
868 869 params[:image].fill('blue')
869 870 params[:image].polygon(x - 4, y, x, y - 4, x + 4, y, x, y + 4)
870 871 end
871 872 end
872 873 # Renders the label on the right
873 874 if options[:label]
874 875 params[:image].fill('black')
875 876 params[:image].text(params[:subject_width] + (coords[:bar_end] || 0) + 5,
876 877 params[:top] + 1,
877 878 options[:label])
878 879 end
879 880 end
880 881 end
881 882 end
882 883 end
General Comments 0
You need to be logged in to leave comments. Login now