| 116 |
116 |
MBMultiCell(w,h,txt,border,align,fill)
|
| 117 |
117 |
else
|
| 118 |
118 |
super(w,h,txt,border,align,fill)
|
| 119 |
|
end
|
|
119 |
end
|
| 120 |
120 |
end
|
| 121 |
121 |
|
| 122 |
122 |
def MBMultiCell(w,h,txt,border=0,align='L',fill=0)
|
| 123 |
|
#Multi-byte version of MultiCell()
|
|
123 |
#Multi-byte version of MultiCell() for UTF-8
|
|
124 |
#Output text with automatic or explicit line breaks
|
| 124 |
125 |
cw=@CurrentFont['cw']
|
| 125 |
126 |
if(w==0)
|
| 126 |
127 |
w=@w-@rMargin-@x
|
| 127 |
|
end
|
|
128 |
end
|
| 128 |
129 |
wmax=(w-2*@cMargin)*1000/@FontSize
|
| 129 |
130 |
s=txt.gsub("\r",'')
|
| 130 |
131 |
nb=s.length
|
| 131 |
132 |
if(nb>0 and s[nb-1]=="\n")
|
| 132 |
133 |
nb-=1
|
| 133 |
|
end
|
|
134 |
end
|
| 134 |
135 |
b=0
|
| 135 |
136 |
if(border)
|
| 136 |
137 |
if(border==1)
|
| ... | ... | |
| 139 |
140 |
b2='LR'
|
| 140 |
141 |
else
|
| 141 |
142 |
b2=''
|
| 142 |
|
if(border.to_s.index('L').nil?)
|
|
143 |
if(border.to_s.index('L'))
|
| 143 |
144 |
b2+='L'
|
| 144 |
|
end
|
| 145 |
|
if(border.to_s.index('R').nil?)
|
|
145 |
end
|
|
146 |
if(border.to_s.index('R'))
|
| 146 |
147 |
b2+='R'
|
| 147 |
|
end
|
| 148 |
|
b=border.to_s.index('T').nil? ? b2+'T' : b2
|
|
148 |
end
|
|
149 |
b=border.to_s.index('T') ? b2+'T' : b2
|
| 149 |
150 |
end
|
| 150 |
151 |
end
|
| 151 |
152 |
sep=-1
|
| 152 |
153 |
i=0
|
| 153 |
154 |
j=0
|
| 154 |
|
l=0
|
|
155 |
l=0 # Automatic line break counter
|
| 155 |
156 |
nl=1
|
| 156 |
157 |
while(i<nb)
|
| 157 |
|
#Get next character
|
| 158 |
|
c=s[i]
|
| 159 |
|
#Check if ASCII or MB
|
| 160 |
|
ascii=(c<128)
|
| 161 |
|
if(c=="\n")
|
| 162 |
|
#Explicit line break
|
|
158 |
case s[i]
|
|
159 |
when 0x00 .. 0x09, 0x0b .. 0x7f # UTF-8 1byte ASCII
|
|
160 |
ascii=true
|
|
161 |
n=1
|
|
162 |
l+=cw[s[i].chr] || 0
|
|
163 |
if(s[i].chr==' ')
|
|
164 |
sep=i
|
|
165 |
end
|
|
166 |
when 0x0a # Explicit line break "\n"
|
| 163 |
167 |
Cell(w,h,s[j,i-j],b,2,align,fill)
|
| 164 |
168 |
i+=1
|
| 165 |
169 |
sep=-1
|
| ... | ... | |
| 168 |
172 |
nl+=1
|
| 169 |
173 |
if(border and nl==2)
|
| 170 |
174 |
b=b2
|
| 171 |
|
end
|
|
175 |
end
|
| 172 |
176 |
next
|
| 173 |
|
end
|
| 174 |
|
if(!ascii)
|
|
177 |
when 0xc0 .. 0xdf # UTF-8 2byte
|
|
178 |
n=2
|
|
179 |
l+=500
|
| 175 |
180 |
sep=i
|
| 176 |
|
ls=l
|
| 177 |
|
elsif(c==' ')
|
|
181 |
when 0xe0 .. 0xee # UTF-8 3byte
|
|
182 |
n=3
|
|
183 |
l+=1000 # Full-width character
|
| 178 |
184 |
sep=i
|
| 179 |
|
ls=l
|
|
185 |
when 0xef # UTF-8 3byte
|
|
186 |
n=3
|
|
187 |
if((s[i+1]==0xbd and (s[i+2]>=0xa1 and s[i+2]<=0xbf)) or (s[i+1]==0xbe and(s[i+2]>=0x80 and s[i+2]<=0x9f)))
|
|
188 |
l+=500 # Half-width katakana (UTF-8: EFBDA1 - EFBDBF, EFBE80 - EFBE9F)
|
|
189 |
else
|
|
190 |
l+=1000 # Full-width character
|
|
191 |
end
|
|
192 |
sep=i
|
|
193 |
when 0xf0 .. 0xf7 # UTF-8 4byte
|
|
194 |
n=4
|
|
195 |
l+=1000
|
|
196 |
sep=i
|
|
197 |
when 0xf8 .. 0xfb # UTF-8 5byte
|
|
198 |
n=5
|
|
199 |
l+=1000
|
|
200 |
sep=i
|
|
201 |
when 0xfc .. 0xfd # UTF-8 6byte
|
|
202 |
n=6
|
|
203 |
l+=1000
|
|
204 |
sep=i
|
|
205 |
else
|
|
206 |
i+=1
|
|
207 |
next
|
| 180 |
208 |
end
|
| 181 |
|
l+=(ascii ? cw[c.chr] : 1000) || 0
|
|
209 |
|
| 182 |
210 |
if(l>wmax)
|
| 183 |
211 |
#Automatic line break
|
| 184 |
212 |
if(sep==-1 or i==j)
|
| 185 |
213 |
if(i==j)
|
| 186 |
|
i+=ascii ? 1 : 2
|
| 187 |
|
end
|
|
214 |
i+=n
|
|
215 |
end
|
| 188 |
216 |
Cell(w,h,s[j,i-j],b,2,align,fill)
|
| 189 |
217 |
else
|
| 190 |
218 |
Cell(w,h,s[j,sep-j],b,2,align,fill)
|
| ... | ... | |
| 196 |
224 |
nl+=1
|
| 197 |
225 |
if(border and nl==2)
|
| 198 |
226 |
b=b2
|
| 199 |
|
end
|
|
227 |
end
|
| 200 |
228 |
else
|
| 201 |
|
i+=ascii ? 1 : 2
|
| 202 |
|
end
|
|
229 |
i+=n
|
|
230 |
if(!ascii)
|
|
231 |
sep=i
|
|
232 |
end
|
|
233 |
end
|
| 203 |
234 |
end
|
| 204 |
235 |
#Last chunk
|
| 205 |
236 |
if(border and not border.to_s.index('B').nil?)
|
| 206 |
237 |
b+='B'
|
| 207 |
|
end
|
|
238 |
end
|
| 208 |
239 |
Cell(w,h,s[j,i-j],b,2,align,fill)
|
| 209 |
240 |
@x=@lMargin
|
| 210 |
241 |
end
|