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

📄 htmlworker.java

📁 源码包含生成 PDF 和 HTML 的类库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				if (!h.containsKey(ElementTags.FACE)) {					h.put(ElementTags.FACE, "Courier");				}				cprops.addToChain(tag, h);				isPRE = true;				return;			}			if (tag.equals("p")) {				cprops.addToChain(tag, h);				currentParagraph = FactoryProperties.createParagraph(h);				return;			}			if (tag.equals("tr")) {				if (pendingTR)					endElement("tr");				skipText = true;				pendingTR = true;				cprops.addToChain("tr", h);				return;			}			if (tag.equals("td") || tag.equals("th")) {				if (pendingTD)					endElement(tag);				skipText = false;				pendingTD = true;				cprops.addToChain("td", h);				stack.push(new IncCell(tag, cprops));				return;			}			if (tag.equals("table")) {				cprops.addToChain("table", h);				IncTable table = new IncTable(h);				stack.push(table);				tableState.push(new boolean[] { pendingTR, pendingTD });				pendingTR = pendingTD = false;				skipText = true;				return;			}		} catch (Exception e) {			throw new ExceptionConverter(e);		}	}	public void endElement(String tag) {		if (!tagsSupported.containsKey(tag))			return;		try {			String follow = (String) FactoryProperties.followTags.get(tag);			if (follow != null) {				cprops.removeChain(follow);				return;			}			if (tag.equals("font") || tag.equals("span")) {				cprops.removeChain(tag);				return;			}			if (tag.equals("a")) {				if (currentParagraph == null) {					currentParagraph = new Paragraph();				}				boolean skip = false;				if (interfaceProps != null) {					ALink i = (ALink) interfaceProps.get("alink_interface");					if (i != null)						skip = i.process(currentParagraph, cprops);				}				if (!skip) {					String href = cprops.getProperty("href");					if (href != null) {						ArrayList chunks = currentParagraph.getChunks();						int size = chunks.size();						for (int k = 0; k < size; ++k) {							Chunk ck = (Chunk) chunks.get(k);							ck.setAnchor(href);						}					}				}				Paragraph tmp = (Paragraph) stack.pop();				Phrase tmp2 = new Phrase();				tmp2.add(currentParagraph);				tmp.add(tmp2);				currentParagraph = tmp;				cprops.removeChain("a");				return;			}			if (tag.equals("br")) {				return;			}			if (currentParagraph != null) {				if (stack.empty())					document.add(currentParagraph);				else {					Object obj = stack.pop();					if (obj instanceof TextElementArray) {						TextElementArray current = (TextElementArray) obj;						current.add(currentParagraph);					}					stack.push(obj);				}			}			currentParagraph = null;			if (tag.equals(HtmlTags.UNORDEREDLIST)					|| tag.equals(HtmlTags.ORDEREDLIST)) {				if (pendingLI)					endElement(HtmlTags.LISTITEM);				skipText = false;				cprops.removeChain(tag);				if (stack.empty())					return;				Object obj = stack.pop();				if (!(obj instanceof com.lowagie.text.List)) {					stack.push(obj);					return;				}				if (stack.empty())					document.add((Element) obj);				else					((TextElementArray) stack.peek()).add(obj);				return;			}			if (tag.equals(HtmlTags.LISTITEM)) {				pendingLI = false;				skipText = true;				cprops.removeChain(tag);				if (stack.empty())					return;				Object obj = stack.pop();				if (!(obj instanceof ListItem)) {					stack.push(obj);					return;				}				if (stack.empty()) {					document.add((Element) obj);					return;				}				Object list = stack.pop();				if (!(list instanceof com.lowagie.text.List)) {					stack.push(list);					return;				}				ListItem item = (ListItem) obj;				((com.lowagie.text.List) list).add(item);				ArrayList cks = item.getChunks();				if (!cks.isEmpty())					item.getListSymbol()							.setFont(((Chunk) cks.get(0)).getFont());				stack.push(list);				return;			}			if (tag.equals("div") || tag.equals("body")) {				cprops.removeChain(tag);				return;			}			if (tag.equals(HtmlTags.PRE)) {				cprops.removeChain(tag);				isPRE = false;				return;			}			if (tag.equals("p")) {				cprops.removeChain(tag);				return;			}			if (tag.equals("h1") || tag.equals("h2") || tag.equals("h3")					|| tag.equals("h4") || tag.equals("h5") || tag.equals("h6")) {				cprops.removeChain(tag);				return;			}			if (tag.equals("table")) {				if (pendingTR)					endElement("tr");				cprops.removeChain("table");				IncTable table = (IncTable) stack.pop();				PdfPTable tb = table.buildTable();				tb.setSplitRows(true);				if (stack.empty())					document.add(tb);				else					((TextElementArray) stack.peek()).add(tb);				boolean state[] = (boolean[]) tableState.pop();				pendingTR = state[0];				pendingTD = state[1];				skipText = false;				return;			}			if (tag.equals("tr")) {				if (pendingTD)					endElement("td");				pendingTR = false;				cprops.removeChain("tr");				ArrayList cells = new ArrayList();				IncTable table = null;				while (true) {					Object obj = stack.pop();					if (obj instanceof IncCell) {						cells.add(((IncCell) obj).getCell());					}					if (obj instanceof IncTable) {						table = (IncTable) obj;						break;					}				}				table.addCols(cells);				table.endRow();				stack.push(table);				skipText = true;				return;			}			if (tag.equals("td") || tag.equals("th")) {				pendingTD = false;				cprops.removeChain("td");				skipText = true;				return;			}		} catch (Exception e) {			throw new ExceptionConverter(e);		}	}	public void text(String str) {		if (skipText)			return;		String content = str;		if (isPRE) {			if (currentParagraph == null) {				currentParagraph = FactoryProperties.createParagraph(cprops);			}			Chunk chunk = factoryProperties.createChunk(content, cprops);			currentParagraph.add(chunk);			return;		}		if (content.trim().length() == 0 && content.indexOf(' ') < 0) {			return;		}		StringBuffer buf = new StringBuffer();		int len = content.length();		char character;		boolean newline = false;		for (int i = 0; i < len; i++) {			switch (character = content.charAt(i)) {			case ' ':				if (!newline) {					buf.append(character);				}				break;			case '\n':				if (i > 0) {					newline = true;					buf.append(' ');				}				break;			case '\r':				break;			case '\t':				break;			default:				newline = false;				buf.append(character);			}		}		if (currentParagraph == null) {			currentParagraph = FactoryProperties.createParagraph(cprops);		}		Chunk chunk = factoryProperties.createChunk(buf.toString(), cprops);		currentParagraph.add(chunk);	}	public boolean add(Element element) throws DocumentException {		objectList.add(element);		return true;	}	public void clearTextWrap() throws DocumentException {	}	public void close() {	}	public boolean newPage() {		return true;	}	public void open() {	}	public void resetFooter() {	}	public void resetHeader() {	}	public void resetPageCount() {	}	public void setFooter(HeaderFooter footer) {	}	public void setHeader(HeaderFooter header) {	}	public boolean setMarginMirroring(boolean marginMirroring) {		return true;	}	public boolean setMargins(float marginLeft, float marginRight,			float marginTop, float marginBottom) {		return true;	}	public void setPageCount(int pageN) {	}	public boolean setPageSize(Rectangle pageSize) {		return true;	}	public static final String tagsSupportedString = "ol ul li a pre font span br p div body table td th tr i b u sub sup em strong s strike"			+ " h1 h2 h3 h4 h5 h6 img";	public static final HashMap tagsSupported = new HashMap();	static {		StringTokenizer tok = new StringTokenizer(tagsSupportedString);		while (tok.hasMoreTokens())			tagsSupported.put(tok.nextToken(), null);	}	/**	 * 	 * This method is replace with Markup.lengthParse	 * @deprecated	 * @see com.lowagie.text.html.Markup#parseLength(String string)	 * @param txt	 * @param c	 * @return float value of length	 */	private static float lengthParse(String txt, int c) {		if (txt == null)			return -1;		if (txt.endsWith("%")) {			float vf = Float.parseFloat(txt.substring(0, txt.length() - 1));			return vf;		}		if (txt.endsWith("px")) {			float vf = Float.parseFloat(txt.substring(0, txt.length() - 2));			return vf;		}		int v = Integer.parseInt(txt);		return (float) v / c * 100f;	}}

⌨️ 快捷键说明

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