# kuten 94x94 matrix (JISX0208) JIS.start <- "\033$B" JIS.end <- "\033(B" JIS.name <- "ISO-2022-JP" JIS.range <- c( 1:2, # symbol 147 chars 3, # Alpha Numeric 62 chars 4, # HiraKana 83 chars 5, # KataKana 86 chars 6, # Greek 48 chars 7, # Cyrillic 66 chars 8, # Line 32 chars # 9:15, # undefined or machine dependence, 13 ms only. 16:47,# JIS1 2965 chars 48:84 # JIS2 3390 chars # 85:94 # undefined or machine dependence ) # kuten 94x94 matrix (KS X 1001) KS.start <- "\033$)C\016" KS.end <- "\017" KS.name <- "ISO-2022-KR" KS.range <- c( 1:2, # symbol 3, # Alpha Numeric 4, # hangle 5, # Greek 6, # line 7, # unit of credit 8, # circle symbol 9, # parenthetic symbol 10, # Hira-kana 11, # Kata-kana 12, # Cyrillic 16:40,# hangle 42:93 # Kanji ) GB.start <- "\033$)E\016" GB.end <- "\017" GB.name <- "ISO-2022-CN-EXT" GB.range <- c(# ISO-IR-165:1992 1, # symbol 2, # numeric 3, # Alpha Numeric 4, # Hira-kana 5, # Kata-kana 6, # Greek 7, # Cyrillic 8, # Wide-pinyin 9, # line 10, # Harf-ascii 11, # Harf-pinyin 12, # Kanji 13, # GB7589-87 14, # GN7589-87 15, # non Kanji and Kanji 16:55,# Kanji level1 56:87,# Kanji level2 # 88:89,# undefined 90:94 # GB7589-87 ) toInt<-function(x) as.integer(charToRaw(x)) BIG5.start <- "" BIG5.end <- "" BIG5.name <- "BIG5" BIG5.range <- c( seq(toInt("\xa1"),toInt("\xc6")), # level 1 seq(toInt("\xc9"),toInt("\xf9")) # level 2 ) kuplot<-function(ku=1,start="\033$B",end="\033(B",kutenname="ISO-2022-JP",mode="d") { kutenToRaw<-function(ku=1,ten=1) { if(mode=="d") return(as.raw(as.integer(structure(c(32+ku,32+ten))))) return(as.raw(as.integer(structure(c(ku,ten))))) } if(mode=="d") TenRange <- c(1:94) else TenRange <- c(64:126,161:254) par(mar=c(1,1,2,1)) par(ps=as.integer(par()$pin[1]*2)) if(mode=="d"){ plot(0:15,xlim=c(0,15), ylim=c(-5.5,0), type="n", xlab="", ylab="", xaxt="n", yaxt="n") title(paste(kutenname," encoding ", ku, "ku")) grid(16, 6, lty=1) }else{ plot(0:15,xlim=c(0,15), ylim=c(-9.4,-0.1), type="n", xlab="", ylab="", xaxt="n", yaxt="n") title(paste(kutenname," encoding ", as.character(as.raw(structure(ku))), "ku")) grid(16, 10, lty=1) } par(xpd=T) text(2.5, par()$usr[3]-.3, cex=.6, col="red",kutenname) text(7.5, par()$usr[3]-.3, cex=.6, col="blue",localeToCharset()[1]) text(12.5, par()$usr[3]-.3, cex=.6, col="gray","UCS-2") par(xpd=F) for(ten in TenRange){ tentext <- ten x <- ten %% 16 y <- ten if ( mode == "x" ){ y <- ifelse(y>127,y-32,y) y <- y - 64 tentext <- as.character(as.raw(structure(tentext))) } y <- y %/% 16 kutenhex<-rawToChar(kutenToRaw(ku,ten)) str<-paste(start,kutenhex,end,sep="") str<-iconv(str,kutenname) if(strwidth(str)>0){ text(x, -y+.15, cex=.4, col="darkgreen",tentext) text(x, -y, str) text(x, -y-.2, cex=.6, col="red",paste(as.character(kutenToRaw(ku,ten)),collapse="")) text(x, -y-.4, cex=.6, col="blue",paste(as.character(charToRaw(str)),collapse="")) text(x, -y-.6, cex=.6, col="gray",paste(as.character(charToRaw(iconv(str,"","UCS-2BE"))),collapse="")) } } } pdf("CJK.pdf",paper="a4r", width=0, height=0) if ( localeToCharset()[1] == "UTF-8" || localeToCharset()[1] == "CP936" || localeToCharset()[1] == "GBK" || localeToCharset()[1] == "GB2312" || localeToCharset()[1] == "GB18030" || localeToCharset()[1] == "EUC-CN" ){ par(mfrow=c(3,3),family="GB1") lapply(GB.range,function(x)kuplot(x,start=GB.start,end=GB.end,kutenname=GB.name)) } if ( localeToCharset()[1] == "UTF-8" || localeToCharset()[1] == "CP950" || localeToCharset()[1] == "EUC-TW" ){ par(mfrow=c(2,3),family="CNS1") lapply(BIG5.range,function(x)kuplot(x,start=BIG5.start,end=BIG5.end,kutenname=BIG5.name,mode="x")) } if ( localeToCharset()[1] == "UTF-8" || length(grep("^ja_",ignore.case=T,Sys.getlocale("LC_CTYPE")))!=0 || length(grep("^japanese",ignore.case=T,Sys.getlocale("LC_CTYPE")))!=0 ){ par(mfrow=c(3,3),family="Japan1") lapply(JIS.range,function(x)kuplot(x,start=JIS.start,end=JIS.end,kutenname=JIS.name)) } if ( localeToCharset()[1] == "UTF-8" || length(grep("^ko_",ignore.case=T,Sys.getlocale("LC_CTYPE")))!=0 || length(grep("^korean",ignore.case=T,Sys.getlocale("LC_CTYPE")))!=0 ){ par(mfrow=c(3,3),family="Korea1") lapply(KS.range,function(x)kuplot(x,start=KS.start,end=KS.end,kutenname=KS.name)) } dev.off()