Example #1
0
        public override Status Layout(Area area)
        {
            if (!(area is BlockArea))
            {
                FonetDriver.ActiveDriver.FireFonetWarning(
                    "Page-number outside block area");
                return new Status(Status.OK);
            }
            if (this.marker == MarkerStart)
            {
                AccessibilityProps mAccProps = propMgr.GetAccessibilityProps();
                AuralProps mAurProps = propMgr.GetAuralProps();
                BorderAndPadding bap = propMgr.GetBorderAndPadding();
                BackgroundProps bProps = propMgr.GetBackgroundProps();
                MarginInlineProps mProps = propMgr.GetMarginInlineProps();
                RelativePositionProps mRelProps = propMgr.GetRelativePositionProps();

                ColorType c = this.properties.GetProperty("color").GetColorType();
                this.red = c.Red;
                this.green = c.Green;
                this.blue = c.Blue;

                this.wrapOption = this.properties.GetProperty("wrap-option").GetEnum();
                this.whiteSpaceCollapse =
                    this.properties.GetProperty("white-space-collapse").GetEnum();
                ts = new TextState();
                this.marker = 0;

                string id = this.properties.GetProperty("id").GetString();
                area.getIDReferences().InitializeID(id, area);
            }

            string p = area.getPage().getFormattedNumber();
            this.marker = FOText.addText((BlockArea)area,
                                         propMgr.GetFontState(area.getFontInfo()),
                                         red, green, blue, wrapOption, null,
                                         whiteSpaceCollapse, p.ToCharArray(), 0,
                                         p.Length, ts, VerticalAlign.BASELINE);
            return new Status(Status.OK);
        }
