⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 word.java

📁 J2ME中游戏读文档的类word.java
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
					blankPage = true;
					
					x = f.charWidth(v[index]);							// 第一个字符宽度
					if(isPunctuation(v[index])) {

						// 下句首是标点
						index++;
						// 标点归到上句末
						if(rows > 1) {
							rows--;
//							pages--;
							rei[rows - 1] = index;

//							System.out.println("punction row end " + (rows - 1) + ", " + index);	
						}
//						System.out.println("find a punctuation at first position in a line at: "+ (rows) + " punctuation: " + v[index - 1] + " former word: " + v[index - 2]);
//						continue;
					} else {
						if(y >= height) {
//							System.out.println("next page " + pages);// 文字高度超过显示区域高度,置新页开始行
							pbr[pages++] = rows;
							if(index == len - 2 && v[index] == BEGINOF_FORMAT) {		// 句末两个字符为特殊字符
								pages--;
							}
							y = yOffset - LINE_OFFSET;
						}
						while(x < width && index < len) {				// 设置行,行宽不能超过显示区域宽并且文本未结束
							c = v[index++];												// 取一个字符
							if(c == BEGINOF_FORMAT) {							// 转义字符
								c = v[index];												// 取下一个字符
								if(c == FORMAT[TYPE_NEWLINE]) {			// 换行字符
									index++;
									p = true;
									break;
								} else
									if(c == FORMAT[TYPE_NEWPAGE]) {			// 换页字符
//										if(index + 1 < len) {
											rc[rolls++] = pages;
											r = true;
//											System.out.println("role begin " + (rolls - 1) + ", " + (pages) + ", " + index + " : " + v[index]);
//										}
										if(blankPage && index != 1)
											rbi[rows - 1] += 2;
										if(!blankPage || index == 1) {
											index++;
											p = true;
											y = height;
											rc[rolls - 1] = pages + 1;
//											System.out.println("new role begin " + (rolls - 1) + ", " + (pages + 1) + ", " + (index - 1) + " : " + v[index - 1]);
											break;
										}
										index++;
										blankPage = false;
										
//										System.out.println("next page/role");
										continue;
									}
							}
							blankPage = false;
							x += f.charWidth(v[index < len ? index : len - 1]);		// x坐标加上下一字符宽度
						}
						rei[rows - 1] = p ? index - 2 : index;	// 置该行结束位置,如果该行有转义字符,结束位置前移两位
						
						y += yOffset;
//						System.out.println("row end " + (rows - 1) + ", " + (p ? index - 2 : index));	
					}
																				// 新行起始y坐标	

						r = false;
						p = false;
