Exemplo n.º 1
0
        private void AddLargeStartSymbol(string line, double xoffset, double xspacing)
        {
            dy += (FontSize * LineSpacing);
            AddTextSpan(CardTextBox, line, Styles.SymbolFontStyle, SymbolLargeFontSize, newline, x + xoffset, dy);

            // measure the font's witdh
            var symbolSize = MeausureFont.MeasureString(line, SymbolLargeFontSize, Styles.SymbolFont);

            newLineStartX = symbolSize.Width + xspacing;
            // start a new line, next to the capital
            newline = true;
            // next to the capital
            x = newLineStartX;
            // relative move the line one rule up
            dy = -(FontSize * LineSpacing);
            // reset the newLineStart after two lines next to the symbol
            xcountreset = 2;
        }
Exemplo n.º 2
0
        private void AddMarkColumnStartSymbol(string line, double xoffset, double xspacing)
        {
            // dy += (Styles.FontSize*Styles.LineSpacing);
            AddTextSpan(CardTextBox, line, Styles.SymbolFontStyle, SymbolFontSize, newline, x + xoffset, dy);

            // measure the font's witdh
            var symbolSize = MeausureFont.MeasureString(line, SymbolFontSize, Styles.SymbolFont);

            newLineStartX = symbolSize.Width + xspacing;
            // start a new line, next to the capital
            newline = true;
            // next to the capital
            x = newLineStartX;
            // reset on same line
            dy = 0;
            // reset the newLineStart after two lines next to the symbol
            xcountreset = 10;
        }
Exemplo n.º 3
0
        private Tuple <string, string> WrapOverflow(string line, double newLineStartX, double fontSize, Typeface normalFont)
        {
            var secondLine = string.Empty;
            var firstLine  = line;
            var wordsSize  = MeausureFont.MeasureString(line, FontSize, Styles.NormalFont);

            while (newLineStartX + wordsSize.Width > Template.MaxTextBoxWidth)
            {
                var split = firstLine.LastIndexOf(" ");
                if (split == -1)
                {
                    // doesn't fit on the row
                    return(new Tuple <string, string>(string.Empty, line));
                }
                firstLine  = firstLine.Substring(0, split);
                secondLine = line.Substring(split);
                wordsSize  = MeausureFont.MeasureString(firstLine, FontSize, Styles.NormalFont);
            }
            return(new Tuple <string, string>(firstLine, secondLine));
        }
Exemplo n.º 4
0
        private void LayoutText(string line, Typeface font, string fontStyle, double fontSize, double xoffset = 0, double xspacing = 0)
        {
            // we'll keep on processing the line until al is layed out
            while (!string.IsNullOrEmpty(line))
            {
                var lineOverflow = WrapOverflow(line, x, fontSize, font);

                // first line doesn't fit on the row
                if (string.IsNullOrWhiteSpace(lineOverflow.Item1))
                {
                    dy += (fontSize * LineSpacing);
                    if (x == 0)
                    {
                        throw new Exception(string.Format("Word {0} is to long", lineOverflow.Item2));
                    }
                }
                else
                {
                    AddTextSpan(CardTextBox, lineOverflow.Item1, fontStyle, fontSize, newline, x + xoffset, dy, dx);
                    dx = xspacing;
                }

                // check if there is a seccond line
                newline = !string.IsNullOrEmpty(lineOverflow.Item2);
                if (newline)
                {
                    NewLineReset(fontSize);
                }
                else
                {
                    dy = 0;
                    x += MeausureFont.MeasureString(lineOverflow.Item1, fontSize, font).Width + xoffset;
                }
                line = lineOverflow.Item2;
            }
        }
