2009/10/26

Redmine 한글 PDF 출력 문제

얼마전 부터 Redmine 을 활용하여 프로젝트 관리를 해오고 있는데 Redmine 에서 지원하는 Gantt Chart 와 업무리스트를 PDF 로 출력을 시도해 보았는데 한글이 모두 이상한 문자로 출력이 되었다. 수정할 수 있는지 해서 인터넷에 검색을 해 보았는데 해당 문건이 많지 않았다.

검색된 자료 중 "Redmine pdf export 시 한글 깨지는 문제" 문서를 참조하여 해결을 하였다.

해결 방법은 PDF 출력 루틴과 한국어 출력 부분인데 "Redmine pdf export 시 한글 깨지는 문제" 문서에서 제시한 해결책이 그대로 적용되었다. 단, 버전의 차이에서 인지 수정해야할 파일들의 위치가 달랐다. 검색된 문서에서 제시된 redmine 버전은 0.8이고 현재 설치된 버전은 그 보다 상위 버전인 0.8.5 이다.

우선 PDF 출력 파일을 수정하였다.
파일의 위치는 lib\redmine\export\pdf.rb 이다. 이 파일의 내용중 "zh-tw" 의 내용을 복사하여 한글에 맞도록 수정한다.

  when 'zh-tw'
extend(PDF_Chinese)
AddBig5Font()
@font_for_content = 'Big5'
@font_for_footer = 'Big5'
# 한글 출력을 위해 추가된 부분
when 'ko'
extend(PDF_Korean)
AddUHCFont()
@font_for_content = 'UHC'
@font_for_footer = 'UHC'



다음 수정 사항은 폰트에 대한 것인데, 기본 적으로 명조체 출력을 지원하고 있는데 이 부분을 고딕체로 수정하는 내용이다. 명조체로 출력을 원하면 수정하지 않으면 된다.
수정해야할 파일은 vendor\plugins\rfpdf\lib\rfpdf\korean.rb

# HYSMyeongJoStd-Medium-Acro 를 HYGoThic-Medium로 바꾼다.
def AddUHCFont(family='UHC',name='HYGoThic-Medium')
#Add UHC font with proportional Latin
cw=UHC_widths
cMap='KSCms-UHC-H'
registry={'ordering'=>'Korea1','supplement'=>1}
AddCIDFonts(family,name,cw,cMap,registry)
end

def AddUHChwFont(family='UHC-hw',name='HYGoThic-Medium')
#Add UHC font with half-witdh Latin
32.upto(126) do |i|
cw[i.chr]=500
end
cMap='KSCms-UHC-HW-H'
registry={'ordering'=>'Korea1','supplement'=>1}
AddCIDFonts(family,name,cw,cMap,registry)
end



그리고 MultiCell 함수와 MBMultiCell 함수를 chinese.rb에서 복사해 온다.
아래 내용을 복사해 온 내용이다.

  def MultiCell(w,h,txt,border=0,align='L',fill=0)
if(@CurrentFont['type']=='Type0')
MBMultiCell(w,h,txt,border,align,fill)
else
super(w,h,txt,border,align,fill)
end
end

def MBMultiCell(w,h,txt,border=0,align='L',fill=0)
#Multi-byte version of MultiCell()
cw=@CurrentFont['cw']
if(w==0)
w=@w-@rMargin-@x
end
wmax=(w-2*@cMargin)*1000/@FontSize
s=txt.gsub("\r",'')
nb=s.length
if(nb>0 and s[nb-1]=="\n")
nb-=1
end
b=0
if(border)
if(border==1)
border='LTRB'
b='LRT'
b2='LR'
else
b2=''
if(border.to_s.index('L'))
b2+='L'
end
if(border.to_s.index('R'))
b2+='R'
end
b=border.to_s.index('T') ? b2+'T' : b2
end
end
sep=-1
i=0
j=0
l=0
nl=1
while(i<nb)
#Get next character
c=s[i]
#Check if ASCII or MB
ascii=(c<128)
if(c.chr=="\n")
#Explicit line break
Cell(w,h,s[j,i-j],b,2,align,fill)
i+=1
sep=-1
j=i
l=0
nl+=1
if(border and nl==2)
b=b2
end
next
end
if(!ascii)
sep=i
ls=l
elsif(c==' ')
sep=i
ls=l
end
l+=ascii ? (cw[c.chr] || 0) : 1100
if(l>wmax)
#Automatic line break
if(sep==-1 or i==j)
if(i==j)
i+=ascii ? 1 : 3
end
Cell(w,h,s[j,i-j],b,2,align,fill)
else
Cell(w,h,s[j,sep-j],b,2,align,fill)
i=(s[sep]==' ') ? sep+1 : sep
end
sep=-1
j=i
l=0
# nl+=1
if(border and nl==2)
b=b2
end
else
i+=ascii ? 1 : 3
end
end
#Last chunk
if(border and not border.to_s.index('B').nil?)
b+='B'
end
Cell(w,h,s[j,i-j],b,2,align,fill)
@x=@lMargin
end



이제 redmine 을 재시작하고 Gantt Chart 나 작업 목록에서 PDF로 출력을 해보면 한글이 깨끗하게 나오는 걸 확인할 수 있다

Original Post : http://neodreamer-dev.tistory.com/337

No comments :

Post a Comment