Example #2
0
        public int addText(char[] odata, int start, int end, LinkSet ls,
                           TextState textState)
        {
            if (start == -1)
            {
                return -1;
            }
            bool overrun = false;

            int wordStart = start;
            int wordLength = 0;
            int wordWidth = 0;
            int whitespaceWidth = getCharWidth(' ');

            char[] data = new char[odata.Length];
            char[] dataCopy = new char[odata.Length];
            Array.Copy(odata, data, odata.Length);
            Array.Copy(odata, dataCopy, odata.Length);

            bool isText = false;
            bool isMultiByteChar = false;

            for (int i = start; i < end; i++)
            {
                int charWidth;
                char c = data[i];
                if (!(isSpace(c) || (c == '\n') || (c == '\r') || (c == '\t')
                    || (c == '\u2028')))
                {
                    charWidth = getCharWidth(c);
                    isText = true;
                    isMultiByteChar = (c > 127);
                    if (charWidth <= 0 && c != '\u200B' && c != '\uFEFF')
                    {
                        charWidth = whitespaceWidth;
                    }
                }
                else
                {
                    if ((c == '\n') || (c == '\r') || (c == '\t'))
                    {
                        charWidth = whitespaceWidth;
                    }
                    else
                    {
                        charWidth = getCharWidth(c);
                    }

                    isText = false;
                    isMultiByteChar = false;

                    if (prev == WHITESPACE)
                    {
                        if (this.whiteSpaceCollapse == WhiteSpaceCollapse.FALSE)
                        {
                            if (isSpace(c))
                            {
                                spaceWidth += getCharWidth(c);
                            }
                            else if (c == '\n' || c == '\u2028')
                            {
                                if (spaceWidth > 0)
                                {
                                    InlineSpace isp = new InlineSpace(spaceWidth);
                                    isp.setUnderlined(textState.getUnderlined());
                                    isp.setOverlined(textState.getOverlined());
                                    isp.setLineThrough(textState.getLineThrough());
                                    addChild(isp);
                                    finalWidth += spaceWidth;
                                    spaceWidth = 0;
                                }
                                return i + 1;
                            }
                            else if (c == '\t')
                            {
                                spaceWidth += 8 * whitespaceWidth;
                            }
                        }
                        else if (c == '\u2028')
                        {
                            if (spaceWidth > 0)
                            {
                                InlineSpace isp = new InlineSpace(spaceWidth);
                                isp.setUnderlined(textState.getUnderlined());
                                isp.setOverlined(textState.getOverlined());
                                isp.setLineThrough(textState.getLineThrough());
                                addChild(isp);
                                finalWidth += spaceWidth;
                                spaceWidth = 0;
                            }
                            return i + 1;
                        }

                    }
                    else if (prev == TEXT || prev == MULTIBYTECHAR)
                    {
                        if (spaceWidth > 0)
                        {
                            InlineSpace isp = new InlineSpace(spaceWidth);
                            if (prevUlState)
                            {
                                isp.setUnderlined(textState.getUnderlined());
                            }
                            if (prevOlState)
                            {
                                isp.setOverlined(textState.getOverlined());
                            }
                            if (prevLTState)
                            {
                                isp.setLineThrough(textState.getLineThrough());
                            }
                            addChild(isp);
                            finalWidth += spaceWidth;
                            spaceWidth = 0;
                        }

                        IEnumerator e = pendingAreas.GetEnumerator();
                        while (e.MoveNext())
                        {
                            Box box = (Box)e.Current;
                            if (box is InlineArea)
                            {
                                if (ls != null)
                                {
                                    Rectangle lr =
                                        new Rectangle(finalWidth, 0,
                                                      ((InlineArea)box).getContentWidth(),
                                                      fontState.FontSize);
                                    ls.addRect(lr, this, (InlineArea)box);
                                }
                            }
                            addChild(box);
                        }

                        finalWidth += pendingWidth;

                        pendingWidth = 0;
                        pendingAreas = new ArrayList();

                        if (wordLength > 0)
                        {
                            addSpacedWord(new String(data, wordStart, wordLength),
                                          ls, finalWidth, 0, textState, false);
                            finalWidth += wordWidth;

                            wordWidth = 0;
                        }

                        prev = WHITESPACE;

                        embeddedLinkStart = 0;

                        spaceWidth = getCharWidth(c);

                        if (this.whiteSpaceCollapse == WhiteSpaceCollapse.FALSE)
                        {
                            if (c == '\n' || c == '\u2028')
                            {
                                return i + 1;
                            }
                            else if (c == '\t')
                            {
                                spaceWidth = whitespaceWidth;
                            }
                        }
                        else if (c == '\u2028')
                        {
                            return i + 1;
                        }
                    }
                    else
                    {
                        if (this.whiteSpaceCollapse == WhiteSpaceCollapse.FALSE)
                        {
                            if (isSpace(c))
                            {
                                prev = WHITESPACE;
                                spaceWidth = getCharWidth(c);
                            }
                            else if (c == '\n')
                            {
                                InlineSpace isp = new InlineSpace(spaceWidth);
                                addChild(isp);
                                return i + 1;
                            }
                            else if (c == '\t')
                            {
                                prev = WHITESPACE;
                                spaceWidth = 8 * whitespaceWidth;
                            }

                        }
                        else
                        {
                            wordStart++;
                        }
                    }

                }

                if (isText)
                {

                    int curr = isMultiByteChar ? MULTIBYTECHAR : TEXT;
                    if (prev == WHITESPACE)
                    {
                        wordWidth = charWidth;
                        if ((finalWidth + spaceWidth + wordWidth)
                            > this.getContentWidth())
                        {
                            if (overrun)
                            {
                                FonetDriver.ActiveDriver.FireFonetWarning(
                                    "Area contents overflows area");
                            }
                            if (this.wrapOption == WrapOption.WRAP)
                            {
                                return i;
                            }
                        }
                        prev = curr;
                        wordStart = i;
                        wordLength = 1;
                    }
                    else if (prev == TEXT || prev == MULTIBYTECHAR)
                    {
                        if (prev == TEXT && curr == TEXT || !canBreakMidWord())
                        {
                            wordLength++;
                            wordWidth += charWidth;
                        }
                        else
                        {
                            InlineSpace isp = new InlineSpace(spaceWidth);
                            if (prevUlState)
                            {
                                isp.setUnderlined(textState.getUnderlined());
                            }
                            if (prevOlState)
                            {
                                isp.setOverlined(textState.getOverlined());
                            }
                            if (prevLTState)
                            {
                                isp.setLineThrough(textState.getLineThrough());
                            }
                            addChild(isp);
                            finalWidth += spaceWidth;
                            spaceWidth = 0;

                            IEnumerator e = pendingAreas.GetEnumerator();
                            while (e.MoveNext())
                            {
                                Box box = (Box)e.Current;
                                if (box is InlineArea)
                                {
                                    if (ls != null)
                                    {
                                        Rectangle lr =
                                            new Rectangle(finalWidth, 0,
                                                          ((InlineArea)box).getContentWidth(),
                                                          fontState.FontSize);
                                        ls.addRect(lr, this, (InlineArea)box);
                                    }
                                }
                                addChild(box);
                            }

                            finalWidth += pendingWidth;

                            pendingWidth = 0;
                            pendingAreas = new ArrayList();

                            if (wordLength > 0)
                            {
                                addSpacedWord(new String(data, wordStart, wordLength),
                                              ls, finalWidth, 0, textState, false);
                                finalWidth += wordWidth;
                            }
                            spaceWidth = 0;
                            wordStart = i;
                            wordLength = 1;
                            wordWidth = charWidth;
                        }
                        prev = curr;
                    }
                    else
                    {
                        prev = curr;
                        wordStart = i;
                        wordLength = 1;
                        wordWidth = charWidth;
                    }

                    if ((finalWidth + spaceWidth + pendingWidth + wordWidth)
                        > this.getContentWidth())
                    {
                        if (this.wrapOption == WrapOption.WRAP)
                        {
                            if (wordStart == start)
                            {
                                overrun = true;
                                if (finalWidth > 0)
                                {
                                    return wordStart;
                                }
                            }
                            else
                            {
                                return wordStart;
                            }

                        }
                    }
                }
            }

            if (prev == TEXT || prev == MULTIBYTECHAR)
            {
                if (spaceWidth > 0)
                {
                    InlineSpace pis = new InlineSpace(spaceWidth);
                    pis.setEatable(true);
                    if (prevUlState)
                    {
                        pis.setUnderlined(textState.getUnderlined());
                    }
                    if (prevOlState)
                    {
                        pis.setOverlined(textState.getOverlined());
                    }
                    if (prevLTState)
                    {
                        pis.setLineThrough(textState.getLineThrough());
                    }
                    pendingAreas.Add(pis);
                    pendingWidth += spaceWidth;
                    spaceWidth = 0;
                }

                addSpacedWord(new String(data, wordStart, wordLength), ls,
                              finalWidth + pendingWidth,
                              spaceWidth, textState, true);

                embeddedLinkStart += wordWidth;
                wordWidth = 0;
            }

            if (overrun)
            {
                FonetDriver.ActiveDriver.FireFonetWarning(
                    "Area contents overflows area");
            }
            return -1;
        }
Example #3
0
        private void addSpacedWord(string word, LinkSet ls, int startw,
                                   int spacew, TextState textState,
                                   bool addToPending)
        {
            /*
             * Split string based on four delimeters:
             * \u00A0 - Latin1 NBSP (Non breaking space)
             * \u202F - unknown reserved character according to Unicode Standard
             * \u3000 - CJK IDSP (Ideographic space)
             * \uFEFF - Arabic ZWN BSP (Zero width no break space)
             */
            StringTokenizer st = new StringTokenizer(word, "\u00A0\u202F\u3000\uFEFF", true);
            int extraw = 0;
            while (st.MoveNext())
            {
                string currentWord = (string)st.Current;

                if (currentWord.Length == 1
                    && (isNBSP(currentWord[0])))
                {
                    // Add an InlineSpace
                    int spaceWidth = getCharWidth(currentWord[0]);
                    if (spaceWidth > 0)
                    {
                        InlineSpace ispace = new InlineSpace(spaceWidth);
                        extraw += spaceWidth;
                        if (prevUlState)
                        {
                            ispace.setUnderlined(textState.getUnderlined());
                        }
                        if (prevOlState)
                        {
                            ispace.setOverlined(textState.getOverlined());
                        }
                        if (prevLTState)
                        {
                            ispace.setLineThrough(textState.getLineThrough());
                        }

                        if (addToPending)
                        {
                            pendingAreas.Add(ispace);
                            pendingWidth += spaceWidth;
                        }
                        else
                        {
                            addChild(ispace);
                        }
                    }
                }
                else
                {
                    WordArea ia = new WordArea(currentFontState, this.red,
                                               this.green, this.blue,
                                               currentWord,
                                               getWordWidth(currentWord));
                    ia.setYOffset(placementOffset);
                    ia.setUnderlined(textState.getUnderlined());
                    prevUlState = textState.getUnderlined();
                    ia.setOverlined(textState.getOverlined());
                    prevOlState = textState.getOverlined();
                    ia.setLineThrough(textState.getLineThrough());
                    prevLTState = textState.getLineThrough();
                    ia.setVerticalAlign(vAlign);

                    if (addToPending)
                    {
                        pendingAreas.Add(ia);
                        pendingWidth += getWordWidth(currentWord);
                    }
                    else
                    {
                        addChild(ia);
                    }
                    if (ls != null)
                    {
                        Rectangle lr = new Rectangle(startw + extraw, spacew,
                                                     ia.getContentWidth(),
                                                     fontState.FontSize);
                        ls.addRect(lr, this, ia);
                    }
                }
            }
        }
