Exemplo n.º 1
0
        private IEnumerable <InputValue> GetInputValues(string delimiterPattern)
        {
            var startIndex = 0;
            var delimiters = GetDelimiters(delimiterPattern);

            if (!delimiters.Any())
            {
                yield return(new InputValue(RawText, Bias(startIndex)));

                yield break;
            }
            foreach (var delimiterMatch in delimiters)
            {
                yield return(new InputValue(RawText.Substring(startIndex, delimiterMatch.Index - startIndex), Bias(startIndex)));

                startIndex = delimiterMatch.Index + delimiterMatch.Length;
            }

            var last = delimiters.LastOrDefault();

            if (last != null)
            {
                yield return(new InputValue(RawText.Substring(startIndex, RawText.Length - startIndex), Bias(startIndex)));
            }
        }
 // RZ: 5.6.2012
 /// <summary>
 ///  Loads the properties of the FreeMarker 'ftl' directive.
 /// </summary>
 private void loadTemplateProperties()
 {
     _StriptWhiteSpaces = false;
     try {
         if (RawText != string.Empty)
         {
             String startingTag      = FTL_START_TAG;
             String endingTag        = FTL_END_TAG;
             int    startingPosition = 0;
             int    endingPosition   = 0;
             startingPosition = RawText.IndexOf(startingTag) + startingTag.Length;
             endingPosition   = RawText.IndexOf(endingTag);
             String templateProperties = RawText.Substring(startingPosition, endingPosition - startingPosition);
             if (!String.IsNullOrEmpty(templateProperties))
             {
                 string[] pairs = templateProperties.Trim().Split(' ');
                 foreach (String pair in pairs)
                 {
                     String[] value = pair.Split('=');
                     value[0] = value[0].Trim();
                     if (value.Length == 2)
                     {
                         if (value[0].ToLower() == FTL_STRIP_WHITESPACE)
                         {
                             Boolean result = false;
                             Boolean.TryParse(removeQuotes(value[1].Trim()), out result);
                             _StriptWhiteSpaces = result;
                         }
                     }
                 }
             }
         }
     } catch (Exception e) {
     }
 }
Exemplo n.º 3
0
 public void SetDataText(string newData)
 {
     RawText =
         RawText.Substring(0, DataStartIndex)                              // add preceding whitespace
         + newData.Replace("#", "\\#")                                     // escape comments
         + RawText.Substring(DataEndIndex, RawText.Length - DataEndIndex); // add any following whitespace or comments
 }
Exemplo n.º 4
0
        public override void Invoke(Touch touch)
        {
            if (touch.State == TouchState.Begin)
            {
                Input.Value = GetText();
            }
            if (touch.State == TouchState.End || touch.State == TouchState.Moving)
            {
                List <char> charShift = InputLabelStyle.Type == InputLabelType.Digits
                    ? Digits
                    : (InputLabelStyle.Type == InputLabelType.Characters ? Characters : All);
                string newValue = Input.Temp;
                int    delta    = touch.Session.PreviousTouch.AbsoluteY - touch.AbsoluteY;
                if (delta % charShift.Count != 0)
                {
                    int  charPosition = touch.Session.BeginTouch.X / 2;
                    int  charIndex    = charShift.IndexOf(RawText[charPosition]);
                    char newChar      = charShift[((charIndex + delta) % charShift.Count + charShift.Count) % charShift.Count];
                    newValue = $"{RawText.Substring(0, charPosition)}{newChar}{RawText.Substring(charPosition + 1, (RawText.Length - charPosition - 1))}";
                }

                if (touch.State == TouchState.End || InputLabelStyle.TriggerInRuntime)
                {
                    SetValue(newValue, true, touch.Session.PlayerIndex);
                }
                else
                {
                    SetTempValue(newValue, true);
                }
            }
        }
Exemplo n.º 5
0
        public string GetDataText()
        {
            if (RawText.IsWhitespace()) return String.Empty;

            return RawText.Substring(DataStartIndex, DataEndIndex - DataStartIndex)
                .Replace("\\#", "#"); // unescape comments
        }
Exemplo n.º 6
0
        /* Function: DecodePropertyValue
         * Extracts the property value from the passed XML value, stripping off the surrounding quotes and any escaped quotes
         * within.
         */
        private string DecodePropertyValue(int valueIndex, int valueLength)
        {
            string value = RawText.Substring(valueIndex + 1, valueLength - 2);

            value = value.Replace("\\\"", "\"");
            value = value.Replace("\\'", "'");
            value = HTMLEntityChars.DecodeAll(value);

            return(value);
        }
 private void loadTemplateText()
 {
     try {
         if (RawText != string.Empty)
         {
             TemplateText = RawText.Substring(RawText.IndexOf("-->") + 3);
         }
     } catch (Exception e) {
         throw new Exception("Didn't find the end of the xml block.", e);
     }
 }
Exemplo n.º 8
0
        /* Function: DecodeHTMLPropertyValue
         * Extracts the property value from the passed HTML tag value, stripping off the surrounding quotes and any escaped quotes
         * within.
         */
        private string DecodeHTMLPropertyValue(int valueIndex, int valueLength)
        {
            if (RawText[valueIndex] == '"' || RawText[valueIndex] == '\'')
            {
                string value = RawText.Substring(valueIndex + 1, valueLength - 2);

                value = value.Replace("\\\"", "\"");
                value = value.Replace("\\'", "'");
                value = HTMLEntityChars.DecodeAll(value);

                return(value);
            }
            else
            {
                return(RawText.Substring(valueIndex, valueLength));
            }
        }
 private void loadFormConfig()
 {
     try {
         if (RawText != string.Empty)
         {
             String startingTag      = "<#--";
             String endingTag        = "-->";
             int    startingPosition = 0;
             int    endingPosition   = 0;
             startingPosition = RawText.IndexOf(startingTag) + startingTag.Length;
             endingPosition   = RawText.IndexOf(endingTag);
             FormConfigXML    = RawText.Substring(startingPosition, endingPosition - startingPosition);
         }
     } catch (Exception e) {
         throw new Exception("Didn't find any XML in the first comment.", e);
     }
 }
Exemplo n.º 10
0
        /*--------------------------------------------------------------------------------------------*/
        private void BuildParams(int pParamI)
        {
            string raw = RawText.Substring(pParamI);

            if (raw.Length < 2 || raw.Substring(raw.Length - 1) != ")")
            {
                throw NewStepFault(FabFault.Code.InvalidParamSyntax, "Invalid parameter format.");
            }

            raw     = raw.Substring(1, raw.Length - 2);
            vParams = (raw.Length > 0 ? raw.Split(',') : new string[0]);

            for (int i = 0; i < vParams.Length; i++)
            {
                string p = vParams[i];

                if (p.Length == 0)
                {
                    throw NewStepFault(FabFault.Code.InvalidParamSyntax, "Parameter is empty.", i);
                }

                vParams[i] = p.Trim();
            }
        }
Exemplo n.º 11
0
        public PdfTextElement SubPart(int startIndex, int endIndex)
        {
            PdfTextElement blockElem = new PdfTextElement
            {
                Font          = null,
                FontSize      = FontSize,
                Matrix        = Matrix.Copy(),
                RawText       = RawText.Substring(startIndex, endIndex - startIndex),
                VisibleText   = VisibleText.Substring(startIndex, endIndex - startIndex),
                VisibleWidth  = 0,
                VisibleHeight = VisibleHeight,
                Characters    = new List <PdfCharElement>(),
                Childs        = new List <PdfTextElement>(),
            };
            double displacement = Characters[startIndex].Displacement;

            blockElem.Matrix.Matrix[0, 2] += displacement;
            for (int j = startIndex; j < endIndex; j++)
            {
                blockElem.Characters.Add(new PdfCharElement
                {
                    Char         = Characters[j].Char,
                    Displacement = Characters[j].Displacement - displacement,
                    Width        = Characters[j].Width,
                });
            }
            PdfCharElement lastChar = blockElem.Characters[blockElem.Characters.Count - 1];

            blockElem.VisibleWidth = lastChar.Displacement + lastChar.Width;
            foreach (PdfTextElement elem in Childs)
            {
                blockElem.Childs.Add(elem);
            }

            return(blockElem);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Processes formatting text.
        /// </summary>
        protected override void ProcessText()
        {
            Stack formatting = new Stack();
            int   pos        = 0;

            // Locate formatting tags
            MatchCollection matches = _recognizer.Matches(RawText);

            foreach (Match match in matches)
            {
                if (match.Index > pos)
                {
                    string[] ss = Split(
                        RawText.Substring(pos, match.Index - pos));

                    // Collect formatting
                    Styles f     = Styles.Regular;
                    object color = null;
                    foreach (FormatToken token in formatting)
                    {
                        f |= token.Format;
                        if (token.Format == Styles.Color)
                        {
                            color = token.Param;
                        }
                    }

                    foreach (string s in ss)
                    {
                        Word word = null;

                        if (color != null)
                        {
                            word = new StyledWord(s, f, (Color)color);
                        }
                        else
                        {
                            word = new StyledWord(s, f, Color.Empty);
                        }

                        InnerWords.Add(word);
                    }

                    // Advance pos
                    pos = match.Index;
                }

                if (match.Index == pos)
                {
                    // Modify formatting
                    Styles f       = Styles.Regular;
                    object param   = null;
                    bool   closing = match.Value.IndexOf("/") != -1;
                    string mval    = match.Value.ToLower();

                    if (mval == "<b>" || mval == "</b>")
                    {
                        f = Styles.Bold;
                    }

                    else if (mval == "<i>" || mval == "</i>")
                    {
                        f = Styles.Italic;
                    }

                    else if (mval == "<u>" || mval == "</u>")
                    {
                        f = Styles.Underline;
                    }

                    else if (mval == "<sub>" || mval == "</sub>")
                    {
                        f = Styles.Sub;
                    }

                    else if (mval == "<sup>" || mval == "</sup>")
                    {
                        f = Styles.Sup;
                    }

                    else if (mval.IndexOf("color") != -1)
                    {
                        f = Styles.Color;
                        if (!closing)
                        {
                            int    spos  = mval.IndexOf("#");
                            string color = mval.Substring(spos + 1, 6);
                            param = Color.FromArgb(
                                int.Parse(color.Substring(0, 2), System.Globalization.NumberStyles.HexNumber),
                                int.Parse(color.Substring(2, 2), System.Globalization.NumberStyles.HexNumber),
                                int.Parse(color.Substring(4, 2), System.Globalization.NumberStyles.HexNumber));
                        }
                    }

                    // It it is opening tag, add it to the stack,
                    // otherwise - find the last corresponding opening
                    // tag and remove it from the stack.
                    if (!closing)
                    {
                        formatting.Push(new FormatToken(f, param));
                    }
                    else
                    {
                        Stack temp = new Stack();
                        while (formatting.Count > 0)
                        {
                            if ((formatting.Peek() as FormatToken).Format == f)
                            {
                                break;
                            }

                            temp.Push(formatting.Pop());
                        }

                        // Remove if found
                        if (formatting.Count > 0)
                        {
                            formatting.Pop();
                        }

                        // Return the remaining tokens
                        while (temp.Count > 0)
                        {
                            formatting.Push(temp.Pop());
                        }
                    }

                    // Advance pos
                    pos += match.Length;
                    continue;
                }

                throw new Exception("Styled text internal error.");
            }

            if (pos < RawText.Length)
            {
                string[] ss = Split(RawText.Substring(pos));

                // Collect formatting
                Styles f     = Styles.Regular;
                object color = null;
                foreach (FormatToken token in formatting)
                {
                    f |= token.Format;
                    if (token.Format == Styles.Color)
                    {
                        color = token.Param;
                    }
                }

                foreach (string s in ss)
                {
                    Word word = null;

                    if (color != null)
                    {
                        word = new StyledWord(s, f, (Color)color);
                    }
                    else
                    {
                        word = new StyledWord(s, f, Color.Empty);
                    }

                    InnerWords.Add(word);
                }
            }

            // Update the pure text
            _plainText = "";
            foreach (Word word in InnerWords)
            {
                _plainText += word.Value;
            }
        }