コード例 #1
0
        public PrintTextValues_v1 GetTextValues_v1(IEnumerable<string> texts, string title)
        {
            // read : title
            // modify : infos, description, language, size, nbPages

            PrintTextValues_v1 textValues = new PrintTextValues_v1();
            List<string> description = new List<string>();

            _exportDataWriter.zWriteStartDocument();
            _exportDataWriter.zWrite("Title", title);
            _exportDataWriter.zWriteStartArray("Texts");

            string name = null;
            string text = null;
            string name2 = null;
            string text2 = null;
            foreach (string s in texts)
            {
                // PDF | 116 pages | 53 Mb | French
                _exportDataWriter.zWrite(s);
                if (__trace)
                    pb.Trace.CurrentTrace.WriteLine("SetTextValues : \"{0}\"", s);

                // Editeur : Presse fr
                bool textValues2 = ExtractTextValues2(s, out name2, out text2);
                if (textValues2)
                {
                    if (__trace)
                        pb.Trace.CurrentTrace.WriteLine("SetTextValues SetValue : \"{0}\" = \"{1}\"", name2, text2);
                    textValues.infos.SetValue(name2, new ZString(text2));
                }

                if (s == "\r\n" || textValues2)
                {
                    if (name != null)
                    {
                        if (__trace)
                            pb.Trace.CurrentTrace.WriteLine("SetTextValues SetValue : \"{0}\" = \"{1}\"", name, text);
                        textValues.infos.SetValue(name, new ZString(text));
                    }
                    else if (text != null)
                    {
                        if (__trace)
                            pb.Trace.CurrentTrace.WriteLine("SetTextValues description.Add : \"{0}\"", text);
                        description.Add(text);
                    }
                    name = null;
                    text = null;
                }
                else
                {
                    string s2 = s.Trim();
                    if (s2.EndsWith(":"))
                    {
                        string s3 = s2.Substring(0, s2.Length - 1).Trim();
                        if (s3 != "")
                        {
                            if (name != null)
                            {
                                if (__trace)
                                    pb.Trace.CurrentTrace.WriteLine("SetTextValues SetValue : \"{0}\" = \"{1}\"", name, text);
                                textValues.infos.SetValue(name, new ZString(text));
                            }
                            else if (text != null)
                            {
                                if (__trace)
                                    pb.Trace.CurrentTrace.WriteLine("SetTextValues description.Add : \"{0}\"", text);
                                description.Add(text);
                            }
                            name = s3;
                            text = null;
                            //foundName = true;
                            if (__trace)
                                pb.Trace.CurrentTrace.WriteLine("SetTextValues Set name \"{0}\"", name);
                        }
                        else
                        {
                            if (__trace)
                                pb.Trace.CurrentTrace.WriteLine("SetTextValues Nothing to do");
                        }
                    }
                    else
                    {
                        s2 = ExtractTextValues(textValues.infos, s);
                        s2 = Trim(s2);
                        if (__trace)
                            pb.Trace.CurrentTrace.WriteLine("SetTextValues ExtractTextValues : \"{0}\" - \"{1}\"", s, s2);
                        if (textValues.infos.ContainsKey("language"))
                        {
                            textValues.language = (string)textValues.infos["language"];
                            textValues.infos.Remove("language");
                        }
                        else if (textValues.infos.ContainsKey("size"))
                        {
                            textValues.size = (string)textValues.infos["size"];
                            textValues.infos.Remove("size");
                        }
                        else if (textValues.infos.ContainsKey("page_nb"))
                        {
                            textValues.nbPages = int.Parse((string)textValues.infos["page_nb"]);
                            textValues.infos.Remove("page_nb");
                        }

                        if (s2 != "" && s2 != title)
                        {
                            if (text == null)
                                text = s2;
                            else
                                text += " " + s2;
                            if (__trace)
                                pb.Trace.CurrentTrace.WriteLine("SetTextValues Add string to text : \"{0}\"", text);
                        }
                        else
                        {
                            if (__trace)
                                pb.Trace.CurrentTrace.WriteLine("SetTextValues dont Add string to text");
                        }
                    }
                }
            }
            if (text != null)
            {
                if (name != null)
                {
                    if (__trace)
                        pb.Trace.CurrentTrace.WriteLine("SetTextValues SetValue : \"{0}\" = \"{1}\"", name, text);
                    textValues.infos.SetValue(name, new ZString(text));
                }
                else
                {
                    if (__trace)
                        pb.Trace.CurrentTrace.WriteLine("SetTextValues description.Add : \"{0}\"", text);
                    description.Add(text);
                }
            }
            textValues.description = description.ToArray();

            _exportDataWriter.zWriteEndArray();
            _exportDataWriter.zWriteName("PrintTextValues");
            //_exportDataWriter.zWriteStartDocument("PrintTextValues");
            _exportDataWriter.zSerialize(textValues);
            //_exportDataWriter.zWriteEndDocument();
            _exportDataWriter.zWriteEndDocument();
            _exportDataWriter.zWriteName("fake");    // ??? pour éviter l'erreur : WriteString can only be called when State is Value or Initial, not when State is Name (System.InvalidOperationException)
            _exportDataWriter.zWriteLine();
            return textValues;
        }