Example #4
0
        public TextState getTextDecoration(FObj parent)
        {
            TextState tsp = null;
            bool found = false;

            do
            {
                string fname = parent.GetName();
                if (fname.Equals("fo:flow") || fname.Equals("fo:static-content"))
                {
                    found = true;
                }
                else if (fname.Equals("fo:block") || fname.Equals("fo:inline"))
                {
                    FObjMixed fom = (FObjMixed)parent;
                    tsp = fom.getTextState();
                    found = true;
                }
                parent = parent.getParent();
            } while (!found);

            TextState ts = new TextState();

            if (tsp != null)
            {
                ts.setUnderlined(tsp.getUnderlined());
                ts.setOverlined(tsp.getOverlined());
                ts.setLineThrough(tsp.getLineThrough());
            }

            int textDecoration = this.properties.GetProperty("text-decoration").GetEnum();

            if (textDecoration == TextDecoration.UNDERLINE)
            {
                ts.setUnderlined(true);
            }
            if (textDecoration == TextDecoration.OVERLINE)
            {
                ts.setOverlined(true);
            }
            if (textDecoration == TextDecoration.LINE_THROUGH)
            {
                ts.setLineThrough(true);
            }
            if (textDecoration == TextDecoration.NO_UNDERLINE)
            {
                ts.setUnderlined(false);
            }
            if (textDecoration == TextDecoration.NO_OVERLINE)
            {
                ts.setOverlined(false);
            }
            if (textDecoration == TextDecoration.NO_LINE_THROUGH)
            {
                ts.setLineThrough(false);
            }

            return ts;
        }
Example #5
0
        public override Status Layout(Area area)
        {
            if (!(area is BlockArea))
            {
                FonetDriver.ActiveDriver.FireFonetError(
                    "Text outside block area" + new String(ca, start, length));
                return new Status(Status.OK);
            }
            if (this.marker == MarkerStart)
            {
                string fontFamily =
                    this.parent.properties.GetProperty("font-family").GetString();
                string fontStyle =
                    this.parent.properties.GetProperty("font-style").GetString();
                string fontWeight =
                    this.parent.properties.GetProperty("font-weight").GetString();
                int fontSize =
                    this.parent.properties.GetProperty("font-size").GetLength().MValue();
                int fontVariant =
                    this.parent.properties.GetProperty("font-variant").GetEnum();

                int letterSpacing =
                    this.parent.properties.GetProperty("letter-spacing").GetLength().MValue();
                this.fs = new FontState(area.getFontInfo(), fontFamily,
                                        fontStyle, fontWeight, fontSize,
                                        fontVariant, letterSpacing);

                ColorType c = this.parent.properties.GetProperty("color").GetColorType();
                this.red = c.Red;
                this.green = c.Green;
                this.blue = c.Blue;

                this.verticalAlign =
                    this.parent.properties.GetProperty("vertical-align").GetEnum();

                this.wrapOption =
                    this.parent.properties.GetProperty("wrap-option").GetEnum();
                this.whiteSpaceCollapse =
                    this.parent.properties.GetProperty("white-space-collapse").GetEnum();
                this.ts = new TextState();
                ts.setUnderlined(underlined);
                ts.setOverlined(overlined);
                ts.setLineThrough(lineThrough);

                this.marker = this.start;
            }
            int orig_start = this.marker;
            this.marker = addText((BlockArea)area, fs, red, green, blue,
                                  wrapOption, this.GetLinkSet(),
                                  whiteSpaceCollapse, ca, this.marker, length,
                                  ts, verticalAlign);
            if (this.marker == -1)
            {
                return new Status(Status.OK);
            }
            else if (this.marker != orig_start)
            {
                return new Status(Status.AREA_FULL_SOME);
            }
            else
            {
                return new Status(Status.AREA_FULL_NONE);
            }
        }
