user-pref-r8745.patch

Toshi MARUYAMA, 2012-02-02 03:17

Download (3.03 KB)

View differences:

app/controllers/gantts_controller.rb
39 39

  
40 40
    basename = (@project ? "#{@project.identifier}-" : '') + 'gantt'
41 41

  
42
    @rmagick_font = params[:rmagick_font] || User.current.pref[:rmagick_font]
43
    if User.current.logged? && !@rmagick_font.blank? &&
44
         ( @rmagick_font != User.current.pref[:rmagick_font] )
45
      User.current.pref[:rmagick_font] = @rmagick_font
46
      User.current.preference.save
47
    end
48

  
42 49
    respond_to do |format|
43 50
      format.html { render :action => "show", :layout => !request.xhr? }
44
      format.png  { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => "#{basename}.png") } if @gantt.respond_to?('to_image')
51
      if @gantt.respond_to?('to_image')
52
        format.png do
53
          send_data(@gantt.to_image('PNG', @rmagick_font), :disposition => 'inline',
54
                    :type => 'image/png', :filename => "#{basename}.png")
55
        end
56
      end
45 57
      format.pdf  { send_data(@gantt.to_pdf, :type => 'application/pdf', :filename => "#{basename}.pdf") }
46 58
    end
47 59
  end
app/views/gantts/show.html.erb
174 174
</tr>
175 175
</table>
176 176

  
177
<% if @gantt.respond_to?('to_image') %>
178
  <% form_tag(params.merge({'format'=>'PNG'}).merge(@gantt.params), :method => 'get') do %>
179
    <label>TODO: PNG font</label>
180
    <%= select_tag 'rmagick_font',
181
                    options_for_select(
182
                      Magick.fonts.collect {|t| [t.name, CGI.escape(t.name)]},
183
                      @rmagick_font
184
                        ) %>
185
    <%= submit_tag 'OK' %>
186
  <% end %>
187
<% end %>
188

  
177 189
<% other_formats_links do |f| %>
178 190
  <%= f.link_to 'PDF', :url => params.merge(@gantt.params) %>
179
  <%= f.link_to('PNG', :url => params.merge(@gantt.params)) if @gantt.respond_to?('to_image') %>
180 191
<% end %>
181 192
<% end # query.valid? %>
182 193

  
lib/redmine/helpers/gantt.rb
392 392

  
393 393
      # Generates a gantt image
394 394
      # Only defined if RMagick is avalaible
395
      def to_image(format='PNG')
395
      def to_image(format='PNG', rmagick_font=nil)
396 396
        date_to = (@date_from >> @months)-1
397 397
        show_weeks = @zoom > 1
398 398
        show_days = @zoom > 2
......
409 409
        imgl = Magick::ImageList.new
410 410
        imgl.new_image(subject_width+g_width+1, height)
411 411
        gc = Magick::Draw.new
412
        gc.font = CGI.unescape(rmagick_font) unless rmagick_font.blank?
412 413

  
413 414
        # Subjects
414 415
        gc.stroke('transparent')