Chris@0: # encoding: utf-8 Chris@0: # Chris@0: # Redmine - project management software Chris@0: # Copyright (C) 2006-2009 Jean-Philippe Lang Chris@0: # Chris@0: # This program is free software; you can redistribute it and/or Chris@0: # modify it under the terms of the GNU General Public License Chris@0: # as published by the Free Software Foundation; either version 2 Chris@0: # of the License, or (at your option) any later version. Chris@0: # Chris@0: # This program is distributed in the hope that it will be useful, Chris@0: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: # GNU General Public License for more details. Chris@0: # Chris@0: # You should have received a copy of the GNU General Public License Chris@0: # along with this program; if not, write to the Free Software Chris@0: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@0: Chris@0: require 'iconv' Chris@0: require 'rfpdf/fpdf' Chris@0: require 'rfpdf/chinese' Chris@0: Chris@0: module Redmine Chris@0: module Export Chris@0: module PDF Chris@0: include ActionView::Helpers::TextHelper Chris@0: include ActionView::Helpers::NumberHelper Chris@0: Chris@0: class IFPDF < FPDF Chris@0: include Redmine::I18n Chris@0: attr_accessor :footer_date Chris@0: Chris@0: def initialize(lang) Chris@0: super() Chris@0: set_language_if_valid lang Chris@0: case current_language.to_s.downcase Chris@0: when 'ko' Chris@0: extend(PDF_Korean) Chris@0: AddUHCFont() Chris@0: @font_for_content = 'UHC' Chris@0: @font_for_footer = 'UHC' Chris@0: when 'ja' Chris@0: extend(PDF_Japanese) Chris@0: AddSJISFont() Chris@0: @font_for_content = 'SJIS' Chris@0: @font_for_footer = 'SJIS' Chris@0: when 'zh' Chris@0: extend(PDF_Chinese) Chris@0: AddGBFont() Chris@0: @font_for_content = 'GB' Chris@0: @font_for_footer = 'GB' Chris@0: when 'zh-tw' Chris@0: extend(PDF_Chinese) Chris@0: AddBig5Font() Chris@0: @font_for_content = 'Big5' Chris@0: @font_for_footer = 'Big5' Chris@0: else Chris@0: @font_for_content = 'Arial' Chris@0: @font_for_footer = 'Helvetica' Chris@0: end Chris@0: SetCreator(Redmine::Info.app_name) Chris@0: SetFont(@font_for_content) Chris@0: end Chris@0: Chris@0: def SetFontStyle(style, size) Chris@0: SetFont(@font_for_content, style, size) Chris@0: end Chris@0: Chris@0: def SetTitle(txt) Chris@0: txt = begin Chris@0: utf16txt = Iconv.conv('UTF-16BE', 'UTF-8', txt) Chris@0: hextxt = "" Chris@0: rescue Chris@0: txt Chris@0: end || '' Chris@0: super(txt) Chris@0: end Chris@0: Chris@0: def textstring(s) Chris@0: # Format a text string Chris@0: if s =~ /^ [:user, :details], :order => "#{Journal.table_name}.created_on ASC") Chris@0: pdf.SetFontStyle('B',8) Chris@0: pdf.Cell(190,5, format_time(journal.created_on) + " - " + journal.user.name) Chris@0: pdf.Ln Chris@0: pdf.SetFontStyle('I',8) Chris@0: for detail in journal.details Chris@0: pdf.Cell(190,5, "- " + show_detail(detail, true)) Chris@0: pdf.Ln Chris@0: end Chris@0: if journal.notes? Chris@0: pdf.SetFontStyle('',8) Chris@0: pdf.MultiCell(190,5, journal.notes) Chris@0: end Chris@0: pdf.Ln Chris@0: end Chris@0: Chris@0: if issue.attachments.any? Chris@0: pdf.SetFontStyle('B',9) Chris@0: pdf.Cell(190,5, l(:label_attachment_plural), "B") Chris@0: pdf.Ln Chris@0: for attachment in issue.attachments Chris@0: pdf.SetFontStyle('',8) Chris@0: pdf.Cell(80,5, attachment.filename) Chris@0: pdf.Cell(20,5, number_to_human_size(attachment.filesize),0,0,"R") Chris@0: pdf.Cell(25,5, format_date(attachment.created_on),0,0,"R") Chris@0: pdf.Cell(65,5, attachment.author.name,0,0,"R") Chris@0: pdf.Ln Chris@0: end Chris@0: end Chris@0: pdf.Output Chris@0: end chris@22: Chris@0: end Chris@0: end Chris@0: end