Examples of TextPosition


Examples of nexj.core.util.TextPosition

      try
      {
         body = Pair.list(Symbol.LAMBDA, m_allVariables, new Pair(Symbol.VECTOR, body));

         // Set the top level code's URL
         Object pos = new TextPosition(0, 0);
         m_posMap.put(body, pos);
         m_urlMap.put(pos, URL_PREFIX + getName());

         func = compiler.compile(body, m_posMap, m_urlMap, machine, false);
      }
View Full Code Here

Examples of nexj.core.util.TextPosition

    * @return The internal representation of the element.
    * @throws ParserException if a syntax error has been encountered.
    */
   protected Object parseElement()
   {
      TextPosition pos = null;
      Object obj;

      switch (getCurToken())
      {
         // must start with an open brace, open array, or primitive
View Full Code Here

Examples of nexj.core.util.TextPosition

         try
         {
            if (sName != null && posMap != null && posMap.size() != 0)
            {
               TextPosition pos = (TextPosition)posMap.valueIterator().next();
               StringBuilder buf = new StringBuilder(64);
               String sURL = pos.getURL();

               if (sURL != null)
               {
                  int i = sURL.indexOf('#');
View Full Code Here

Examples of nexj.core.util.TextPosition

      {
         value = parse(new StringReader(sExpression), null);
      }
      catch (RuntimeException e) // common parent of NumberFormatException & ParserException
      {
         TextPosition pos = (e instanceof TextPositionHolder) ? ((TextPositionHolder)e).getTextPosition() : getCurTokenPos();

         throw new ParserException("err.scripting.invalidMatchExpression", new Object[]
         {
            sExpression
         }, e, pos);
View Full Code Here

Examples of nexj.core.util.TextPosition

    *           position.
    * @throws ParserException
    */
   protected final void fail(boolean bToken) throws ParserException
   {
      TextPosition pos = (bToken) ? null : getCurTextPosition();

      if (pos == null)
      {
         // Never returns null.
         pos = getCurTokenPos();
View Full Code Here

Examples of nexj.core.util.TextPosition

    */
   protected PCodeFunction compile(Object code, String sName, Machine machine)
   {
      try
      {
         m_posMap.put(code, new TextPosition(0, 0, URL_PREFIX + m_sName));
         machine.getGlobalEnvironment().defineVariable(Symbol.SYS_CURRENT_LOGGER, m_logger);

         return new Compiler().compile(code, m_posMap, machine, false);
      }
      catch (CompilerException e)
View Full Code Here

Examples of nexj.core.util.TextPosition

            {
               Object expr = new Pair(Symbol.LAMBDA, new Pair(new Pair(Symbol.THIS), new Pair(m_validation)));

               if (m_textPosMap != null)
               {
                  TextPosition pos = new TextPosition(0,0);

                  m_textPosMap.put(expr, pos);
                  urlMap.put(pos, "class:" + getName() + "$validation");
               }
View Full Code Here

Examples of nexj.core.util.TextPosition

         try
         {
            // Invoke the sys:generate-event macro that generates the ECA code and compile the result
            Pair code = (Pair)machine.invoke((Function)machine.getGlobalEnvironment().getVariable(Symbol.SYS_GENERATE_EVENT), args);
            TextPosition pos = new TextPosition(0, 0);

            posMap.put(code, pos);
            urlMap.put(pos, sEventURL);

            for (Pair pair = code; pair != null; pair = pair.getNext())
            {
               if (pair.getHead() instanceof Pair && !posMap.contains(pair.getHead()))
               {
                  pos = new TextPosition(0, 0);
                  posMap.put(pair.getHead(), pos);
                  urlMap.put(pos, sEventURL);
               }
            }
           
View Full Code Here

Examples of org.apache.pdfbox.text.TextPosition

            int ltrCount = 0;
            int rtlCount = 0;

            while (textIter.hasNext())
            {
                TextPosition position = textIter.next();
                String stringValue = position.getUnicode();
                for (int a = 0; a < stringValue.length(); a++)
                {
                    byte dir = Character.getDirectionality(stringValue.charAt(a));
                    if (dir == Character.DIRECTIONALITY_LEFT_TO_RIGHT ||
                            dir == Character.DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING ||
                            dir == Character.DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE)
                    {
                        ltrCount++;
                    } else if (dir == Character.DIRECTIONALITY_RIGHT_TO_LEFT ||
                            dir == Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC ||
                            dir == Character.DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING ||
                            dir == Character.DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE)
                    {
                        rtlCount++;
                    }
                }
            }
            // choose the dominant direction
            boolean isRtlDominant = rtlCount > ltrCount;

            startArticle(!isRtlDominant);
            startOfArticle = true;
            // we will later use this to skip reordering
            boolean hasRtl = rtlCount > 0;

            // Now cycle through to print the text.
            // We queue up a line at a time before we print so that we can convert
            // the line from presentation form to logical form (if needed).
            List<LineItem> line = new ArrayList<LineItem>();

            textIter = textList.iterator();    // start from the beginning again
            // PDF files don't always store spaces. We will need to guess where we should add
            // spaces based on the distances between TextPositions. Historically, this was done
            // based on the size of the space character provided by the font. In general, this
            // worked but there were cases where it did not work. Calculating the average character
            // width and using that as a metric works better in some cases but fails in some cases
            // where the spacing worked. So we use both. NOTE: Adobe reader also fails on some of
            // these examples.

            // Keeps track of the previous average character width
            float previousAveCharWidth = -1;
            while (textIter.hasNext())
            {
                TextPosition position = textIter.next();
                PositionWrapper current = new PositionWrapper(position);
                String characterValue = position.getUnicode();

                // Resets the average character width when we see a change in font
                // or a change in the font size
                if (lastPosition != null &&
                        (position.getFont() != lastPosition.getTextPosition().getFont() ||
                                position.getFontSize() != lastPosition.getTextPosition().getFontSize()))
                {
                    previousAveCharWidth = -1;
                }

                float positionX;
                float positionY;
                float positionWidth;
                float positionHeight;

                // If we are sorting, then we need to use the text direction
                // adjusted coordinates, because they were used in the sorting.
                if (getSortByPosition())
                {
                    positionX = position.getXDirAdj();
                    positionY = position.getYDirAdj();
                    positionWidth = position.getWidthDirAdj();
                    positionHeight = position.getHeightDir();
                } else
                {
                    positionX = position.getX();
                    positionY = position.getY();
                    positionWidth = position.getWidth();
                    positionHeight = position.getHeight();
                }

                // The current amount of characters in a word
                int wordCharCount = position.getIndividualWidths().length;

                // Estimate the expected width of the space based on the
                // space character with some margin.
                float wordSpacing = position.getWidthOfSpace();
                float deltaSpace;
                if (wordSpacing == 0 || wordSpacing == Float.NaN)
                {
                    deltaSpace = Float.MAX_VALUE;
                } else
View Full Code Here

Examples of org.apache.pdfbox.text.TextPosition

            {
                // test if we overlap the previous entry.
                // Note that we are making an assumption that we need to only look back
                // one TextPosition to find what we are overlapping.
                // This may not always be true. */
                TextPosition previousTextPosition = textList.get(textList.size() - 1);
                if (text.isDiacritic() && previousTextPosition.contains(text))
                {
                    previousTextPosition.mergeDiacritic(text);
                }
                // If the previous TextPosition was the diacritic, merge it into this
                // one and remove it from the list.
                else if (previousTextPosition.isDiacritic() && text.contains(previousTextPosition))
                {
                    text.mergeDiacritic(previousTextPosition);
                    textList.remove(textList.size()-1);
                    textList.add(text);
                }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.