Skip to content

Instantly share code, notes, and snippets.

@znz
Created October 27, 2008 04:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save znz/20016 to your computer and use it in GitHub Desktop.
Save znz/20016 to your computer and use it in GitHub Desktop.
http://groups.google.com/group/redmine-users-ja/browse_thread/thread/6ca8cfb88541e254/40dcd8d66de85a31?#40dcd8d66de85a31
の文字化け対応パッチが改行とかの問題でそのままだと当てられない。
diff -r fa9f989c3ab3 app/helpers/ifpdf_helper.rb
--- a/app/helpers/ifpdf_helper.rb Mon Oct 27 13:15:55 2008 +0900
+++ b/app/helpers/ifpdf_helper.rb Mon Oct 27 13:18:30 2008 +0900
@@ -56,6 +56,17 @@ module IfpdfHelper
end
def Cell(w,h=0,txt='',border=0,ln=0,align='',fill=0,link='')
+ txt = convUTF8toSJISandEscape0x5c(txt)
+ super w,h,txt,border,ln,align,fill,link
+ end
+
+ def MultiCell2(w,h,txt,border=0,align='L',fill=0)
+ txt = convUTF8toSJISandEscape0x5c(txt)
+ MultiCell(w,h,txt,border,align,fill)
+ end
+
+ def convUTF8toSJISandEscape0x5c(txt)
+ txt << " "
@ic ||= Iconv.new(l(:general_pdf_encoding), 'UTF-8')
# these quotation marks are not correctly rendered in the pdf
txt = txt.gsub(/[“”]/, '"') if txt
@@ -67,9 +78,8 @@ module IfpdfHelper
rescue
txt
end || ''
- super w,h,txt,border,ln,align,fill,link
end
-
+
def Footer
SetFont(@font_for_footer, 'I', 8)
SetY(-15)
@@ -79,7 +89,31 @@ module IfpdfHelper
SetX(-30)
Cell(0, 5, PageNo().to_s + '/{nb}', 0, 0, 'C')
end
-
+
+ def SetTitle(txt)
+ case current_language.to_s
+ when 'ja', 'zh', 'zh-tw'
+ txt = begin
+ utf16txt = Iconv.conv('UTF-16BE', 'UTF-8', txt)
+ hextxt = "<FEFF" # FEFF is BOM
+ hextxt << utf16txt.unpack("C*").map {|x| sprintf("%02X",x) }.join
+ hextxt << ">"
+ rescue
+ txt
+ end || ''
+ end
+ super(txt)
+ end
+
+ def textstring(s)
+ # Format a text string
+ if s =~ /^</ # This means the string is hex-dumped.
+ return s
+ else
+ return '('+escape(s)+')'
+ end
+ end
+
end
end
diff -r fa9f989c3ab3 app/views/issues/_pdf.rfpdf
--- a/app/views/issues/_pdf.rfpdf Mon Oct 27 13:15:55 2008 +0900
+++ b/app/views/issues/_pdf.rfpdf Mon Oct 27 13:18:30 2008 +0900
@@ -48,7 +48,7 @@
pdf.SetFontStyle('B',9)
pdf.Cell(35,5, custom_value.custom_field.name + ":","L")
pdf.SetFontStyle('',9)
- pdf.MultiCell(155,5, (show_value custom_value),"R")
+ pdf.MultiCell2(155,5, (show_value custom_value),"R")
end
pdf.SetFontStyle('B',9)
@@ -60,7 +60,7 @@
pdf.SetFontStyle('B',9)
pdf.Cell(35,5, l(:field_description) + ":")
pdf.SetFontStyle('',9)
- pdf.MultiCell(155,5, issue.description,"BR")
+ pdf.MultiCell2(155,5, issue.description,"BR")
pdf.Line(pdf.GetX, y0, pdf.GetX, pdf.GetY)
pdf.Line(pdf.GetX, pdf.GetY, 170, pdf.GetY)
@@ -77,7 +77,7 @@
pdf.Ln
unless changeset.comments.blank?
pdf.SetFontStyle('',8)
- pdf.MultiCell(190,5, changeset.comments)
+ pdf.MultiCell2(190,5, changeset.comments)
end
pdf.Ln
end
@@ -97,7 +97,7 @@
end
if journal.notes?
pdf.SetFontStyle('',8)
- pdf.MultiCell(190,5, journal.notes)
+ pdf.MultiCell2(190,5, journal.notes)
end
pdf.Ln
end
diff -r fa9f989c3ab3 app/views/issues/index.rfpdf
--- a/app/views/issues/index.rfpdf Mon Oct 27 13:15:55 2008 +0900
+++ b/app/views/issues/index.rfpdf Mon Oct 27 13:18:30 2008 +0900
@@ -42,9 +42,9 @@
pdf.Cell(30, row_height, issue.priority.name, 0, 0, 'L', 1)
pdf.Cell(40, row_height, issue.assigned_to ? issue.assigned_to.name : '', 0, 0, 'L', 1)
pdf.Cell(25, row_height, format_date(issue.updated_on), 0, 0, 'L', 1)
- pdf.MultiCell(0, row_height, (@project == issue.project ? issue.subject : "#{issue.project.name} - #{issue.subject}"))
+ pdf.MultiCell2(0, row_height, (@project == issue.project ? issue.subject : "#{issue.project.name} - #{issue.subject}"))
pdf.Line(10, pdf.GetY, 287, pdf.GetY)
pdf.SetY(pdf.GetY() + 1)
end
%>
-<%= pdf.Output %>
\ No newline at end of file
+<%= pdf.Output %>
diff -r fa9f989c3ab3 lang/ja.yml
--- a/lang/ja.yml Mon Oct 27 13:15:55 2008 +0900
+++ b/lang/ja.yml Mon Oct 27 13:18:30 2008 +0900
@@ -50,7 +50,7 @@ general_lang_name: 'Japanese (日本語)
general_lang_name: 'Japanese (日本語)'
general_csv_separator: ','
general_csv_encoding: SJIS
-general_pdf_encoding: UTF-8
+general_pdf_encoding: SJIS
general_day_names: 月曜日,火曜日,水曜日,木曜日,金曜日,土曜日,日曜日
general_first_day_of_week: '7'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment