Created
March 21, 2018 18:26
-
-
Save vuski/d467d9b209ae0db6ecb320620e6e3fe0 to your computer and use it in GitHub Desktop.
attached
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.BufferedWriter; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.io.OutputStreamWriter; | |
import java.util.ArrayList; | |
public class EditSVGFiles { | |
public static void main(String[] args) throws IOException { | |
String[][] layer = { | |
{"1","Layer 1"}, | |
{"2","Layer 2"}, | |
{"3","녹지"}, | |
{"4","도로"}, | |
{"5","하천"}, | |
{"6","다리"}, | |
{"7","건물"}, | |
{"8","지하철역"}, | |
{"9","지하철 선로"}, | |
{"10","행정동 경계"}, | |
{"11","초등학교"}, | |
{"12","100m 격자"}, | |
{"13","Layer 22"}, | |
{"14","지도프레임"}, | |
{"15","범례"}, | |
}; | |
String sourceLocation = "V:\\source\\"; | |
String targetLocation = "V:\\target\\"; | |
ArrayList<String> fileNameList = getFileNameList(sourceLocation, ".svg"); | |
for (String fileName : fileNameList ) { | |
String text = readFile(sourceLocation+fileName, "utf-8"); | |
//폰트 이름 변경 | |
text = text.replaceAll("나눔고딕","NanumGothicBold"); | |
//레이어 이름 변경 | |
for (int i=0 ; i<layer.length ; i++) { | |
String fromText = "Layer "+layer[i][0]; | |
String toText = layer[i][1]; | |
text = text.replaceAll(fromText, toText); | |
} | |
//stroke-width 수정 | |
StringBuffer result = new StringBuffer(); | |
int iE = 0; | |
String target = "stroke-width=\""; | |
int iS = text.indexOf(target); | |
while (iS!=-1) { | |
result.append(text.substring(iE, iS+target.length())); | |
iE = text.indexOf("\"",iS+target.length()); | |
float value = Float.parseFloat(text.substring(iS+target.length(),iE)); | |
value = value/3.07087f; | |
result.append(""+value); | |
iS = text.indexOf(target,iE); | |
} | |
result.append(text.substring(iE)); | |
FileOutputStream fos = new FileOutputStream(targetLocation+fileName); | |
OutputStreamWriter osw = new OutputStreamWriter(fos,"UTF-8"); | |
BufferedWriter bw = new BufferedWriter(osw); | |
bw.write(result.toString()); | |
bw.close(); | |
System.out.println(fileName); | |
} | |
} | |
public static ArrayList<String> getFileNameList(String fileLocation, String extension) { | |
ArrayList<String> fileNames = new ArrayList<String>(); | |
File[] files = (new File(fileLocation)).listFiles(); | |
if(!(files.length <= 0)){ | |
for (int i = 0; i < files.length; i++) { | |
if(files[i].isFile() && files[i].getName().endsWith(extension)) fileNames.add(files[i].getName()); | |
} | |
} | |
return fileNames; | |
} | |
public static String readFile(String fileName, String charset) throws IOException { | |
FileInputStream fis = new FileInputStream(fileName); | |
InputStreamReader isr = new InputStreamReader(fis,charset); | |
BufferedReader br = new BufferedReader(isr); | |
StringBuffer temp = new StringBuffer(); | |
String line; | |
while ((line=br.readLine()) != null) { | |
temp.append(line); | |
} | |
br.close(); | |
return temp.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment