Package org.apache.poi.hwpf.sprm

Examples of org.apache.poi.hwpf.sprm.SprmBuffer


                Integer.valueOf( _textRuns.size() ), " elements)" );

        if ( _textRuns.isEmpty() )
        {
            logger.log( POILogger.WARN, "CHPX FKPs are empty" );
            _textRuns.add( new CHPX( 0, 0, new SprmBuffer( 0 ) ) );
        }
    }
View Full Code Here


                            + "'s PRM references to unknown grpprl" );
                    continue;
                }

                boolean hasChp = false;
                SprmBuffer sprmBuffer = sprmBuffers[igrpprl];
                for ( SprmIterator iterator = sprmBuffer.iterator(); iterator
                        .hasNext(); )
                {
                    SprmOperation sprmOperation = iterator.next();
                    if ( sprmOperation.getType() == SprmOperation.TYPE_CHP )
                    {
                        hasChp = true;
                        break;
                    }
                }

                if ( hasChp )
                {
                    SprmBuffer newSprmBuffer;
                    try
                    {
                        newSprmBuffer = (SprmBuffer) sprmBuffer.clone();
                    }
                    catch ( CloneNotSupportedException e )
                    {
                        // shall not happen
                        throw new Error( e );
                    }

                    CHPX chpx = new CHPX( textPiece.getStart(),
                            textPiece.getEnd(), newSprmBuffer );
                    _textRuns.add( chpx );
                }
            }
            logger.log( POILogger.DEBUG,
                    "Merged with CHPX from complex file table in ",
                    Long.valueOf( System.currentTimeMillis() - start ),
                    " ms (", Integer.valueOf( _textRuns.size() ),
                    " elements in total)" );
            start = System.currentTimeMillis();
        }

        List<CHPX> oldChpxSortedByStartPos = new ArrayList<CHPX>( _textRuns );
        Collections.sort( oldChpxSortedByStartPos,
                PropertyNode.StartComparator.instance );

        logger.log( POILogger.DEBUG, "CHPX sorted by start position in ",
                Long.valueOf( System.currentTimeMillis() - start ), " ms" );
        start = System.currentTimeMillis();

        final Map<CHPX, Integer> chpxToFileOrder = new IdentityHashMap<CHPX, Integer>();
        {
            int counter = 0;
            for ( CHPX chpx : _textRuns )
            {
                chpxToFileOrder.put( chpx, Integer.valueOf( counter++ ) );
            }
        }
        final Comparator<CHPX> chpxFileOrderComparator = new Comparator<CHPX>()
        {
            public int compare( CHPX o1, CHPX o2 )
            {
                Integer i1 = chpxToFileOrder.get( o1 );
                Integer i2 = chpxToFileOrder.get( o2 );
                return i1.compareTo( i2 );
            }
        };

        logger.log( POILogger.DEBUG, "CHPX's order map created in ",
                Long.valueOf( System.currentTimeMillis() - start ), " ms" );
        start = System.currentTimeMillis();

        List<Integer> textRunsBoundariesList;
        {
            Set<Integer> textRunsBoundariesSet = new HashSet<Integer>();
            for ( CHPX chpx : _textRuns )
            {
                textRunsBoundariesSet.add( Integer.valueOf( chpx.getStart() ) );
                textRunsBoundariesSet.add( Integer.valueOf( chpx.getEnd() ) );
            }
            textRunsBoundariesSet.remove( Integer.valueOf( 0 ) );
            textRunsBoundariesList = new ArrayList<Integer>(
                    textRunsBoundariesSet );
            Collections.sort( textRunsBoundariesList );
        }

        logger.log( POILogger.DEBUG, "Texts CHPX boundaries collected in ",
                Long.valueOf( System.currentTimeMillis() - start ), " ms" );
        start = System.currentTimeMillis();

        List<CHPX> newChpxs = new LinkedList<CHPX>();
        int lastTextRunStart = 0;
        for ( Integer objBoundary : textRunsBoundariesList )
        {
            final int boundary = objBoundary.intValue();

            final int startInclusive = lastTextRunStart;
            final int endExclusive = boundary;
            lastTextRunStart = endExclusive;

            int startPosition = binarySearch( oldChpxSortedByStartPos, boundary );
            startPosition = Math.abs( startPosition );
            while ( startPosition >= oldChpxSortedByStartPos.size() )
                startPosition--;
            while ( startPosition > 0
                    && oldChpxSortedByStartPos.get( startPosition ).getStart() >= boundary )
                startPosition--;

            List<CHPX> chpxs = new LinkedList<CHPX>();
            for ( int c = startPosition; c < oldChpxSortedByStartPos.size(); c++ )
            {
                CHPX chpx = oldChpxSortedByStartPos.get( c );

                if ( boundary < chpx.getStart() )
                    break;

                int left = Math.max( startInclusive, chpx.getStart() );
                int right = Math.min( endExclusive, chpx.getEnd() );

                if ( left < right )
                {
                    chpxs.add( chpx );
                }
            }

            if ( chpxs.size() == 0 )
            {
                logger.log( POILogger.WARN, "Text piece [",
                        Integer.valueOf( startInclusive ), "; ",
                        Integer.valueOf( endExclusive ),
                        ") has no CHPX. Creating new one." );
                // create it manually
                CHPX chpx = new CHPX( startInclusive, endExclusive,
                        new SprmBuffer( 0 ) );
                newChpxs.add( chpx );
                continue;
            }

            if ( chpxs.size() == 1 )
            {
                // can we reuse existing?
                CHPX existing = chpxs.get( 0 );
                if ( existing.getStart() == startInclusive
                        && existing.getEnd() == endExclusive )
                {
                    newChpxs.add( existing );
                    continue;
                }
            }

            Collections.sort( chpxs, chpxFileOrderComparator );

            SprmBuffer sprmBuffer = new SprmBuffer( 0 );
            for ( CHPX chpx : chpxs )
            {
                sprmBuffer.append( chpx.getGrpprl(), 0 );
            }
            CHPX newChpx = new CHPX( startInclusive, endExclusive, sprmBuffer );
            newChpxs.add( newChpx );

            continue;
View Full Code Here

    short istd = papx.getIstd();

    StyleSheet ss = _doc.getStyleSheet();
    CharacterProperties baseStyle = ss.getCharacterStyle(istd);
    byte[] grpprl = CharacterSprmCompressor.compressCharacterProperty(props, baseStyle);
    SprmBuffer buf = new SprmBuffer(grpprl, 0);
    _doc.getCharacterTable().insert(_charStart, _start, buf);

    return insertBefore(text);
  }
