Revision 23971

View differences:

branches/v10/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/dxf/DXFMemoryDriver.java
58 58
import java.util.ArrayList;
59 59
import java.util.Date;
60 60
import java.util.Properties;
61
import java.util.regex.Matcher;
62
import java.util.regex.Pattern;
61 63

  
62 64
import javax.swing.table.DefaultTableModel;
63 65

  
......
269 271
					int auxInt = Integer.parseInt(fea.getProp("color"));
270 272
					auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
271 273
					auxRow[ID_FIELD_TEXT] = ValueFactory
272
							.createValue(new String(fea.getProp("text")));
274
							.createValue(getTextFromMtext(fixUnicode(new String(fea.getProp("text")))));
273 275
					heightText = Float.parseFloat(fea.getProp("textHeight"));
274 276
					auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory
275 277
							.createValue(heightText);
......
343 345
					int auxInt = Integer.parseInt(fea.getProp("color"));
344 346
					auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
345 347
					auxRow[ID_FIELD_TEXT] = ValueFactory
346
							.createValue(new String(fea.getProp("text")));
348
							.createValue(getTextFromMtext(fixUnicode(new String(fea.getProp("text")))));
347 349
					heightText = Float.parseFloat(fea.getProp("textHeight"));
348 350
					auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory
349 351
							.createValue(heightText);
......
915 917
	    	return Types.VARCHAR;
916 918
	    }
917 919
	}
920
	/**
921
	 * Replace the Unicode characters formatted for AutoCAD
922
	 * by the Unicode character corresponding
923
	 *
924
	 * @param s
925
	 *         Multiline text formatted with Autocad.
926
	 *
927
	 * @return Text fixed
928
	 */
929
	private String fixUnicode(String s){
930
		// Viene una cadena tal que as? CA\U+00D1O1
931
		// (una especie de formato Unicode de Autocad)
932
		// y hay que devolver CA?O1
918 933

  
934
		String s2 = "";
935
		String patron = "(\\\\[U][+])([0-9A-Fa-f]{4})";
936
		Pattern compiledPatron = Pattern.compile(patron);
937
		Matcher matcher = compiledPatron.matcher(s);
938

  
939
		int lastEnd = 0;
940
		while(matcher.find()){
941
			int start = matcher.start();
942
			int end = matcher.end();
943

  
944
			String code = matcher.group(2);
945
			String hexa = "0x"+code;
946
			int caracter = Integer.decode(hexa).intValue();
947

  
948
			s2 = s2 + s.substring(lastEnd, start) + (char)caracter;
949
			lastEnd = end;
950
		}
951
		s2 = s2 + s.substring(lastEnd);
952
		return s2;
953
	}
954

  
955

  
956
	/**
957
	 * Extracts the text of a multiline text formatted with Autocad
958
	 *
959
	 * @param mtext
960
	 *            Multiline text formatted with Autocad.
961
	 *            ACAD seems to add braces ({ }) and backslash-P's
962
	 *            to indicate paragraphs, as well as fonts and / or sizes.
963
	 *
964
	 * @return Text extracted
965
	 */
966
	private String getTextFromMtext(String mtext){
967
		String text = "";
968
		String patron = "([^{]*)([{][^;]*[;])([^}]*)([}])";
969
		Pattern compiledPatron = Pattern.compile(patron);
970
		Matcher matcher = compiledPatron.matcher(mtext);
971
		int lastEnd = 0;
972
		while(matcher.find()){
973
			for (int i=1; i<=matcher.groupCount(); i++){
974
				if (i==1){
975
					text = text + matcher.group(i);
976
				}
977
				if (i%4 == 3){
978
					String grupo = matcher.group(i).replace("\\P", " \n");
979
					if(grupo.contains(";")){
980
						String[] ss = grupo.split(";");
981
						text = text + ss[ss.length-1];
982
					} else {
983
						text = text + grupo;
984
					}
985
				}
986
			}
987
			lastEnd = matcher.end();
988
		}
989
		text = text + mtext.substring(lastEnd);
990
		return text;
991
	}
919 992
}

Also available in: Unified diff