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

📄 worddocument.java

📁 Office格式转换代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
  }  private void closeBlock(StringBuffer buf)  {    buf.append("</fo:block>\r\n");  }  private ArrayList findPAPProperties(int start, int end, BTreeSet.BTreeNode root)  {    ArrayList results = new ArrayList();    BTreeSet.Entry[] entries = root.entries;    for(int x = 0; x < entries.length; x++)    {      if(entries[x] != null)      {        BTreeSet.BTreeNode child = entries[x].child;        PapxNode papxNode = (PapxNode)entries[x].element;        if(papxNode != null)        {          int papxStart = papxNode.getStart();          if(papxStart < end)          {            if(papxStart >= start)            {              if(child != null)              {                ArrayList beforeItems = findPAPProperties(start, end, child);                results.addAll(beforeItems);              }              results.add(papxNode);            }          }          else          {            if(child != null)            {              ArrayList beforeItems = findPAPProperties(start, end, child);              results.addAll(beforeItems);            }            break;          }        }        else if(child != null)        {          ArrayList afterItems = findPAPProperties(start, end, child);          results.addAll(afterItems);        }      }      else      {        break;      }    }    return results;  }  private String createPageMaster(SEP sep, String type, int section,                                  String regionBefore, String regionAfter)  {    float height = ((float)sep._yaPage)/1440.0f;    float width = ((float)sep._xaPage)/1440.0f;    float leftMargin = ((float)sep._dxaLeft)/1440.0f;    float rightMargin = ((float)sep._dxaRight)/1440.0f;    float topMargin = ((float)sep._dyaTop)/1440.0f;    float bottomMargin = ((float)sep._dyaBottom)/1440.0f;    //add these to the header    String thisPage = type + "-page" + section;    _headerBuffer.append("<fo:simple-page-master master-name=\"" +                        thisPage + "\"\r\n");    _headerBuffer.append("page-height=\"" + height + "in\"\r\n");    _headerBuffer.append("page-width=\"" + width + "in\"\r\n");    _headerBuffer.append(">\r\n");    _headerBuffer.append("<fo:region-body ");    //top right bottom left    _headerBuffer.append("margin=\"" + topMargin + "in " + rightMargin + "in " +                         bottomMargin + "in " + leftMargin + "in\"\r\n");    //String style = null;    //String color = null;    addBorder(_headerBuffer, sep._brcTop, "top");    addBorder(_headerBuffer, sep._brcBottom, "bottom");    addBorder(_headerBuffer, sep._brcLeft, "left");    addBorder(_headerBuffer, sep._brcRight, "right");    if(sep._ccolM1 > 0)    {      _headerBuffer.append("column-count=\"" + (sep._ccolM1 + 1) + "\" ");      if(sep._fEvenlySpaced)      {        _headerBuffer.append("column-gap=\"" + ((float)(sep._dxaColumns))/1440.0f + "in\"");      }      else      {        _headerBuffer.append("column-gap=\"0.25in\"");      }    }    _headerBuffer.append("/>\r\n");    if(regionBefore != null)    {      _headerBuffer.append(regionBefore);    }    if(regionAfter != null)    {      _headerBuffer.append(regionAfter);    }    _headerBuffer.append("</fo:simple-page-master>\r\n");    return thisPage;  }  private void addBorder(StringBuffer buf, short[] brc, String where)  {    if((brc[0] & 0xff00) != 0 && brc[0] != -1)    {      int type = (brc[0] & 0xff00) >> 8;      float width = ((float)(brc[0] & 0x00ff))/8.0f;      String style = getBorderStyle(brc[0]);      String color = getColor(brc[1] & 0x00ff);      String thickness = getBorderThickness(brc[0]);      buf.append("border-" + where + "-style=\"" + style + "\"\r\n");      buf.append("border-" + where + "-color=\"" + color + "\"\r\n");      buf.append("border-" + where + "-width=\"" + width + "pt\"\r\n");    }  }  public void closeDoc()  {    _headerBuffer.append("</fo:layout-master-set>");    _bodyBuffer.append("</fo:root>");    //_headerBuffer.append();    //test code    try    {      OutputStreamWriter test = new OutputStreamWriter(new FileOutputStream(_outName), "8859_1");      test.write(_headerBuffer.toString());      test.write(_bodyBuffer.toString());      test.flush();      test.close();    }    catch(Throwable t)    {      t.printStackTrace();    }  }  private String getBorderThickness(int style)  {    switch(style)    {      case 1:        return "medium";      case 2:        return "thick";      case 3:        return "medium";      case 5:        return "thin";      default:        return "medium";    }  }  private String getColor(int ico)  {    switch(ico)    {      case 1:        return "black";      case 2:        return "blue";      case 3:        return "cyan";      case 4:        return "green";      case 5:        return "magenta";      case 6:        return "red";      case 7:        return "yellow";      case 8:        return "white";      case 9:        return "darkblue";      case 10:        return "darkcyan";      case 11:        return "darkgreen";      case 12:        return "darkmagenta";      case 13:        return "darkred";      case 14:        return "darkyellow";      case 15:        return "darkgray";      case 16:        return "lightgray";      default:        return "black";    }  }  private String getBorderStyle(int type)  {    switch(type)    {      case 1:      case 2:        return "solid";      case 3:        return "double";      case 5:        return "solid";      case 6:        return "dotted";      case 7:      case 8:        return "dashed";      case 9:        return "dotted";      case 10:      case 11:      case 12:      case 13:      case 14:      case 15:      case 16:      case 17:      case 18:      case 19:        return "double";      case 20:        return "solid";      case 21:        return "double";      case 22:        return "dashed";      case 23:        return "dashed";      case 24:        return "ridge";      case 25:        return "grooved";      default:        return "solid";    }  }  /**   * creates the List data   *   * @param tableStream Main table stream buffer.   */  private void createListTables(byte[] tableStream)  {    int lfoOffset = LittleEndian.getInt(_header, 0x2ea);    int lfoSize = LittleEndian.getInt(_header, 0x2ee);    byte[] plflfo = new byte[lfoSize];    System.arraycopy(tableStream, lfoOffset, plflfo, 0, lfoSize);    int lstOffset = LittleEndian.getInt(_header, 0x2e2);    int lstSize = LittleEndian.getInt(_header, 0x2e2);    if(lstOffset > 0 && lstSize > 0)    {      lstSize = lfoOffset - lstOffset;      byte[] plcflst = new byte[lstSize];      System.arraycopy(tableStream, lstOffset, plcflst, 0, lstSize);      _listTables = new ListTables(plcflst, plflfo);    }  }  /**   * Creates the documents StyleSheet   *   * @param tableStream Main table stream buffer.   *   */  private void createStyleSheet(byte[] tableStream)  {      int stshIndex = LittleEndian.getInt(_header, 0xa2);      int stshSize = LittleEndian.getInt(_header, 0xa6);      byte[] stsh = new byte[stshSize];      System.arraycopy(tableStream, stshIndex, stsh, 0, stshSize);      _styleSheet = new StyleSheet(stsh);  }  /**   * creates the Font table   *   * @param tableStream Main table stream buffer.   */  private void createFontTable(byte[] tableStream)  {    int fontTableIndex = LittleEndian.getInt(_header, 0x112);    int fontTableSize = LittleEndian.getInt(_header, 0x116);    byte[] fontTable = new byte[fontTableSize];    System.arraycopy(tableStream, fontTableIndex, fontTable, 0, fontTableSize);    _fonts = new FontTable(fontTable);  }  private void overrideCellBorder(int row, int col, int height,                                  int width, TC tc, TAP tap)  {    if(row == 0)    {      if(tc._brcTop[0] == 0 || tc._brcTop[0] == -1)      {        tc._brcTop = tap._brcTop;      }      if(tc._brcBottom[0] == 0 || tc._brcBottom[0] == -1)      {        tc._brcBottom = tap._brcHorizontal;      }    }    else if(row == (height - 1))    {      if(tc._brcTop[0] == 0 || tc._brcTop[0] == -1)      {        tc._brcTop = tap._brcHorizontal;      }      if(tc._brcBottom[0] == 0 || tc._brcBottom[0] == -1)      {        tc._brcBottom = tap._brcBottom;      }    }    else    {      if(tc._brcTop[0] == 0 || tc._brcTop[0] == -1)      {        tc._brcTop = tap._brcHorizontal;      }      if(tc._brcBottom[0] == 0 || tc._brcBottom[0] == -1)      {        tc._brcBottom = tap._brcHorizontal;      }    }    if(col == 0)    {      if(tc._brcLeft[0] == 0 || tc._brcLeft[0] == -1)      {        tc._brcLeft = tap._brcLeft;      }      if(tc._brcRight[0] == 0 || tc._brcRight[0] == -1)      {        tc._brcRight = tap._brcVertical;      }    }    else if(col == (width - 1))    {      if(tc._brcLeft[0] == 0 || tc._brcLeft[0] == -1)      {        tc._brcLeft = tap._brcVertical;      }      if(tc._brcRight[0] == 0 || tc._brcRight[0] == -1)      {        tc._brcRight = tap._brcRight;      }    }    else    {      if(tc._brcLeft[0] == 0 || tc._brcLeft[0] == -1)      {        tc._brcLeft = tap._brcVertical;      }      if(tc._brcRight[0] == 0 || tc._brcRight[0] == -1)      {        tc._brcRight = tap._brcVertical;      }    }  }  private void printTable()  {    if(_table != null)    {      int size = _table.size();      //local buffers for the table      StringBuffer tableHeaderBuffer = new StringBuffer();      StringBuffer tableBodyBuffer = new StringBuffer();      for(int x = 0; x < size; x++)      {        StringBuffer rowBuffer = tableBodyBuffer;        TableRow row = (TableRow)_table.get(x);        TAP tap = row.getTAP();        ArrayList cells = row.getCells();        if(tap._fTableHeader)        {          rowBuffer = tableHeaderBuffer;        }        rowBuffer.append("<fo:table-row ");        if(tap._dyaRowHeight > 0)        {          rowBuffer.append("height=\"" + ((float)tap._dyaRowHeight)/1440.0f + "in\" ");        }        if(tap._fCantSplit)        {          rowBuffer.append("keep-together=\"always\" ");        }        rowBuffer.append(">");        //add cells        for(int y = 0; y < tap._itcMac; y++)        {          TC tc = tap._rgtc[y];          overrideCellBorder(x, y, size, tap._itcMac, tc, tap);          rowBuffer.append("<fo:table-cell ");          rowBuffer.append("width=\"" + ((float)(tap._rgdxaCenter[y+1] - tap._rgdxaCenter[y]))/1440.0f + "in\" ");          rowBuffer.append("padding-start=\"" + ((float)tap._dxaGapHalf)/1440.0f + "in\" ");          rowBuffer.append("padding-end=\"" + ((float)tap._dxaGapHalf)/1440.0f + "in\" ");          addBorder(rowBuffer, tc._brcTop, "top");          addBorder(rowBuffer, tc._brcLeft, "left");          addBorder(rowBuffer, tc._brcBottom, "bottom");          addBorder(rowBuffer, tc._brcRight, "right");          rowBuffer.append(">");          rowBuffer.append((String)cells.get(y));          rowBuffer.append("</fo:table-cell>");        }        rowBuffer.append("</fo:table-row>");      }      StringBuffer tableBuffer = new StringBuffer();      tableBuffer.append("<fo:table>");      if(tableHeaderBuffer.length() > 0)      {        tableBuffer.append("<fo:table-header>");        tableBuffer.append(tableHeaderBuffer.toString());        tableBuffer.append("</fo:table-header>");      }      tableBuffer.append("<fo:table-body>");      tableBuffer.append(tableBodyBuffer.toString());      tableBuffer.append("</fo:table-body>");      tableBuffer.append("</fo:table>");      _bodyBuffer.append(tableBuffer.toString());      _table = null;    }  }  private void initPclfHdd(byte[] tableStream)  {    int size = Utils.convertBytesToInt(_header, 0xf6);    int pos = Utils.convertBytesToInt(_header, 0xf2);    _plcfHdd = new byte[size];    System.arraycopy(tableStream, pos, _plcfHdd, 0, size);  }}

⌨️ 快捷键说明

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