View Full Code Here

    short istd = papx.getIstd();

    StyleSheet ss = _doc.getStyleSheet();
    CharacterProperties baseStyle = ss.getCharacterStyle(istd);
    byte[] grpprl = CharacterSprmCompressor.compressCharacterProperty(props, baseStyle);
    SprmBuffer buf = new SprmBuffer(grpprl, 0);
    _doc.getCharacterTable().insert(_charEnd, _end, buf);
    _charEnd++;
    return insertAfter(text);
  }
View Full Code Here

    byte[] grpprl = ParagraphSprmCompressor.compressParagraphProperty(props, baseStyle);
    byte[] withIndex = new byte[grpprl.length + LittleEndian.SHORT_SIZE];
    LittleEndian.putShort(withIndex, (short) styleIndex);
    System.arraycopy(grpprl, 0, withIndex, LittleEndian.SHORT_SIZE, grpprl.length);
    SprmBuffer buf = new SprmBuffer(withIndex, 2);

    _doc.getParagraphTable().insert(_parStart, _start, buf);
    insertBefore(text, baseChp);
    return getParagraph(0);
  }
View Full Code Here

    byte[] grpprl = ParagraphSprmCompressor.compressParagraphProperty(props, baseStyle);
    byte[] withIndex = new byte[grpprl.length + LittleEndian.SHORT_SIZE];
    LittleEndian.putShort(withIndex, (short) styleIndex);
    System.arraycopy(grpprl, 0, withIndex, LittleEndian.SHORT_SIZE, grpprl.length);
    SprmBuffer buf = new SprmBuffer(withIndex, 2);

    _doc.getParagraphTable().insert(_parEnd, _end, buf);
    _parEnd++;
    insertAfter(text, baseChp);
    return getParagraph(numParagraphs() - 1);
View Full Code Here

  private ParagraphHeight _phe;

  public PAPX(int fcStart, int fcEnd, CharIndexTranslator translator, byte[] papx, ParagraphHeight phe, byte[] dataStream)
  {
    super(fcStart, fcEnd, translator, new SprmBuffer(papx, 2));
    _phe = phe;
    SprmBuffer buf = findHuge(new SprmBuffer(papx, 2), dataStream);
    if(buf != null)
      _buf = buf;
  }
View Full Code Here

  }

    public PAPX( int charStart, int charEnd, byte[] papx, ParagraphHeight phe,
            byte[] dataStream )
    {
        super( charStart, charEnd, new SprmBuffer( papx, 2 ) );
        _phe = phe;
        SprmBuffer buf = findHuge( new SprmBuffer( papx, 2 ), dataStream );
        if ( buf != null )
            _buf = buf;
    }
View Full Code Here

            // copy original istd into huge Grpprl
            hugeGrpprl[0] = grpprl[0]; hugeGrpprl[1] = grpprl[1];
            // copy Grpprl from dataStream
            System.arraycopy(datastream, hugeGrpprlOffset + 2, hugeGrpprl, 2,
                             grpprlSize);
            return new SprmBuffer(hugeGrpprl, 2);
          }
        }
      }
    }
    return null;
View Full Code Here

            // );

            for ( int[] range : translator.getCharIndexRanges( bytesStartAt,
                    bytesEndAt ) )
            {
                CHPX chpx = new CHPX( range[0], range[1], new SprmBuffer(
                        getGrpprl( x ), 0 ) );
                _chpxList.add( chpx );
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.poi.hwpf.sprm.SprmBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.