📄 hdfobjectfactory.java
字号:
int parPlcfLen = parPlcf.length(); int currentPageIndex = _parParsingState.getCurrentPageIndex(); FormattedDiskPage fkp = _parParsingState.getFkp(); int currentPapxIndex = _parParsingState.getCurrentPropIndex(); int currentArraySize = fkp.size(); do { if (currentPapxIndex < currentArraySize) { int parStart = fkp.getStart(currentPapxIndex); int parEnd = fkp.getEnd(currentPapxIndex); byte[] papx = fkp.getGrpprl(currentPapxIndex); _listener.paragraph(new PapxNode(Math.max(parStart, start), Math.min(parEnd, end), papx)); initCharacterProperties(charOffset, charPlcf, Math.max(start, parStart), Math.min(parEnd, end)); if (parEnd < end) { currentPapxIndex++; } else { //save the state _parParsingState.setState(currentPageIndex, fkp, currentPapxIndex); break; } } else { int currentParPage = LittleEndian.getInt(_tableBuffer, parOffset + parPlcf.getStructOffset(++currentPageIndex)); byte byteFkp[] = new byte[512]; System.arraycopy(_mainDocument, (currentParPage * 512), byteFkp, 0, 512); fkp = new PAPFormattedDiskPage(byteFkp); currentPapxIndex = 0; currentArraySize = fkp.size(); } } while(currentPageIndex < parPlcfLen); } /** * initializes the CharacterProperties BTree */ /*private void initCharacterProperties() { int charOffset = _fib.getFcPlcfbteChpx(); int charPlcSize = _fib.getLcbPlcfbteChpx(); //int arraySize = (charPlcSize - 4)/8; //first we must go through the bin table and find the fkps for(int x = 0; x < arraySize; x++) { //get page number(has nothing to do with document page) //containing the chpx for the paragraph int PN = LittleEndian.getInt(_tableBuffer, charOffset + (4 * (arraySize + 1) + (4 * x))); byte[] fkp = new byte[512]; System.arraycopy(_mainDocument, (PN * 512), fkp, 0, 512); //take each fkp and get the chpxs int crun = LittleEndian.getUnsignedByte(fkp, 511); for(int y = 0; y < crun; y++) { //get the beginning fc of each paragraph text run int fcStart = LittleEndian.getInt(fkp, y * 4); int fcEnd = LittleEndian.getInt(fkp, (y+1) * 4); //get the offset in fkp of the papx for this paragraph int chpxOffset = 2 * LittleEndian.getUnsignedByte(fkp, ((crun + 1) * 4) + y); //optimization if offset == 0 use "Normal" style if(chpxOffset == 0) { _characterRuns.add(new ChpxNode(fcStart, fcEnd, new byte[0])); continue; } int size = LittleEndian.getUnsignedByte(fkp, chpxOffset); byte[] chpx = new byte[size]; System.arraycopy(fkp, ++chpxOffset, chpx, 0, size); //_papTable.put(new Integer(fcStart), papx); _characterRuns.add(new ChpxNode(fcStart, fcEnd, chpx)); } } }*/ /** * intializes the Paragraph Properties BTree */ private void initParagraphProperties() { //paragraphs int parOffset = _fib.getFcPlcfbtePapx(); int parPlcSize = _fib.getLcbPlcfbtePapx(); //characters int charOffset = _fib.getFcPlcfbteChpx(); int charPlcSize = _fib.getLcbPlcfbteChpx(); PlexOfCps charPlcf = new PlexOfCps(charPlcSize, 4); PlexOfCps parPlcf = new PlexOfCps(parPlcSize, 4); //Initialize character property stuff int currentCharPage = LittleEndian.getInt(_tableBuffer, charOffset + charPlcf.getStructOffset(0)); int charPlcfLen = charPlcf.length(); int currentPageIndex = 0; byte[] fkp = new byte[512]; System.arraycopy(_mainDocument, (currentCharPage * 512), fkp, 0, 512); CHPFormattedDiskPage cfkp = new CHPFormattedDiskPage(fkp); int currentChpxIndex = 0; int currentArraySize = cfkp.size(); int arraySize = parPlcf.length(); //first we must go through the bin table and find the fkps for(int x = 0; x < arraySize; x++) { int PN = LittleEndian.getInt(_tableBuffer, parOffset + parPlcf.getStructOffset(x)); fkp = new byte[512]; System.arraycopy(_mainDocument, (PN * 512), fkp, 0, 512); PAPFormattedDiskPage pfkp = new PAPFormattedDiskPage(fkp); //take each fkp and get the paps int crun = pfkp.size(); for(int y = 0; y < crun; y++) { //get the beginning fc of each paragraph text run int fcStart = pfkp.getStart(y); int fcEnd = pfkp.getEnd(y); //get the papx for this paragraph byte[] papx = pfkp.getGrpprl(y); _listener.paragraph(new PapxNode(fcStart, fcEnd, papx)); //get the character runs for this paragraph int charStart = 0; int charEnd = 0; //add the character runs do { if (currentChpxIndex < currentArraySize) { charStart = cfkp.getStart(currentChpxIndex); charEnd = cfkp.getEnd(currentChpxIndex); byte[] chpx = cfkp.getGrpprl(currentChpxIndex); _listener.characterRun(new ChpxNode(charStart, charEnd, chpx)); if (charEnd < fcEnd) { currentChpxIndex++; } else { break; } } else { currentCharPage = LittleEndian.getInt(_tableBuffer, charOffset + charPlcf.getStructOffset(++currentPageIndex)); fkp = new byte[512]; System.arraycopy(_mainDocument, (currentCharPage * 512), fkp, 0, 512); cfkp = new CHPFormattedDiskPage(fkp); currentChpxIndex = 0; currentArraySize = cfkp.size(); } } while(currentCharPage <= charPlcfLen + 1); } } } private void initParsingStates(int parOffset, PlexOfCps parPlcf, int charOffset, PlexOfCps charPlcf) { int currentCharPage = LittleEndian.getInt(_tableBuffer, charOffset + charPlcf.getStructOffset(0)); byte[] fkp = new byte[512]; System.arraycopy(_mainDocument, (currentCharPage * 512), fkp, 0, 512); CHPFormattedDiskPage cfkp = new CHPFormattedDiskPage(fkp); _charParsingState = new ParsingState(currentCharPage, cfkp); int currentParPage = LittleEndian.getInt(_tableBuffer, parOffset + parPlcf.getStructOffset(0)); fkp = new byte[512]; System.arraycopy(_mainDocument, (currentParPage * 512), fkp, 0, 512); PAPFormattedDiskPage pfkp = new PAPFormattedDiskPage(fkp); _parParsingState = new ParsingState(currentParPage, pfkp); } /** * initializes the SectionProperties BTree */ private void initSectionProperties() { int ccpText = _fib.getCcpText(); int ccpFtn = _fib.getCcpFtn(); //sections int fcMin = _fib.getFcMin(); int plcfsedFC = _fib.getFcPlcfsed(); int plcfsedSize = _fib.getLcbPlcfsed(); //paragraphs int parOffset = _fib.getFcPlcfbtePapx(); int parPlcSize = _fib.getLcbPlcfbtePapx(); //characters int charOffset = _fib.getFcPlcfbteChpx(); int charPlcSize = _fib.getLcbPlcfbteChpx(); PlexOfCps charPlcf = new PlexOfCps(charPlcSize, 4); PlexOfCps parPlcf = new PlexOfCps(parPlcSize, 4); initParsingStates(parOffset, parPlcf, charOffset, charPlcf); //byte[] plcfsed = new byte[plcfsedSize]; //System.arraycopy(_tableBuffer, plcfsedFC, plcfsed, 0, plcfsedSize); PlexOfCps plcfsed = new PlexOfCps(plcfsedSize, 12); int arraySize = plcfsed.length(); int start = fcMin; int end = fcMin + ccpText; int x = 0; int sectionEnd = 0; //do the main body sections while (x < arraySize) { int sectionStart = LittleEndian.getInt(_tableBuffer, plcfsedFC + plcfsed.getIntOffset(x)) + fcMin; sectionEnd = LittleEndian.getInt(_tableBuffer, plcfsedFC + plcfsed.getIntOffset(x + 1)) + fcMin; int sepxStart = LittleEndian.getInt(_tableBuffer, plcfsedFC + plcfsed.getStructOffset(x) + 2); int sepxSize = LittleEndian.getShort(_mainDocument, sepxStart); byte[] sepx = new byte[sepxSize]; System.arraycopy(_mainDocument, sepxStart + 2, sepx, 0, sepxSize); SepxNode node = new SepxNode(x + 1, sectionStart, sectionEnd, sepx); _listener.bodySection(node); initParagraphProperties(parOffset, parPlcf, charOffset, charPlcf, sectionStart, Math.min(end, sectionEnd)); if (sectionEnd > end) { break; } else { x++; } } //do the header sections for (; x < arraySize; x++)// && sectionEnd <= end; x++) { int sectionStart = LittleEndian.getInt(_tableBuffer, plcfsedFC + plcfsed.getIntOffset(x)) + fcMin; sectionEnd = LittleEndian.getInt(_tableBuffer, plcfsedFC + plcfsed.getIntOffset(x + 1)) + fcMin; int sepxStart = LittleEndian.getInt(_tableBuffer, plcfsedFC + plcfsed.getStructOffset(x) + 2); int sepxSize = LittleEndian.getShort(_mainDocument, sepxStart); byte[] sepx = new byte[sepxSize]; System.arraycopy(_mainDocument, sepxStart + 2, sepx, 0, sepxSize); SepxNode node = new SepxNode(x + 1, sectionStart, sectionEnd, sepx); _listener.hdrSection(node); initParagraphProperties(parOffset, parPlcf, charOffset, charPlcf, Math.max(sectionStart, end), sectionEnd); } _listener.endSections(); } /** * Initializes the DocumentProperties object unique to this document. */ private void initDocumentProperties() { int pos = _fib.getFcDop(); int size = _fib.getLcbDop(); byte[] dopArray = new byte[size]; System.arraycopy(_tableBuffer, pos, dopArray, 0, size); _listener.document(new DocumentProperties(dopArray)); } /** * Uncompresses the StyleSheet from file into memory. */ private void createStyleSheet() { int stshIndex = _fib.getFcStshf(); int stshSize = _fib.getLcbStshf(); byte[] stsh = new byte[stshSize]; System.arraycopy(_tableBuffer, stshIndex, stsh, 0, stshSize); _listener.styleSheet(new StyleSheet(stsh)); } /** * Initializes the list tables for this document */ private void createListTables() { int lfoOffset = _fib.getFcPlfLfo(); int lfoSize = _fib.getLcbPlfLfo(); byte[] plflfo = new byte[lfoSize]; System.arraycopy(_tableBuffer, lfoOffset, plflfo, 0, lfoSize); int lstOffset = _fib.getFcPlcfLst(); int lstSize = _fib.getLcbPlcfLst(); if (lstOffset > 0 && lstSize > 0) { // The lstSize returned by _fib.getLcbPlcfLst() doesn't appear // to take into account any LVLs. Therefore, we recalculate // lstSize based on where the LFO section begins (because the // LFO section immediately follows the LST section). lstSize = lfoOffset - lstOffset; byte[] plcflst = new byte[lstSize]; System.arraycopy(_tableBuffer, lstOffset, plcflst, 0, lstSize); _listener.lists(new ListTables(plcflst, plflfo)); } } /** * Initializes this document's FontTable; */ private void createFontTable() { int fontTableIndex = _fib.getFcSttbfffn(); int fontTableSize = _fib.getLcbSttbfffn(); byte[] fontTable = new byte[fontTableSize]; System.arraycopy(_tableBuffer, fontTableIndex, fontTable, 0, fontTableSize); _listener.fonts(new FontTable(fontTable)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -