summaryrefslogtreecommitdiff
path: root/systems/android/hktex/HKtex2/src/worker4math/hktex2/Drawblock.java
blob: e60e3ad724107108091d624de16a0071f070c4d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//
// Latex Project Public Licence (lppl1.3) applies
// Originally written by Kwanleung Tse
// First Release : 1st July, 2014
// Last Update : 27th September, 2014
//
//
package worker4math.hktex2;

import java.util.ArrayList;
import java.util.HashMap;

import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.Canvas;
import android.graphics.Paint;

public class Drawblock {

    float moleculeheight = 0.0f;
    float moleculelength = 0.0f;
    
	public  void drawblock(Canvas canvas, 
			ArrayList<String> block,
			ArrayList<Float> xpos,
			ArrayList<Float> ypos,
			ArrayList<String> attribute,
			HashMap<String, String> symbolunicode, HashMap<String, Integer> symboltype, HashMap<String, String> matchsymbol, 
			ArrayList<Typeface> tf ) {
      	
		int i,j1,ii,i2=0;
		int numatom = 0;
	    int fontcolor=0;
	    
    	String key = "";
		  
	    char temp = ' ';
	    char charExclaim = '!';

	    Colorfile color = new Colorfile();
	    color.colorfile();
      	  
	    Paint mPaint = new Paint();
	    mPaint.setColor(Color.BLACK);    
	    Paint lPaint= new Paint();
	    Paint sPaint = new Paint();
	    sPaint.setTypeface(tf.get(4));

  	  
	    numatom = block.size();
  	
	    for (i=0;i<=numatom-1;i++){
	    	if (attribute.get(i).charAt(0)=='g'){
	    		canvas.drawBitmap(DocumentBitmap.bitmap.get(block.get(i)), xpos.get(i), ypos.get(i), null);
	    	} else if (attribute.get(i).charAt(0)=='G'){
	    		canvas.drawBitmap(DocumentBitmap.bitmap.get(block.get(i)), xpos.get(i), ypos.get(i), null);
	    	} else if (attribute.get(i).charAt(0)=='1'){
	    		mPaint.setUnderlineText(false);mPaint.setStrikeThruText(false);mPaint.setTextSkewX(0);mPaint.setAlpha(255);mPaint.setShadowLayer(0,0,0,0);
	    		mPaint.setTextSize(Integer.parseInt(attribute.get(i).substring(1,4)));
        	
	    		Long il=Long.parseLong(attribute.get(i).substring(9,17),16);
	    		ii=il.intValue();
	    		mPaint.setColor(ii);
	    		mPaint.setTypeface(tf.get(Integer.parseInt(attribute.get(i).substring(4,7))));
	    		canvas.drawText(block.get(i), xpos.get(i), ypos.get(i), mPaint);
	    	} else {
	    		String atom = block.get(i);	           
  	
	    		Float positionx = xpos.get(i);	     	            	  
	    		Float positiony = ypos.get(i);	    
	    		String textattribute=attribute.get(i);
  	  
	    		if (textattribute.charAt(0)=='0'){
	    			if (textattribute.charAt(18) == '1'){mPaint.setUnderlineText(true);sPaint.setUnderlineText(true);} else {mPaint.setUnderlineText(false);sPaint.setUnderlineText(false);};
	    			if (textattribute.charAt(19) == '1'){mPaint.setStrikeThruText(true);sPaint.setStrikeThruText(true);} else{mPaint.setStrikeThruText(false);sPaint.setStrikeThruText(false);} ;
	    			if (textattribute.substring(20,25)!="+0.00"){mPaint.setTextSkewX(Float.parseFloat(textattribute.substring(20,25)));sPaint.setTextSkewX(Float.parseFloat(textattribute.substring(20,25)));}
	    			else {mPaint.setTextSkewX(0);sPaint.setTextSkewX(0);} ;
	    			if (textattribute.substring(25,29)!="0xFF"){ mPaint.setAlpha(Integer.parseInt(textattribute.substring(27,29),16));sPaint.setAlpha(Integer.parseInt(textattribute.substring(27,29),16));}
	    			else {mPaint.setAlpha(255);sPaint.setAlpha(255);};
	    			if (textattribute.charAt(29) != '0'){
	    				Long il=Long.parseLong(color.colorinteger.get(textattribute.substring(32)).substring(2),16);
	    				fontcolor=il.intValue();
	    				mPaint.setShadowLayer(Float.parseFloat(textattribute.substring(29,30)),Float.parseFloat(textattribute.substring(30,31)),
	    						Float.parseFloat(textattribute.substring(31,32)),fontcolor);
	    				sPaint.setShadowLayer(Float.parseFloat(textattribute.substring(29,30)),Float.parseFloat(textattribute.substring(30,31)),
	    						Float.parseFloat(textattribute.substring(31,32)),fontcolor);
	    			} else {
	    				mPaint.setShadowLayer(0,0,0,0);sPaint.setShadowLayer(0,0,0,0);  		  
	    			};
	    		} else {
	    			mPaint.setUnderlineText(false);sPaint.setUnderlineText(false);mPaint.setStrikeThruText(false);sPaint.setStrikeThruText(false);
	    			mPaint.setShadowLayer(0,0,0,0);sPaint.setShadowLayer(0,0,0,0);mPaint.setAlpha(255);sPaint.setAlpha(255);
	    			mPaint.setTextSkewX(0);sPaint.setTextSkewX(0);
	    		}
	    		mPaint.setTextSize(Integer.parseInt(attribute.get(i).substring(1,4)));
	    		Long il=Long.parseLong(attribute.get(i).substring(9,17),16);
	    		fontcolor=il.intValue();
        
	    		j1=0;
	    		for (int j=0; j1<=atom.length()-1 && j<1000; j++){
      	  
	    			temp = atom.charAt(j1);
	    			if (temp != charExclaim) {
             
	    				int fontinteger=Integer.parseInt(attribute.get(i).substring(4,7));
          	
	    				mPaint.setColor(fontcolor);
	    				mPaint.setTypeface(tf.get(fontinteger));
	    				canvas.drawText(Character.toString(temp), positionx, positiony, mPaint);
       	  
	    				float tempsize = mPaint.measureText(Character.toString(temp));
	    				positionx = positionx + tempsize;
	    				j1++;
	    			}  else if (temp == charExclaim) {
	    				key ="";
	    				for (i2=j1+1;!(atom.charAt(i2)==' ');i2++){
	    					key = key + atom.charAt(i2);
	    				}	                 			
	    				if (symboltype.containsKey(key) && (symboltype.get(key)<=13 ||symboltype.get(key)>=16) ){
	    					sPaint.setTextSize(Integer.parseInt(attribute.get(i).substring(1,4)));
	    					sPaint.setColor(fontcolor);
	    					canvas.drawText(symbolunicode.get(key), positionx, positiony, sPaint); 
	    					j1=j1+key.length()+2;     			  
	    				}else if (symboltype.containsKey(key) && (symboltype.get(key)==14 ||  symboltype.get(key)==15)){
	    					mPaint.setTextSize(Integer.parseInt(attribute.get(i).substring(1,4))); 
	    					mPaint.setTypeface(tf.get(5));
	    					mPaint.setColor(fontcolor);
	    					canvas.drawText(symbolunicode.get(key), positionx, positiony, mPaint);  
	    					j1=j1+key.length()+2;
	    				}else if (key.equals("hlin")){
	    					lPaint.setColor(fontcolor);
	    					int strokewidth=1;
	    					lPaint.setStrokeWidth(strokewidth);
	    					float tempy=Integer.parseInt(attribute.get(i).substring(1,4));
	    					canvas.drawLine(positionx, positiony, positionx+tempy, positiony, lPaint);
	    					j1+=6;	  
	    				}else if (key.equals("vlin")){
	    					lPaint.setColor(fontcolor);
	    					int strokewidth=1;
	    					lPaint.setStrokeWidth(strokewidth);
	    					float tempy=Integer.parseInt(attribute.get(i).substring(1,4));
	    					canvas.drawLine(positionx, positiony, positionx, positiony-tempy, lPaint);
            			  j1+=6;	  
	    				}else if (key.equals("dno")){
//  do nothing
	    					j1+=5;
	    				}  else if (key.equals("hsp")){	                 	    	 
	    					j1+=5;            		   
	    				} else if (key.equals("vsp")){	                 	    	 
	    					j1+=5;	              		   
	    				}else if (key.equals("gho")){	        	    	
	    					j1+=5;	    	              		   
	    				}else  {       	    	
	    					mPaint.setColor(fontcolor);
	    					mPaint.setTypeface(tf.get(0));
	    					canvas.drawText(symbolunicode.get(key), positionx, positiony, mPaint);	  		           

	    					j1=j1+key.length()+2;                      }
       	     
	    			}   
	    		} }}
           } 
    }