Exemplo n.º 5
0
        public void ParseParagraph(XElement paragraph)
        {
            // start of the paragraph, reset
            x           = 0.0;
            xcountreset = 0;
            var line = string.Empty;

            newline       = true;
            newLineStartX = 0.0;
            dx            = 0.0;

            foreach (var xElement in paragraph.Elements())
            {
                switch (xElement.Name.LocalName)
                {
                // Capital letter, should only occurr as the first item of a paragraph
                case "c":
                    line = xElement.Value;
                    dy  += (FontSize * LineSpacing);
                    AddTextSpan(CardTextBox, line, Styles.CapitalFontStyle, CapitalFontSize, newline, x, dy);

                    // measure the font's witdh
                    var wordsSize = MeausureFont.MeasureString(line, CapitalFontSize, Styles.CapitalFont);
                    newLineStartX = wordsSize.Width + 2;
                    // start a new line, next to the capital
                    newline = true;
                    // next to the capital
                    x = newLineStartX;
                    // relative move the line one rule up
                    dy = -(FontSize * LineSpacing);
                    // reset the newLineStart after two lines next to the capital
                    xcountreset = 2;
                    break;

                // Larrge symbol, should only occurr as the first item of a paragraph
                case "m":
                    line = "M";
                    AddLargeStartSymbol(line, 5, 2);
                    break;

                case "m0":
                    line = "0";
                    AddLargeStartSymbol(line, 5, 2);
                    break;

                case "m1":
                    line = "1";
                    AddLargeStartSymbol(line, 5, 2);
                    break;

                case "m2":
                    line = "2";
                    AddLargeStartSymbol(line, 5, 2);
                    break;

                case "m3":
                    line = "3";
                    AddLargeStartSymbol(line, 5, 2);
                    break;

                case "m4":
                    line = "4";
                    AddLargeStartSymbol(line, 5, 2);
                    break;

                case "m5":
                    line = "5";
                    AddLargeStartSymbol(line, 5, 2);
                    break;

                case "m6":
                    line = "6";
                    AddLargeStartSymbol(line, 5, 2);
                    break;

                case "m7":
                    line = "7";
                    AddLargeStartSymbol(line, 5, 2);
                    break;

                case "m8":
                    line = "8";
                    AddLargeStartSymbol(line, 5, 2);
                    break;

                case "m9":
                    line = "9";
                    AddLargeStartSymbol(line, 5, 2);
                    break;

                case "ma":
                    line = "A";
                    AddLargeStartSymbol(line, 5, 2);
                    break;

                case "mt":
                    line = "T";
                    AddLargeStartSymbol(line, 5, 2);
                    break;

                case "mx":
                    line = "X";
                    AddLargeStartSymbol(line, 5, 2);
                    break;

                case "mc":
                    line = "M";
                    AddMarkColumnStartSymbol(line, 4, 4);
                    break;

                case "mi":
                    line = "m";
                    AddLargeStartSymbol(line, 0, 2);
                    break;

                case "mic":
                    line = "m";
                    AddMarkColumnStartSymbol(line, 0, 2);
                    break;

                case "mis":
                    line = "m";
                    AddSymbol(line, 0, 5);
                    break;

                case "g0":
                    line = "k";
                    AddSymbol(line);
                    break;

                case "g1":
                    line = "b";
                    AddSymbol(line);
                    break;

                case "g2":
                    line = "c";
                    AddSymbol(line);
                    break;

                case "g3":
                    line = "d";
                    AddSymbol(line);
                    break;

                case "g4":
                    line = "e";
                    AddSymbol(line);
                    break;

                case "g5":
                    line = "f";
                    AddSymbol(line);
                    break;

                case "g6":
                    line = "g";
                    AddSymbol(line);
                    break;

                case "g7":
                    line = "h";
                    AddSymbol(line);
                    break;

                case "g8":
                    line = "i";
                    AddSymbol(line);
                    break;

                case "g9":
                    line = "j";
                    AddSymbol(line);
                    break;

                case "gt":
                    line = "t";
                    AddSymbol(line);
                    break;

                case "gx":
                    line = "x";
                    AddSymbol(line);
                    break;

                // normal text
                case "n":
                    line = xElement.Value;
                    LayoutText(line, Styles.NormalFont, Styles.NormalFontStyle, FontSize);
                    break;

                // normal text
                case "b":
                    line = xElement.Value;
                    LayoutText(line, Styles.BoldFont, Styles.BoldFontStyle, FontSize);
                    break;

                case "i":
                    line = xElement.Value;
                    LayoutText(line, Styles.ItalicFont, Styles.ItalicFontStyle, FontSize);
                    break;

                case "bi":
                    line = xElement.Value;
                    LayoutText(line, Styles.BoldItalicFont, Styles.BoldItalicFontStyle, FontSize);
                    break;

                case "br":
                    NewLineReset(FontSize);
                    newline = true;
                    break;
                }
            }
            dy += FontSize + ParagraphSkip;
        }