Example #6
0
        protected static int addRealText(BlockArea ba, FontState fontState,
                                         float red, float green, float blue,
                                         int wrapOption, LinkSet ls,
                                         int whiteSpaceCollapse, char[] data,
                                         int start, int end, TextState textState,
                                         int vAlign)
        {
            int ts, te;
            char[] ca;

            ts = start;
            te = end;
            ca = data;

            LineArea la = ba.getCurrentLineArea();
            if (la == null)
            {
                return start;
            }

            la.changeFont(fontState);
            la.changeColor(red, green, blue);
            la.changeWrapOption(wrapOption);
            la.changeWhiteSpaceCollapse(whiteSpaceCollapse);
            la.changeVerticalAlign(vAlign);
            ba.setupLinkSet(ls);

            ts = la.addText(ca, ts, te, ls, textState);

            while (ts != -1)
            {
                la = ba.createNextLineArea();
                if (la == null)
                {
                    return ts;
                }
                la.changeFont(fontState);
                la.changeColor(red, green, blue);
                la.changeWrapOption(wrapOption);
                la.changeWhiteSpaceCollapse(whiteSpaceCollapse);
                ba.setupLinkSet(ls);

                ts = la.addText(ca, ts, te, ls, textState);
            }
            return -1;
        }
Example #7
0
        public static int addText(BlockArea ba, FontState fontState, float red,
                                  float green, float blue, int wrapOption,
                                  LinkSet ls, int whiteSpaceCollapse,
                                  char[] data, int start, int end,
                                  TextState textState, int vAlign)
        {
            if (fontState.FontVariant == FontVariant.SMALL_CAPS)
            {
                FontState smallCapsFontState;
                try
                {
                    int smallCapsFontHeight =
                        (int)(((double)fontState.FontSize) * 0.8d);
                    smallCapsFontState = new FontState(fontState.FontInfo,
                                                       fontState.FontFamily,
                                                       fontState.FontStyle,
                                                       fontState.FontWeight,
                                                       smallCapsFontHeight,
                                                       FontVariant.NORMAL);
                }
                catch (FonetException ex)
                {
                    smallCapsFontState = fontState;
                    FonetDriver.ActiveDriver.FireFonetError(
                        "Error creating small-caps FontState: " + ex.Message);
                }

                char c;
                bool isLowerCase;
                int caseStart;
                FontState fontStateToUse;
                for (int i = start; i < end; )
                {
                    caseStart = i;
                    c = data[i];
                    isLowerCase = (Char.IsLetter(c) && Char.IsLower(c));
                    while (isLowerCase == (Char.IsLetter(c) && Char.IsLower(c)))
                    {
                        if (isLowerCase)
                        {
                            data[i] = Char.ToUpper(c);
                        }
                        i++;
                        if (i == end)
                        {
                            break;
                        }
                        c = data[i];
                    }
                    if (isLowerCase)
                    {
                        fontStateToUse = smallCapsFontState;
                    }
                    else
                    {
                        fontStateToUse = fontState;
                    }
                    int index = addRealText(ba, fontStateToUse, red, green, blue,
                                            wrapOption, ls, whiteSpaceCollapse,
                                            data, caseStart, i, textState,
                                            vAlign);
                    if (index != -1)
                    {
                        return index;
                    }
                }

                return -1;
            }

            return addRealText(ba, fontState, red, green, blue, wrapOption, ls,
                               whiteSpaceCollapse, data, start, end, textState,
                               vAlign);
        }
Example #8
0
        public int addText(char[] odata, int start, int end, LinkSet ls,
                           TextState textState)
        {
            if (start == -1)
            {
                return(-1);
            }
            bool overrun = false;

            int wordStart       = start;
            int wordLength      = 0;
            int wordWidth       = 0;
            int whitespaceWidth = getCharWidth(' ');

            char[] data     = new char[odata.Length];
            char[] dataCopy = new char[odata.Length];
            Array.Copy(odata, data, odata.Length);
            Array.Copy(odata, dataCopy, odata.Length);

            bool isText          = false;
            bool isMultiByteChar = false;

            for (int i = start; i < end; i++)
            {
                int  charWidth;
                char c = data[i];
                if (!(isSpace(c) || (c == '\n') || (c == '\r') || (c == '\t') ||
                      (c == '\u2028')))
                {
                    charWidth       = getCharWidth(c);
                    isText          = true;
                    isMultiByteChar = (c > 127);
                    if (charWidth <= 0 && c != '\u200B' && c != '\uFEFF')
                    {
                        charWidth = whitespaceWidth;
                    }
                }
                else
                {
                    if ((c == '\n') || (c == '\r') || (c == '\t'))
                    {
                        charWidth = whitespaceWidth;
                    }
                    else
                    {
                        charWidth = getCharWidth(c);
                    }

                    isText          = false;
                    isMultiByteChar = false;

                    if (prev == WHITESPACE)
                    {
                        if (this.whiteSpaceCollapse == WhiteSpaceCollapse.FALSE)
                        {
                            if (isSpace(c))
                            {
                                spaceWidth += getCharWidth(c);
                            }
                            else if (c == '\n' || c == '\u2028')
                            {
                                if (spaceWidth > 0)
                                {
                                    InlineSpace isp = new InlineSpace(spaceWidth);
                                    isp.setUnderlined(textState.getUnderlined());
                                    isp.setOverlined(textState.getOverlined());
                                    isp.setLineThrough(textState.getLineThrough());
                                    addChild(isp);
                                    finalWidth += spaceWidth;
                                    spaceWidth  = 0;
                                }
                                return(i + 1);
                            }
                            else if (c == '\t')
                            {
                                spaceWidth += 8 * whitespaceWidth;
                            }
                        }
                        else if (c == '\u2028')
                        {
                            if (spaceWidth > 0)
                            {
                                InlineSpace isp = new InlineSpace(spaceWidth);
                                isp.setUnderlined(textState.getUnderlined());
                                isp.setOverlined(textState.getOverlined());
                                isp.setLineThrough(textState.getLineThrough());
                                addChild(isp);
                                finalWidth += spaceWidth;
                                spaceWidth  = 0;
                            }
                            return(i + 1);
                        }
                    }
                    else if (prev == TEXT || prev == MULTIBYTECHAR)
                    {
                        if (spaceWidth > 0)
                        {
                            InlineSpace isp = new InlineSpace(spaceWidth);
                            if (prevUlState)
                            {
                                isp.setUnderlined(textState.getUnderlined());
                            }
                            if (prevOlState)
                            {
                                isp.setOverlined(textState.getOverlined());
                            }
                            if (prevLTState)
                            {
                                isp.setLineThrough(textState.getLineThrough());
                            }
                            addChild(isp);
                            finalWidth += spaceWidth;
                            spaceWidth  = 0;
                        }

                        IEnumerator e = pendingAreas.GetEnumerator();
                        while (e.MoveNext())
                        {
                            Box box = (Box)e.Current;
                            if (box is InlineArea)
                            {
                                if (ls != null)
                                {
                                    Rectangle lr =
                                        new Rectangle(finalWidth, 0,
                                                      ((InlineArea)box).getContentWidth(),
                                                      fontState.FontSize);
                                    ls.addRect(lr, this, (InlineArea)box);
                                }
                            }
                            addChild(box);
                        }

                        finalWidth += pendingWidth;

                        pendingWidth = 0;
                        pendingAreas = new ArrayList();

                        if (wordLength > 0)
                        {
                            addSpacedWord(new String(data, wordStart, wordLength),
                                          ls, finalWidth, 0, textState, false);
                            finalWidth += wordWidth;

                            wordWidth = 0;
                        }

                        prev = WHITESPACE;

                        embeddedLinkStart = 0;

                        spaceWidth = getCharWidth(c);

                        if (this.whiteSpaceCollapse == WhiteSpaceCollapse.FALSE)
                        {
                            if (c == '\n' || c == '\u2028')
                            {
                                return(i + 1);
                            }
                            else if (c == '\t')
                            {
                                spaceWidth = whitespaceWidth;
                            }
                        }
                        else if (c == '\u2028')
                        {
                            return(i + 1);
                        }
                    }
                    else
                    {
                        if (this.whiteSpaceCollapse == WhiteSpaceCollapse.FALSE)
                        {
                            if (isSpace(c))
                            {
                                prev       = WHITESPACE;
                                spaceWidth = getCharWidth(c);
                            }
                            else if (c == '\n')
                            {
                                InlineSpace isp = new InlineSpace(spaceWidth);
                                addChild(isp);
                                return(i + 1);
                            }
                            else if (c == '\t')
                            {
                                prev       = WHITESPACE;
                                spaceWidth = 8 * whitespaceWidth;
                            }
                        }
                        else
                        {
                            wordStart++;
                        }
                    }
                }

                if (isText)
                {
                    int curr = isMultiByteChar ? MULTIBYTECHAR : TEXT;
                    if (prev == WHITESPACE)
                    {
                        wordWidth = charWidth;
                        if ((finalWidth + spaceWidth + wordWidth)
                            > this.getContentWidth())
                        {
                            if (overrun)
                            {
                                FonetDriver.ActiveDriver.FireFonetWarning(
                                    "Area contents overflows area");
                            }
                            if (this.wrapOption == WrapOption.WRAP)
                            {
                                return(i);
                            }
                        }
                        prev       = curr;
                        wordStart  = i;
                        wordLength = 1;
                    }
                    else if (prev == TEXT || prev == MULTIBYTECHAR)
                    {
                        if (prev == TEXT && curr == TEXT || !canBreakMidWord())
                        {
                            wordLength++;
                            wordWidth += charWidth;
                        }
                        else
                        {
                            InlineSpace isp = new InlineSpace(spaceWidth);
                            if (prevUlState)
                            {
                                isp.setUnderlined(textState.getUnderlined());
                            }
                            if (prevOlState)
                            {
                                isp.setOverlined(textState.getOverlined());
                            }
                            if (prevLTState)
                            {
                                isp.setLineThrough(textState.getLineThrough());
                            }
                            addChild(isp);
                            finalWidth += spaceWidth;
                            spaceWidth  = 0;

                            IEnumerator e = pendingAreas.GetEnumerator();
                            while (e.MoveNext())
                            {
                                Box box = (Box)e.Current;
                                if (box is InlineArea)
                                {
                                    if (ls != null)
                                    {
                                        Rectangle lr =
                                            new Rectangle(finalWidth, 0,
                                                          ((InlineArea)box).getContentWidth(),
                                                          fontState.FontSize);
                                        ls.addRect(lr, this, (InlineArea)box);
                                    }
                                }
                                addChild(box);
                            }

                            finalWidth += pendingWidth;

                            pendingWidth = 0;
                            pendingAreas = new ArrayList();

                            if (wordLength > 0)
                            {
                                addSpacedWord(new String(data, wordStart, wordLength),
                                              ls, finalWidth, 0, textState, false);
                                finalWidth += wordWidth;
                            }
                            spaceWidth = 0;
                            wordStart  = i;
                            wordLength = 1;
                            wordWidth  = charWidth;
                        }
                        prev = curr;
                    }
                    else
                    {
                        prev       = curr;
                        wordStart  = i;
                        wordLength = 1;
                        wordWidth  = charWidth;
                    }

                    if ((finalWidth + spaceWidth + pendingWidth + wordWidth)
                        > this.getContentWidth())
                    {
                        if (this.wrapOption == WrapOption.WRAP)
                        {
                            if (wordStart == start)
                            {
                                overrun = true;
                                if (finalWidth > 0)
                                {
                                    return(wordStart);
                                }
                            }
                            else
                            {
                                return(wordStart);
                            }
                        }
                    }
                }
            }

            if (prev == TEXT || prev == MULTIBYTECHAR)
            {
                if (spaceWidth > 0)
                {
                    InlineSpace pis = new InlineSpace(spaceWidth);
                    pis.setEatable(true);
                    if (prevUlState)
                    {
                        pis.setUnderlined(textState.getUnderlined());
                    }
                    if (prevOlState)
                    {
                        pis.setOverlined(textState.getOverlined());
                    }
                    if (prevLTState)
                    {
                        pis.setLineThrough(textState.getLineThrough());
                    }
                    pendingAreas.Add(pis);
                    pendingWidth += spaceWidth;
                    spaceWidth    = 0;
                }

                addSpacedWord(new String(data, wordStart, wordLength), ls,
                              finalWidth + pendingWidth,
                              spaceWidth, textState, true);

                embeddedLinkStart += wordWidth;
                wordWidth          = 0;
            }

            if (overrun)
            {
                FonetDriver.ActiveDriver.FireFonetWarning(
                    "Area contents overflows area");
            }
            return(-1);
        }
Example #9
0
        private void addSpacedWord(string word, LinkSet ls, int startw,
                                   int spacew, TextState textState,
                                   bool addToPending)
        {
            /*
             * Split string based on four delimeters:
             * \u00A0 - Latin1 NBSP (Non breaking space)
             * \u202F - unknown reserved character according to Unicode Standard
             * \u3000 - CJK IDSP (Ideographic space)
             * \uFEFF - Arabic ZWN BSP (Zero width no break space)
             */
            StringTokenizer st     = new StringTokenizer(word, "\u00A0\u202F\u3000\uFEFF", true);
            int             extraw = 0;

            while (st.MoveNext())
            {
                string currentWord = (string)st.Current;

                if (currentWord.Length == 1 &&
                    (isNBSP(currentWord[0])))
                {
                    // Add an InlineSpace
                    int spaceWidth = getCharWidth(currentWord[0]);
                    if (spaceWidth > 0)
                    {
                        InlineSpace ispace = new InlineSpace(spaceWidth);
                        extraw += spaceWidth;
                        if (prevUlState)
                        {
                            ispace.setUnderlined(textState.getUnderlined());
                        }
                        if (prevOlState)
                        {
                            ispace.setOverlined(textState.getOverlined());
                        }
                        if (prevLTState)
                        {
                            ispace.setLineThrough(textState.getLineThrough());
                        }

                        if (addToPending)
                        {
                            pendingAreas.Add(ispace);
                            pendingWidth += spaceWidth;
                        }
                        else
                        {
                            addChild(ispace);
                        }
                    }
                }
                else
                {
                    WordArea ia = new WordArea(currentFontState, this.red,
                                               this.green, this.blue,
                                               currentWord,
                                               getWordWidth(currentWord));
                    ia.setYOffset(placementOffset);
                    ia.setUnderlined(textState.getUnderlined());
                    prevUlState = textState.getUnderlined();
                    ia.setOverlined(textState.getOverlined());
                    prevOlState = textState.getOverlined();
                    ia.setLineThrough(textState.getLineThrough());
                    prevLTState = textState.getLineThrough();
                    ia.setVerticalAlign(vAlign);

                    if (addToPending)
                    {
                        pendingAreas.Add(ia);
                        pendingWidth += getWordWidth(currentWord);
                    }
                    else
                    {
                        addChild(ia);
                    }
                    if (ls != null)
                    {
                        Rectangle lr = new Rectangle(startw + extraw, spacew,
                                                     ia.getContentWidth(),
                                                     fontState.FontSize);
                        ls.addRect(lr, this, ia);
                    }
                }
            }
        }