//						System.out.println("next row " + rows);
					
				}
				} else {																		
					int wordBegin = 0;												
					int wordEnd = 0;													
					int wordWidth = 0;												
					while(index < len) {
						rbi[rows++] = wordBegin;								
						if(y >= height) {												
							pbr[pages++] = rows;
							y = yOffset - LINE_OFFSET;
							
							if(r) {
								rc[rolls++] = pages;
								r = false;
							}
						}
						while(index < len) {										
							c = v[index++];												
							if(c == BEGINOF_FORMAT) {							
								c = v[index];												
								if(c == FORMAT[TYPE_NEWLINE]) {			
									index++;
									p = true;													
									wordBegin = index;								
									wordEnd = index - 2;
									x = wordWidth;										
									wordWidth = 0;
									break;
								} else
								if(c == FORMAT[TYPE_NEWPAGE]) {			
									index++;
									y = height;
									p = true;
									r = true;													
									wordBegin = index;								
									wordEnd = index - 2;
									x = wordWidth;										
									wordWidth = 0;
									break;
								}
							} else
							if(c == SPACE || index >= len) {			
								if(x + wordWidth > width) {					
									x = wordWidth;										
									wordWidth = 0;										
									index--;													
									//System.out.println("break");
									break;
								} else {
									//System.out.println("row");
									x += wordWidth;
									wordWidth = 0;
									wordBegin = index;								
									wordEnd = index - 1;						
									//System.out.println(wordEnd);
								}
							}
							if(!p)
								wordWidth += f.charWidth(v[index < len ? index : len - 1]);
							
						}
						if(index >= len && !p) {								
							wordEnd = len;
						}
						p = false;
						rei[rows - 1] = wordEnd;								
						y += yOffset;														
					}
				}
				
				row_begin = new int[rows];
				System.arraycopy(rbi, 0, row_begin, 0, rows);
				row_end = new int[rows];
				System.arraycopy(rei, 0, row_end, 0, rows);
				
				//System.out.println("::::="+pages);
				
				page_begin = new int[pages];
				
				for(int a=0;a<page_begin.length;a++)
				//System.out.println("oooooooo="+page_begin[a]);
				
				System.arraycopy(pbr, 0, page_begin, 0, pages);
				roll_begin = new int[rolls];
				System.arraycopy(rc, 0, roll_begin, 0, rolls);
				totalRows = rows;
				totalPages = pages;
				totalHeight = yOffset * rows + 10;
				/*
				System.out.print("rolls begin page:");
				for(int i = 0; i < rolls; i++) {
					System.out.print(rc[i] + ", ");
				}
				System.out.println();*/
				/* for test 
				System.out.println("row begin index:");
				for(int i = 0; i < rows; i++) {
					System.out.print(rbi[i] + ", ");
				}
				System.out.println();
				System.out.println("row end index:");
				for(int i = 0; i < rows; i++) {
					System.out.print(rei[i] + ", ");
				}
				System.out.println();
				System.out.println("page begin row:");
				for(int i = 0; i < pages; i++) {
					System.out.print(pbr[i] + ", ");
				}
				System.out.println();
				*/
				break;
		  }
	}
	

	public void settleText(String filename, int type, Font f, int mode, int width, int height) {
		readText(filename, type, null);
		processText(f, mode, width, height);
	}
	
	public void settleText(String filename, int type, String s, Font f, int mode, int width, int height) {
		readText(filename, type, s);
		processText(f, mode, width, height);
	}
	
	public void readText(String filename, int type) {
		readText(filename, type, null);
	}
	
	
	public void readText(String filename, int type, String s) {
		try {
			DataInputStream dis = new DataInputStream("a".getClass().
																getResourceAsStream(filename));
      int sLen = SYMBOL[type].length;
      char[] symbol = null;
      if(type == TYPE_DIALOG) {
      	int l = sLen;
      	sLen += s.length();
      	symbol = new char[sLen];
      	System.arraycopy(SYMBOL[type], 0, symbol, 0, l);
      	char[] t = s.toCharArray();
      	System.arraycopy(t, 0, symbol, l, t.length);
      } else {
      	symbol = new char[sLen];
      	System.arraycopy(SYMBOL[type], 0, symbol, 0, sLen);
      }
      
      char[] c = new char[MAX_SYMBOLS];
      char[] d = new char[MAX_TEXT];
      char temp;
			int c_len = 0, d_len = 0;
			boolean textSpoted = false, textEnd = false, textStart = false;
			
			readChar(dis);
			while(true) {
				try {
					temp = readChar(dis);														
					if(temp != 10 && temp != 13) {									
						if(temp == BEGINOF_PART1) {										
							temp = readChar(dis);
							if(temp == BEGINOF_PART2) {									
								while(true) {
									c[c_len++] = readChar(dis);
									if(c[c_len - 1] == ENDOF) {							
										c_len--;
										if(c_len == sLen) {
											for(int i = 0; i < c_len; i++) {
												if(c[i] != symbol[i]) {
													c_len = 0;
													break;
												}
											}
											if(c_len != 0) {
												if(textSpoted) {
													textEnd = true;									
												} else {
													textSpoted = true;							
												}
											}
										}
										c_len = 0;
										break;
									}
								}
							}
						} else {
							if(textSpoted) textStart = true;
						}
						if(textSpoted && textStart) {									
							if(textEnd) {
								break;
							}
							d[d_len++] = temp;
						}
					}
				} catch(EOFException e) {
					break;
					}
			}
      dis.close();
  		
  		value = null;
  		count = d_len;
  		value = new char[count];
  		System.arraycopy(d, 0, value, 0, count);
  		System.gc();
    } catch(IOException e){
    		throw new IllegalArgumentException();
      }
  }
   
	public static final char readChar(DataInputStream dis) throws IOException {
    int a = dis.read();
    int b = dis.read();
    if((a | b) < 0)
    	throw new EOFException();
    else
    	return (char)((b << 8) + (a << 0));
  }
	
	public int getPageHeight(int page, Font font) {
		int lineNumber = (page < totalPages ? page_begin[page] - 1 : totalRows) - page_begin[page - 1];
		
		return lineNumber * font.getHeight() + (lineNumber -1) * LINE_OFFSET;
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -