private StyledTextModel GetStyledTextCollection(XElement xmlData)
        {
            StyledTextModel t = new StyledTextModel
            {
                GText = (string)xmlData.Element(ns + "text")
            };

            // Run query
            var theERElement =
                from orElementEl
                in xmlData.Elements(ns + "style")
                select orElementEl;

            if (theERElement.Any())
            {
                // Load attribute object references
                foreach (XElement theLoadORElement in theERElement)
                {
                    GrampsStyle newStyleModel = new GrampsStyle
                    {
                        GStyle = GetTextStyle(theLoadORElement),

                        GValue = GetAttribute(theLoadORElement, "Value"),

                        GRange = GetStyledTextRangeCollection(theLoadORElement),
                    };

                    t.Styles.Add(newStyleModel);
                }
            }

            return(t);
        }
        private StyledTextModelCollection GetStyledTextCollection(XElement xmlData)
        {
            StyledTextModelCollection t = new StyledTextModelCollection();

            // Run query
            var theERElement =
                from orElementEl
                in xmlData.Elements(ns + "style")
                select orElementEl;

            if (theERElement.Any())
            {
                // Load attribute object references
                foreach (XElement theLoadORElement in theERElement)
                {
                    StyledTextModel newStyleModel = new StyledTextModel
                    {
                        Handle = "StyledTextCollection",

                        GStyle = GetTextStyle(theLoadORElement),

                        //GCitationReferenceCollection = GetCitationCollection(theLoadORElement),

                        //GNoteModelReferenceCollection = GetNoteCollection(theLoadORElement),

                        //Priv = SetPrivateObject(GetAttribute(theLoadORElement.Attribute("priv"))),

                        //GType = GetAttribute(theLoadORElement.Attribute("type")),

                        //GValue = GetAttribute(theLoadORElement.Attribute("value")),
                    };

                    t.Add(newStyleModel);
                }
            }

            return(t);
        }
Пример #3
0
        /// <summary>
        /// Load Notes from external storage.
        /// </summary>
        /// <param name="noteRepository">
        /// The event repository.
        /// </param>
        /// <returns>
        /// Flag of loaded successfully.
        /// </returns>
        public async Task LoadNotesAsync()
        {
            _iocCommonNotifications.DataLogEntryAdd("Loading Note data");
            {
                // Load notes
                try
                {
                    // Run query
                    var de =
                        from el in localGrampsXMLdoc.Descendants(ns + "note")
                        select el;

                    // get event fields TODO

                    // Loop through results to get the Notes Uri _baseUri = new Uri("ms-appx:///");
                    foreach (XElement pname in de)
                    {
                        INoteModel loadNote = new NoteModel();

                        // Note attributes
                        loadNote.LoadBasics(GetBasics(pname));

                        //loadNote.HLinkKey = loadNote.Handle;
                        loadNote.GIsFormated = GetBool(pname, "format");
                        loadNote.GType       = (string)pname.Attribute("type");

                        // Load Styled Text
                        if (loadNote.Id == "N0482")
                        {
                        }

                        if (loadNote.GIsFormated)
                        {
                        }

                        // Get Text Styles
                        StyledTextModel tempStyledText = GetStyledTextCollection(pname);
                        loadNote.GStyledText.GText = tempStyledText.GText;

                        loadNote.GStyledText.Styles.Clear();
                        foreach (GrampsStyle item in tempStyledText.Styles)
                        {
                            loadNote.GStyledText.Styles.Add(item);
                        }

                        // Get Tags
                        loadNote.GTagRefCollection.Clear();
                        foreach (HLinkTagModel item in GetTagCollection(pname))
                        {
                            loadNote.GTagRefCollection.Add(item);
                        }

                        DV.NoteDV.NoteData.Add((NoteModel)loadNote);
                    }
                }
                catch (Exception ex)
                {
                    // TODO handle this
                    _iocCommonNotifications.NotifyException("Exception loading Notes from the Gramps file", ex);

                    throw;
                }
            }

            _iocCommonNotifications.DataLogEntryReplace("Note load complete");
            return;
        }
        // TODO Cleanup up the code
        public static FormattedString GetFormattedString(StyledTextModel argTextModel, double argFontSize)
        {
            FormattedString returnString = new FormattedString();

            List <FormattedChar> workingString = new List <FormattedChar>();

            // Handle the normal case with no formatting
            if ((argTextModel.GText.Length == 0) || (argTextModel.Styles.Count == 0))
            {
                returnString.Spans.Add(new Span {
                    Text = argTextModel.GText, FontSize = SharedSharp.Common.SharedSharpFontSize.FontSmall
                });

                return(returnString);
            }

            // Setup working list
            for (int i = 0; i < argTextModel.GText.Length; i++)
            {
                workingString.Add(new FormattedChar {
                    Character = argTextModel.GText[i]
                });
            }

            // Initialise Working String
            FormattedChar t;

            foreach (GrampsStyle item in argTextModel.Styles)
            {
                foreach (GrampsStyleRangeModel item1 in item.GRange)
                {
                    for (int i = item1.Start; i < item1.End; i++)
                    {
                        switch (item.GStyle)
                        {
                        // TODO Handle multiple styles

                        case CommonEnums.TextStyle.bold:
                        {
                            t                = workingString[i];
                            t.StyleBold      = true;
                            workingString[i] = t;
                            break;
                        }

                        case CommonEnums.TextStyle.fontcolor:
                            break;

                        case CommonEnums.TextStyle.fontface:
                            t = workingString[i];

                            break;

                        case CommonEnums.TextStyle.fontsize:
                            break;

                        case CommonEnums.TextStyle.highlight:
                            break;

                        case CommonEnums.TextStyle.italic:
                        {
                            t = workingString[i];
                            t.StyleItalics   = true;
                            workingString[i] = t;
                            break;
                        }

                        case CommonEnums.TextStyle.link:
                            break;

                        case CommonEnums.TextStyle.superscript:
                        {
                            t = workingString[i];
                            t.StyleSuperscript = true;
                            workingString[i]   = t;
                            break;
                        }

                        case CommonEnums.TextStyle.underline:
                        {
                            t = workingString[i];
                            t.StyleUnderline = true;
                            workingString[i] = t;
                            break;
                        }

                        case CommonEnums.TextStyle.unknown:
                            break;

                        default:
                            break;
                        }
                    }
                }
            }

            // Setup Styles
            FormattedChar currentStyle;
            string        outString = string.Empty;

            // Add default font
            returnString.Spans.Add(new Span {
                FontSize = argFontSize
            });

            currentStyle = workingString[0];

            foreach (FormattedChar item in workingString)
            {
                if (currentStyle == item)
                {
                    outString += item.Character;
                }
                else
                {
                    returnString.Spans.Add(MakeSpan(outString, currentStyle));

                    // Reset
                    outString    = string.Empty;
                    outString   += item.Character;
                    currentStyle = item;
                }
            }

            // Add the last one
            returnString.Spans.Add(MakeSpan(outString, currentStyle));

            return(returnString);
        }