コード例 #2
0
        public PrintTextValues_v1 GetTextValues_v1(IEnumerable <string> texts, string title)
        {
            // read : title
            // modify : infos, description, language, size, nbPages

            PrintTextValues_v1 textValues  = new PrintTextValues_v1();
            List <string>      description = new List <string>();

            _exportDataWriter.zWriteStartDocument();
            _exportDataWriter.zWrite("Title", title);
            _exportDataWriter.zWriteStartArray("Texts");

            string name  = null;
            string text  = null;
            string name2 = null;
            string text2 = null;

            foreach (string s in texts)
            {
                // PDF | 116 pages | 53 Mb | French
                _exportDataWriter.zWrite(s);
                if (__trace)
                {
                    pb.Trace.WriteLine("SetTextValues : \"{0}\"", s);
                }

                // Editeur : Presse fr
                bool textValues2 = ExtractTextValues2(s, out name2, out text2);
                if (textValues2)
                {
                    if (__trace)
                    {
                        pb.Trace.WriteLine("SetTextValues SetValue : \"{0}\" = \"{1}\"", name2, text2);
                    }
                    textValues.infos.SetValue(name2, new ZString(text2));
                }

                if (s == "\r\n" || textValues2)
                {
                    if (name != null)
                    {
                        if (__trace)
                        {
                            pb.Trace.WriteLine("SetTextValues SetValue : \"{0}\" = \"{1}\"", name, text);
                        }
                        textValues.infos.SetValue(name, new ZString(text));
                    }
                    else if (text != null)
                    {
                        if (__trace)
                        {
                            pb.Trace.WriteLine("SetTextValues description.Add : \"{0}\"", text);
                        }
                        description.Add(text);
                    }
                    name = null;
                    text = null;
                }
                else
                {
                    string s2 = s.Trim();
                    if (s2.EndsWith(":"))
                    {
                        string s3 = s2.Substring(0, s2.Length - 1).Trim();
                        if (s3 != "")
                        {
                            if (name != null)
                            {
                                if (__trace)
                                {
                                    pb.Trace.WriteLine("SetTextValues SetValue : \"{0}\" = \"{1}\"", name, text);
                                }
                                textValues.infos.SetValue(name, new ZString(text));
                            }
                            else if (text != null)
                            {
                                if (__trace)
                                {
                                    pb.Trace.WriteLine("SetTextValues description.Add : \"{0}\"", text);
                                }
                                description.Add(text);
                            }
                            name = s3;
                            text = null;
                            //foundName = true;
                            if (__trace)
                            {
                                pb.Trace.WriteLine("SetTextValues Set name \"{0}\"", name);
                            }
                        }
                        else
                        {
                            if (__trace)
                            {
                                pb.Trace.WriteLine("SetTextValues Nothing to do");
                            }
                        }
                    }
                    else
                    {
                        s2 = ExtractTextValues(textValues.infos, s);
                        s2 = Trim(s2);
                        if (__trace)
                        {
                            pb.Trace.WriteLine("SetTextValues ExtractTextValues : \"{0}\" - \"{1}\"", s, s2);
                        }
                        if (textValues.infos.ContainsKey("language"))
                        {
                            textValues.language = (string)textValues.infos["language"];
                            textValues.infos.Remove("language");
                        }
                        else if (textValues.infos.ContainsKey("size"))
                        {
                            textValues.size = (string)textValues.infos["size"];
                            textValues.infos.Remove("size");
                        }
                        else if (textValues.infos.ContainsKey("page_nb"))
                        {
                            textValues.nbPages = int.Parse((string)textValues.infos["page_nb"]);
                            textValues.infos.Remove("page_nb");
                        }

                        if (s2 != "" && s2 != title)
                        {
                            if (text == null)
                            {
                                text = s2;
                            }
                            else
                            {
                                text += " " + s2;
                            }
                            if (__trace)
                            {
                                pb.Trace.WriteLine("SetTextValues Add string to text : \"{0}\"", text);
                            }
                        }
                        else
                        {
                            if (__trace)
                            {
                                pb.Trace.WriteLine("SetTextValues dont Add string to text");
                            }
                        }
                    }
                }
            }
            if (text != null)
            {
                if (name != null)
                {
                    if (__trace)
                    {
                        pb.Trace.WriteLine("SetTextValues SetValue : \"{0}\" = \"{1}\"", name, text);
                    }
                    textValues.infos.SetValue(name, new ZString(text));
                }
                else
                {
                    if (__trace)
                    {
                        pb.Trace.WriteLine("SetTextValues description.Add : \"{0}\"", text);
                    }
                    description.Add(text);
                }
            }
            textValues.description = description.ToArray();

            _exportDataWriter.zWriteEndArray();
            _exportDataWriter.zWriteName("PrintTextValues");
            //_exportDataWriter.zWriteStartDocument("PrintTextValues");
            _exportDataWriter.zSerialize(textValues);
            //_exportDataWriter.zWriteEndDocument();
            _exportDataWriter.zWriteEndDocument();
            _exportDataWriter.zWriteName("fake");    // ??? pour éviter l'erreur : WriteString can only be called when State is Value or Initial, not when State is Name (System.InvalidOperationException)
            _exportDataWriter.zWriteLine();
            return(textValues);
        }