Example #10
0
        public override Status Layout(Area area)
        {
            if (!(area is BlockArea))
            {
                FonetDriver.ActiveDriver.FireFonetWarning(
                    "Page-number-citation outside block area");
                return new Status(Status.OK);
            }

            IDReferences idReferences = area.getIDReferences();
            this.area = area;
            if (this.marker == MarkerStart)
            {
                AccessibilityProps mAccProps = propMgr.GetAccessibilityProps();
                AuralProps mAurProps = propMgr.GetAuralProps();
                BorderAndPadding bap = propMgr.GetBorderAndPadding();
                BackgroundProps bProps = propMgr.GetBackgroundProps();
                MarginInlineProps mProps = propMgr.GetMarginInlineProps();
                RelativePositionProps mRelProps = propMgr.GetRelativePositionProps();

                ColorType c = this.properties.GetProperty("color").GetColorType();
                this.red = c.Red;
                this.green = c.Green;
                this.blue = c.Blue;

                this.wrapOption = this.properties.GetProperty("wrap-option").GetEnum();
                this.whiteSpaceCollapse =
                    this.properties.GetProperty("white-space-collapse").GetEnum();

                this.refId = this.properties.GetProperty("ref-id").GetString();

                if (this.refId.Equals(""))
                {
                    throw new FonetException("page-number-citation must contain \"ref-id\"");
                }

                this.id = this.properties.GetProperty("id").GetString();
                idReferences.CreateID(id);
                ts = new TextState();

                this.marker = 0;
            }

            if (marker == 0)
            {
                idReferences.ConfigureID(id, area);
            }


            pageNumber = idReferences.getPageNumber(refId);

            if (pageNumber != null)
            {
                this.marker =
                    FOText.addText((BlockArea)area,
                                   propMgr.GetFontState(area.getFontInfo()), red,
                                   green, blue, wrapOption, null,
                                   whiteSpaceCollapse, pageNumber.ToCharArray(),
                                   0, pageNumber.Length, ts,
                                   VerticalAlign.BASELINE);
            }
            else
            {
                BlockArea blockArea = (BlockArea)area;
                LineArea la = blockArea.getCurrentLineArea();
                if (la == null)
                {
                    return new Status(Status.AREA_FULL_NONE);
                }
                la.changeFont(propMgr.GetFontState(area.getFontInfo()));
                la.changeColor(red, green, blue);
                la.changeWrapOption(wrapOption);
                la.changeWhiteSpaceCollapse(whiteSpaceCollapse);
                la.addPageNumberCitation(refId, null);
                this.marker = -1;
            }

            if (this.marker == -1)
            {
                return new Status(Status.OK);
            }
            else
            {
                return new Status(Status.AREA_FULL_NONE);
            }
        }