Exemplo n.º 1
0
        public static System.Drawing.FontFamily[] ToDrawingFontFamilies(this FontFamily[] fontFamilies)
        {
            System.Drawing.FontFamily[] result = new System.Drawing.FontFamily[fontFamilies.Length];

            for (int i = 0; i < fontFamilies.Length; i++)
            {
                result[i] = ToDrawingFontFamily(fontFamilies[i]);
            }

            return result;
        }
Exemplo n.º 2
0
        public void WriteToFile(string fileName, List<Problem> source, int numberOfPage)
        {
            DocX doc = DocX.Create(fileName);
              var font = new System.Drawing.FontFamily("Consolas");
              var rand = new Random(DateTime.Now.Millisecond);
              var gap = new string(' ', spaceBetweenProblem - 1);

              var totalCount = colCount * rowCount * numberOfPage;

              List<Problem> allItems = new List<Problem>();
              while (allItems.Count < totalCount)
              {
            var problems = source.ToArray();
            Utils.Shuffle(problems);
            allItems.AddRange(problems);
              }

              Paragraph lastLine = null;
              for (int page = 0; page < numberOfPage; page++)
              {
            var from = colCount * rowCount * page;

            for (int row = 0; row < rowCount; row++)
            {
              var line1 = doc.InsertParagraph();
              lastLine = doc.InsertParagraph();
              for (int col = 0; col < colCount; col++)
              {
            line1.Append(string.Format("{0} ", allItems[from].LeftNumber.ToString().PadLeft(maxDigits + 1, ' '))).Font(font).FontSize(fontSize).Append(gap).Font(font).FontSize(fontSize);
            lastLine.Append(string.Format("{0}{1} ", allItems[from].Sign, allItems[from].RightNumber.ToString().PadLeft(maxDigits, ' '))).Font(font).FontSize(fontSize).UnderlineStyle(UnderlineStyle.thick).Append(gap).Font(font).FontSize(fontSize);
            from++;
              }

              if (row != rowCount - 1)
              {
            for (int i = 0; i < spaceLinesBetweenItem; i++)
            {
              lastLine = doc.InsertParagraph();
            }
              }
            }

            if (page != numberOfPage - 1 && addPageBreak)
            {
              lastLine.InsertPageBreakAfterSelf();
            }
              }
              doc.Save();
        }
Exemplo n.º 3
0
 public ActionResult generateCaptcha()
 {
     string  rootFolder=@"\Temp\";
     bool isdirExists = System.IO.Directory.Exists(Server.MapPath("~") + rootFolder);
     if (!isdirExists)
         System.IO.Directory.CreateDirectory(Server.MapPath("~") + rootFolder);
     System.Drawing.FontFamily family = new System.Drawing.FontFamily("Arial");
     CaptchaImage img = new CaptchaImage(150, 50, family);
     string text = img.CreateRandomText(4) + " " + img.CreateRandomText(3);
     img.SetText(text);
     img.GenerateImage();
     img.Image.Save(Server.MapPath("~") + rootFolder + this.Session.SessionID.ToString() + ".png", System.Drawing.Imaging.ImageFormat.Png);
     Session["captchaText"] = text;
     return Json(@"/Temp/"+this.Session.SessionID.ToString() + ".png?t=" + DateTime.Now.Ticks, JsonRequestBehavior.AllowGet);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Write the summary report to the specified writer.
        /// </summary>
        /// <param name="storage">The data store to query</param>
        /// <param name="simulationName">The simulation name to produce a summary report for</param>
        /// <param name="writer">Text writer to write to</param>
        /// <param name="apsimSummaryImageFileName">The file name for the logo. Can be null</param>
        /// <param name="outtype">Indicates the format to be produced</param>
        /// <param name="darkTheme">Whether or not the dark theme should be used.</param>
        public static void WriteReport(
            IDataStore storage,
            string simulationName,
            TextWriter writer,
            string apsimSummaryImageFileName,
            OutputType outtype,
            bool darkTheme)
        {
            Document            document = null;
            RtfDocumentRenderer renderer = null;

            if (outtype == OutputType.html)
            {
                writer.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
                writer.WriteLine("<html>");
                writer.WriteLine("<head>");
                writer.WriteLine("<meta content='text/html; charset=UTF-8; http-equiv='content-type'>");
                writer.WriteLine("<style>");
                if (darkTheme)
                {
                    writer.WriteLine("h2 { color:white; } ");
                    writer.WriteLine("h3 { color:white; } ");
                    writer.WriteLine("table { border:1px solid white; }");
                }
                else
                {
                    writer.WriteLine("h2 { color:darkblue; } ");
                    writer.WriteLine("h3 { color:darkblue; } ");
                    writer.WriteLine("table { border:1px solid black; }");
                    writer.WriteLine("th { background-color: palegoldenrod}");
                    writer.WriteLine("tr.total { color:darkorange; }");
                }
                writer.WriteLine("table { border-collapse:collapse; width:100%; table-layout:fixed; text-align:left; }");
                writer.WriteLine("table.headered {text-align:right; }");
                writer.WriteLine("tr.total { font-weight:bold; }");
                writer.WriteLine("table.headered td.col1 { text-align:left; font-weight:bold; }");
                writer.WriteLine("td { border:1px solid; }");
                writer.WriteLine("th { border:1px solid; text-align:right; }");
                writer.WriteLine("th.col1 { text-align:left; }");
                writer.WriteLine("</style>");
                writer.WriteLine("</head>");
                writer.WriteLine("<body>");
                writer.WriteLine("<a href=\"#log\">Simulation log</a>");
            }
            else if (outtype == OutputType.rtf)
            {
                document = new Document();
                renderer = new RtfDocumentRenderer();

                // Get the predefined style Normal.
                Style style = document.Styles["Normal"];

                // Because all styles are derived from Normal, the next line changes the
                // font of the whole document. Or, more exactly, it changes the font of
                // all styles and paragraphs that do not redefine the font.
                style.Font.Name = "Arial";

                // Heading1 to Heading9 are predefined styles with an outline level. An outline level
                // other than OutlineLevel.BodyText automatically creates the outline (or bookmarks)
                // in PDF.
                style            = document.Styles["Heading2"];
                style.Font.Size  = 14;
                style.Font.Bold  = true;
                style.Font.Color = Colors.DarkBlue;
                style.ParagraphFormat.PageBreakBefore = false;
                style.ParagraphFormat.SpaceAfter      = 3;
                style.ParagraphFormat.SpaceBefore     = 16;

                style            = document.Styles["Heading3"];
                style.Font.Size  = 12;
                style.Font.Bold  = true;
                style.Font.Color = Colors.DarkBlue;
                style.ParagraphFormat.SpaceBefore = 10;
                style.ParagraphFormat.SpaceAfter  = 2;

                // Create a new style called Monospace based on style Normal
                style = document.Styles.AddStyle("Monospace", "Normal");
                System.Drawing.FontFamily monoFamily = new System.Drawing.FontFamily(System.Drawing.Text.GenericFontFamilies.Monospace);
                style.Font.Name = monoFamily.Name;
                Section section = document.AddSection();
            }

            // Get the initial conditions table.
            DataTable initialConditionsTable = storage.Reader.GetData(simulationName: simulationName, tableName: "_InitialConditions");

            if (initialConditionsTable != null)
            {
                // Convert the '_InitialConditions' table in the DataStore to a series of
                // DataTables for each model.
                List <DataTable> tables = new List <DataTable>();
                ConvertInitialConditionsToTables(initialConditionsTable, tables);

                // Now write all tables to our report.
                for (int i = 0; i < tables.Count; i += 2)
                {
                    // Only write something to the summary file if we have something to write.
                    if (tables[i].Rows.Count > 0 || tables[i + 1].Rows.Count > 0)
                    {
                        string heading = tables[i].TableName;
                        WriteHeading(writer, heading, outtype, document);

                        // Write the manager script.
                        if (tables[i].Rows.Count == 1 && tables[i].Rows[0][0].ToString() == "Script code: ")
                        {
                            WriteScript(writer, tables[i].Rows[0], outtype, document);
                        }
                        else
                        {
                            // Write the properties table if we have any properties.
                            if (tables[i].Rows.Count > 0)
                            {
                                WriteTable(writer, tables[i], outtype, "PropertyTable", document);
                            }

                            // Write the general data table if we have any data.
                            if (tables[i + 1].Rows.Count > 0)
                            {
                                WriteTable(writer, tables[i + 1], outtype, "ApsimTable", document);
                            }
                        }

                        if (outtype == OutputType.html)
                        {
                            writer.WriteLine("<br/>");
                        }
                    }
                }
            }

            // Write out all messages.
            WriteHeading(writer, "Simulation log:", outtype, document, "log");
            DataTable messageTable = GetMessageTable(storage, simulationName);

            WriteMessageTable(writer, messageTable, outtype, false, "MessageTable", document);

            if (outtype == OutputType.html)
            {
                writer.WriteLine("</body>");
                writer.WriteLine("</html>");
            }
            else if (outtype == OutputType.rtf)
            {
                string rtf = renderer.RenderToString(document, Path.GetTempPath());
                writer.Write(rtf);
            }
        }
Exemplo n.º 5
0
        private void _Datagrid_formazasok(string alap_ertelmezett_e, int id, params System.Windows.Forms.DataGridView[] be)
        {
            if (alap_ertelmezett_e == "1" || id == 0)
            {
                rgb_datagrid_hatter_alap              = _rgb_datagrid_hatter_alap;
                rgb_datagrid_gridcolor_alap           = _rgb_datagrid_gridcolor_alap;
                rgb_datagrid_forecolor_alap           = _rgb_datagrid_forecolor_alap;
                rgb_datagrid_kivalasztott_hatter_alap = _rgb_datagrid_kivalasztott_hatter_alap;
                rgb_datagrid_kijelolt_betuszin_alap   = _rgb_datagrid_kijelolt_betuszin_alap;
                rgb_datagrid_paros_hatter_alap        = _rgb_datagrid_paros_hatter_alap;
                betu_stilus_alap = _betu_stilus_alap;
            }
            else
            {
                formazas_beallitasok_beolvasasa(id);
            }
            //Data fore color
            for (int i = 0; i < darabolo.Length; i++)
            {
                ddarabolo[i] = rgb_datagrid_forecolor_alap.Split(';')[i];
                darabolo[i]  = Convert.ToInt32(ddarabolo[i]);
            }

            for (int i = 0; i < be.Length; i++)
            {
                be[i].ForeColor = System.Drawing.Color.FromArgb(darabolo[0], darabolo[1], darabolo[2]);

                be[i].AlternatingRowsDefaultCellStyle.ForeColor = System.Drawing.Color.FromArgb(darabolo[0], darabolo[1], darabolo[2]);
                be[i].ColumnHeadersDefaultCellStyle.ForeColor   = System.Drawing.Color.FromArgb(darabolo[0], darabolo[1], darabolo[2]);
                be[i].DefaultCellStyle.ForeColor           = System.Drawing.Color.FromArgb(darabolo[0], darabolo[1], darabolo[2]);
                be[i].RowHeadersDefaultCellStyle.ForeColor = System.Drawing.Color.FromArgb(darabolo[0], darabolo[1], darabolo[2]);
            }


            //data grid color alap
            for (int i = 0; i < darabolo.Length; i++)
            {
                ddarabolo[i] = rgb_datagrid_gridcolor_alap.Split(';')[i];
                darabolo[i]  = Convert.ToInt32(ddarabolo[i]);
            }
            for (int i = 0; i < be.Length; i++)
            {
                be[i].GridColor = System.Drawing.Color.FromArgb(darabolo[0], darabolo[1], darabolo[2]);
            }


            //data back color alap
            for (int i = 0; i < darabolo.Length; i++)
            {
                ddarabolo[i] = rgb_datagrid_hatter_alap.Split(';')[i];
                darabolo[i]  = Convert.ToInt32(ddarabolo[i]);
            }

            for (int i = 0; i < be.Length; i++)
            {
                be[i].BackgroundColor = System.Drawing.Color.FromArgb(darabolo[0], darabolo[1], darabolo[2]);
                be[i].ColumnHeadersDefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(darabolo[0], darabolo[1], darabolo[2]);
                be[i].EnableHeadersVisualStyles = false;
                be[i].AlternatingRowsDefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(darabolo[0], darabolo[1], darabolo[2]);
                be[i].ColumnHeadersDefaultCellStyle.BackColor   = System.Drawing.Color.FromArgb(darabolo[0], darabolo[1], darabolo[2]);
                be[i].RowHeadersDefaultCellStyle.BackColor      = System.Drawing.Color.FromArgb(darabolo[0], darabolo[1], darabolo[2]);
            }

            //data kivalasztott back color alap
            for (int i = 0; i < darabolo.Length; i++)
            {
                ddarabolo[i] = rgb_datagrid_kivalasztott_hatter_alap.Split(';')[i];
                darabolo[i]  = Convert.ToInt32(ddarabolo[i]);
            }
            for (int i = 0; i < be.Length; i++)
            {
                be[i].AlternatingRowsDefaultCellStyle.SelectionBackColor = System.Drawing.Color.FromArgb(darabolo[0], darabolo[1], darabolo[2]);
                be[i].ColumnHeadersDefaultCellStyle.SelectionBackColor   = System.Drawing.Color.FromArgb(darabolo[0], darabolo[1], darabolo[2]);
                be[i].DefaultCellStyle.SelectionBackColor           = System.Drawing.Color.FromArgb(darabolo[0], darabolo[1], darabolo[2]);
                be[i].RowHeadersDefaultCellStyle.SelectionBackColor = System.Drawing.Color.FromArgb(darabolo[0], darabolo[1], darabolo[2]);
            }


            //data kijelolt betuszin alap
            for (int i = 0; i < darabolo.Length; i++)
            {
                ddarabolo[i] = rgb_datagrid_kijelolt_betuszin_alap.Split(';')[i];
                darabolo[i]  = Convert.ToInt32(ddarabolo[i]);
            }

            for (int i = 0; i < be.Length; i++)
            {
                be[i].AlternatingRowsDefaultCellStyle.SelectionForeColor = System.Drawing.Color.FromArgb(darabolo[0], darabolo[1], darabolo[2]);
                be[i].ColumnHeadersDefaultCellStyle.SelectionForeColor   = System.Drawing.Color.FromArgb(darabolo[0], darabolo[1], darabolo[2]);
                be[i].DefaultCellStyle.SelectionForeColor           = System.Drawing.Color.FromArgb(darabolo[0], darabolo[1], darabolo[2]);
                be[i].RowHeadersDefaultCellStyle.SelectionForeColor = System.Drawing.Color.FromArgb(darabolo[0], darabolo[1], darabolo[2]);
            }


            for (int i = 0; i < darabolo.Length; i++) // data paros oszlop hatter
            {
                ddarabolo[i] = rgb_datagrid_paros_hatter_alap.Split(';')[i];
                darabolo[i]  = Convert.ToInt32(ddarabolo[i]);
            }
            for (int i = 0; i < be.Length; i++)
            {
                be[i].DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(darabolo[0], darabolo[1], darabolo[2]);

                //data betűtípus alap
                System.Drawing.FontFamily fa = new System.Drawing.FontFamily(betu_stilus_alap.Split(';')[0]);
                float size = float.Parse(betu_stilus_alap.Split(';')[1]);
                System.Drawing.FontStyle f = (System.Drawing.FontStyle)Enum.Parse(typeof(System.Drawing.FontStyle), betu_stilus_alap.Split(';')[2], true);

                be[i].Font = new System.Drawing.Font(fa.Name, size, f); // betűtípus
                be[i].AlternatingRowsDefaultCellStyle.Font = new System.Drawing.Font(fa.Name, size, f);
                be[i].ColumnHeadersDefaultCellStyle.Font   = new System.Drawing.Font(fa.Name, size, f);
                be[i].DefaultCellStyle.Font           = new System.Drawing.Font(fa.Name, size, f);
                be[i].RowHeadersDefaultCellStyle.Font = new System.Drawing.Font(fa.Name, size, f);
                //  be[i].Font = new System.Drawing.Font(betu_stilus_alap, be[i].Font.Size, System.Drawing.FontStyle.Bold);
            }
        }
 public void AddString(string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.Rectangle layoutRect, System.Drawing.StringFormat format)
 {
 }
Exemplo n.º 7
0
 public ActionResult generateCaptcha()
 {
     System.Drawing.FontFamily family = new System.Drawing.FontFamily("Arial");
     CaptchaImage img = new CaptchaImage(150, 50, family);
     string text = img.CreateRandomText(4) + " " + img.CreateRandomText(3);
     img.SetText(text);
     img.GenerateImage();
     img.Image.Save(Server.MapPath("~/Images/") +
     Session.SessionID + ".png",
     System.Drawing.Imaging.ImageFormat.Png);
     Session["captchaText"] = text;
     return Json(Session.SessionID + ".png?t=" + DateTime.Now.Ticks, JsonRequestBehavior.AllowGet);
 }
        /// <summary>
        /// Creates an SvgDocument from the SVG text string.
        /// </summary>
        /// <returns>An SvgDocument object.</returns>
        private SvgDocument CreateSvgDocument()
        {
            SvgDocument svgDoc;

            using (MemoryStream streamSvg = new MemoryStream(
                Encoding.UTF8.GetBytes(this.Svg)))
            {
                // Create and return SvgDocument from stream.
                svgDoc = SvgDocument.Open(streamSvg);
            }

            // Scale SVG document to requested width.
            svgDoc.Transforms = new SvgTransformCollection();
            float scalar = (float)this.Width / (float)svgDoc.Width;
            svgDoc.Transforms.Add(new SvgScale(scalar, scalar));
            svgDoc.Width = new SvgUnit(svgDoc.Width.Type, svgDoc.Width * scalar);
            svgDoc.Height = new SvgUnit(svgDoc.Height.Type, svgDoc.Height * scalar);

            if (!string.IsNullOrEmpty(_FontFamilyName))
            {
                System.Drawing.FontFamily fontFamily = new System.Drawing.FontFamily(_FontFamilyName);
                foreach (var child in svgDoc.Children)
                {
                    SetFont(child, fontFamily);
                }
            }

            return svgDoc;
        }
Exemplo n.º 9
0
 /// <summary>Initializes a new <see cref="T:Common.Drawing.FontFamily" /> from the specified generic font family.</summary>
 /// <param name="genericFamily">
 ///     The <see cref="T:Common.Drawing.Text.GenericFontFamilies" /> from which to create the new
 ///     <see cref="T:Common.Drawing.FontFamily" />.
 /// </param>
 public FontFamily(GenericFontFamilies genericFamily)
 {
     WrappedFontFamily = new System.Drawing.FontFamily((System.Drawing.Text.GenericFontFamilies)genericFamily);
 }
Exemplo n.º 10
0
 /// <summary>
 ///     Initializes a new <see cref="T:Common.Drawing.FontFamily" /> in the specified
 ///     <see cref="T:Common.Drawing.Text.FontCollection" /> with the specified name.
 /// </summary>
 /// <param name="name">
 ///     A <see cref="T:System.String" /> that represents the name of the new
 ///     <see cref="T:Common.Drawing.FontFamily" />.
 /// </param>
 /// <param name="fontCollection">
 ///     The <see cref="T:Common.Drawing.Text.FontCollection" /> that contains this
 ///     <see cref="T:Common.Drawing.FontFamily" />.
 /// </param>
 /// <exception cref="T:System.ArgumentException">
 ///     <paramref name="name" /> is an empty string ("").-or-<paramref name="name" /> specifies a font that is not
 ///     installed on the computer running the application.-or-<paramref name="name" /> specifies a font that is not a
 ///     TrueType font.
 /// </exception>
 public FontFamily(string name, FontCollection fontCollection)
 {
     WrappedFontFamily = new System.Drawing.FontFamily(name, fontCollection);
 }
Exemplo n.º 11
0
 /// <summary>Initializes a new <see cref="T:Common.Drawing.FontFamily" /> with the specified name.</summary>
 /// <param name="name">The name of the new <see cref="T:Common.Drawing.FontFamily" />. </param>
 /// <exception cref="T:System.ArgumentException">
 ///     <paramref name="name" /> is an empty string ("").-or-<paramref name="name" /> specifies a font that is not
 ///     installed on the computer running the application.-or-<paramref name="name" /> specifies a font that is not a
 ///     TrueType font.
 /// </exception>
 public FontFamily(string name)
 {
     WrappedFontFamily = new System.Drawing.FontFamily(name);
 }
Exemplo n.º 12
0
        /// <summary>
        /// Determines whether [is empty style] [the specified style].
        /// </summary>
        /// <param name="style">The style.</param>
        /// <returns>
        ///     <c>true</c> if [is empty style] [the specified style]; otherwise, <c>false</c>.
        /// </returns>
        /// <remarks>Documented by Dev03, 2008-09-29</remarks>
        private bool IsEmptyStyle(ICardStyle style)
        {
            if (style == null)
            {
                return(true);
            }
            bool result = true;

            Type typeCardStyle = style.GetType();

            foreach (PropertyInfo property in typeCardStyle.GetProperties())
            {
                if (property.GetType().Equals(typeof(ITextStyle)))
                {
                    ITextStyle textStyle     = property.GetValue(style, null) as ITextStyle;
                    Type       typeTextStyle = textStyle.GetType();
                    foreach (PropertyInfo prop in typeTextStyle.GetProperties())
                    {
                        if (prop.GetType().Equals(typeof(int)))
                        {
                            int value = (int)prop.GetValue(textStyle, null);
                            result = result && (value == 0);
                        }
                        else if (prop.GetType().Equals(typeof(string)))
                        {
                            string value = (string)prop.GetValue(textStyle, null);
                            result = result && (value.Length == 0);
                        }
                        else if (prop.GetType().Equals(typeof(System.Drawing.Color)))
                        {
                            System.Drawing.Color value = (System.Drawing.Color)prop.GetValue(textStyle, null);
                            result = result && (value == System.Drawing.Color.Empty);
                        }
                        else if (prop.GetType().Equals(typeof(System.Drawing.FontFamily)))
                        {
                            System.Drawing.FontFamily value = (System.Drawing.FontFamily)prop.GetValue(textStyle, null);
                            result = result && (value == null);
                        }
                        else if (prop.GetType().Equals(typeof(FontSizeUnit)))
                        {
                            FontSizeUnit value = (FontSizeUnit)prop.GetValue(textStyle, null);
                            result = result && (value == FontSizeUnit.Pixel);
                        }
                        else if (prop.GetType().Equals(typeof(CSSFontStyle)))
                        {
                            CSSFontStyle value = (CSSFontStyle)prop.GetValue(textStyle, null);
                            result = result && (value == CSSFontStyle.None);
                        }
                        else if (prop.GetType().Equals(typeof(HorizontalAlignment)))
                        {
                            HorizontalAlignment value = (HorizontalAlignment)prop.GetValue(textStyle, null);
                            result = result && (value == HorizontalAlignment.None);
                        }
                        else if (prop.GetType().Equals(typeof(VerticalAlignment)))
                        {
                            VerticalAlignment value = (VerticalAlignment)prop.GetValue(textStyle, null);
                            result = result && (value == VerticalAlignment.None);
                        }
                        else if (prop.Name == "OtherElements")
                        {
                            SerializableDictionary <string, string> otherElements = prop.GetValue(textStyle, null) as SerializableDictionary <string, string>;
                            result = result && (otherElements.Count == 0);
                        }
                    }
                }
            }
            return(result);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Compares two objects that implement ICardStyle.
        /// </summary>
        /// <param name="one">The first ICardStyle object one.</param>
        /// <param name="two">The second ICardStyle object.</param>
        /// <remarks>Documented by Dev03, 2008-09-26</remarks>
        private void CompareStyles(ICardStyle one, ICardStyle two)
        {
            if ((one == null) || (two == null))
            {
                Assert.IsTrue(IsEmptyStyle(one), "Both styles should be null! (one)");
                Assert.IsTrue(IsEmptyStyle(two), "Both styles should be null! (two)");
                return;
            }

            Type typeCardStyle = one.GetType();

            foreach (PropertyInfo property in typeCardStyle.GetProperties())
            {
                if (property.GetType().Equals(typeof(ITextStyle)))
                {
                    ITextStyle textStyleOne  = property.GetValue(one, null) as ITextStyle;
                    ITextStyle textStyleTwo  = property.GetValue(two, null) as ITextStyle;
                    Type       typeTextStyle = textStyleOne.GetType();
                    foreach (PropertyInfo prop in typeTextStyle.GetProperties())
                    {
                        if (prop.GetType().Equals(typeof(int)))
                        {
                            int valueOne = (int)prop.GetValue(textStyleOne, null);
                            int valueTwo = (int)prop.GetValue(textStyleTwo, null);
                            Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name));
                        }
                        else if (prop.GetType().Equals(typeof(string)))
                        {
                            string valueOne = (string)prop.GetValue(textStyleOne, null);
                            string valueTwo = (string)prop.GetValue(textStyleTwo, null);
                            Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name));
                        }
                        else if (prop.GetType().Equals(typeof(System.Drawing.Color)))
                        {
                            System.Drawing.Color valueOne = (System.Drawing.Color)prop.GetValue(textStyleOne, null);
                            System.Drawing.Color valueTwo = (System.Drawing.Color)prop.GetValue(textStyleTwo, null);
                            Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name));
                        }
                        else if (prop.GetType().Equals(typeof(System.Drawing.FontFamily)))
                        {
                            System.Drawing.FontFamily valueOne = (System.Drawing.FontFamily)prop.GetValue(textStyleOne, null);
                            System.Drawing.FontFamily valueTwo = (System.Drawing.FontFamily)prop.GetValue(textStyleTwo, null);
                            Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name));
                        }
                        else if (prop.GetType().Equals(typeof(FontSizeUnit)))
                        {
                            FontSizeUnit valueOne = (FontSizeUnit)prop.GetValue(textStyleOne, null);
                            FontSizeUnit valueTwo = (FontSizeUnit)prop.GetValue(textStyleTwo, null);
                            Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name));
                        }
                        else if (prop.GetType().Equals(typeof(CSSFontStyle)))
                        {
                            CSSFontStyle valueOne = (CSSFontStyle)prop.GetValue(textStyleOne, null);
                            CSSFontStyle valueTwo = (CSSFontStyle)prop.GetValue(textStyleTwo, null);
                            Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name));
                        }
                        else if (prop.GetType().Equals(typeof(HorizontalAlignment)))
                        {
                            HorizontalAlignment valueOne = (HorizontalAlignment)prop.GetValue(textStyleOne, null);
                            HorizontalAlignment valueTwo = (HorizontalAlignment)prop.GetValue(textStyleTwo, null);
                            Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name));
                        }
                        else if (prop.GetType().Equals(typeof(VerticalAlignment)))
                        {
                            VerticalAlignment valueOne = (VerticalAlignment)prop.GetValue(textStyleOne, null);
                            VerticalAlignment valueTwo = (VerticalAlignment)prop.GetValue(textStyleTwo, null);
                            Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name));
                        }
                        else if (prop.Name == "OtherElements")
                        {
                            SerializableDictionary <string, string> otherElementsOne = prop.GetValue(textStyleOne, null) as SerializableDictionary <string, string>;
                            SerializableDictionary <string, string> otherElementsTwo = prop.GetValue(textStyleTwo, null) as SerializableDictionary <string, string>;
                            foreach (string key in otherElementsOne.Keys)
                            {
                                Assert.IsTrue((otherElementsTwo.ContainsKey(key) && otherElementsOne[key].Equals(otherElementsTwo[key])), String.Format("Both values for {0}[{1}] should be equal!", prop.Name, key));
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 14
0
        public sFont(String name, String path, int scale, int size, String fontName, bool replacement)
        {
            String fontPath  = cProperties.getProperty("path_fonts");
            String skinPath  = cProperties.getProperty("path_skin");
            String skinsPath = cProperties.getProperty("path");

            pfc = new PrivateFontCollection();

            Name = name;
            Path = path;

            Scale       = scale;
            Replacement = replacement;
            Size        = size;
            FontName    = fontName;

            //This way we have only the file name, but what happens if the fonts are in the skin directory ?
            //Lets check all posibilities
            Filename = Path.Substring(Path.LastIndexOf('/') > 0?Path.LastIndexOf('/') + 1:0);
            String AbsolutPathFont         = fontPath + "/" + Filename;
            String AbsolutPathSkinPathFont = skinsPath + "/" + skinPath + "/" + Filename;
            String RelativPathFont         = Path;
            // RelativPathSkinPathFont war der selbe Pfad wie AbsolutPathSkinPathFont
            String RelativPathSkinPathFont = skinsPath + "/" + skinPath + "/" + Path;

            // Deshalb jetzt so, damit auch im Skinordner unter fonts nachgesehen wird
            RelativPathSkinPathFont = skinsPath + "/" + skinPath + "/" + "fonts" + "/" + Path;

            RelativPathFont = Path;
            RelativPathFont = RelativPathFont.Replace("enigma2", "");
            RelativPathFont = RelativPathFont.Replace("usr", "");
            RelativPathFont = RelativPathFont.Replace("local", "");
            RelativPathFont = RelativPathFont.Replace("share", "");
            RelativPathFont = RelativPathFont.Replace("var", "");
            RelativPathFont = skinsPath + "/" + RelativPathFont;

            AbsolutPathFont         = AbsolutPathFont.Replace("\\", "/");
            AbsolutPathSkinPathFont = AbsolutPathSkinPathFont.Replace("\\", "/");
            RelativPathFont         = RelativPathFont.Replace("\\", "/");
            RelativPathSkinPathFont = RelativPathSkinPathFont.Replace("\\", "/");


            //RelativPathFont = fontPath.Replace("fonts", "") + RelativPathFont;

            String lookupPath = "";

            if (File.Exists(AbsolutPathFont))
            {
                lookupPath = new FileInfo(AbsolutPathFont).FullName;
            }
            else if (File.Exists(AbsolutPathSkinPathFont))
            {
                lookupPath = new FileInfo(AbsolutPathSkinPathFont).FullName;
            }
            else if (File.Exists(RelativPathFont))
            {
                lookupPath = new FileInfo(RelativPathFont).FullName;
            }
            else if (File.Exists(RelativPathSkinPathFont))
            {
                lookupPath = new FileInfo(RelativPathSkinPathFont).FullName;
            }
            else
            {
                String errorMessage = "";
                errorMessage += "OpenSkinDesigner has searched in several places for the font \"" + Filename + ".\"\n";
                errorMessage += "Unfortunatly the search was not successful.\n";
                errorMessage += "\n";
                errorMessage += "Search Locations:\n";
                errorMessage += "\t" + new FileInfo(AbsolutPathFont).FullName + "\n";
                errorMessage += "\t" + new FileInfo(AbsolutPathSkinPathFont).FullName + "\n";
                errorMessage += "\t" + new FileInfo(RelativPathFont).FullName + "\n";
                errorMessage += "\t" + new FileInfo(RelativPathSkinPathFont).FullName + "\n";

                MessageBox.Show(errorMessage,
                                "Error while loading fonts",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information,
                                MessageBoxDefaultButton.Button1);

                return;
            }

            try
            {
                pfc.AddFontFile(lookupPath);
            }
            catch (FileNotFoundException error)
            {
                String errorMessage = "";
                errorMessage += "OpenSkinDesigner has tried to open the font \"" + Filename + "\".\n";
                errorMessage += "Unfortunatly this was not successful.\n";
                errorMessage += "Either the font type is not supported by OpenSkinDesigner,\n";
                errorMessage += "or it is not a valid font.\n";
                errorMessage += "\n";
                errorMessage += "Location:\n";
                errorMessage += "\t" + new FileInfo(lookupPath).FullName + "\n" + error + "\n";

                MessageBox.Show(errorMessage,
                                "Error while loading fonts",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information,
                                MessageBoxDefaultButton.Button1);

                return;
            }

            FontFamily = pfc.Families[0];
            String name2 = FontFamily.GetName(0);

            FontStyle = System.Drawing.FontStyle.Regular;
            if (FontFamily.IsStyleAvailable(System.Drawing.FontStyle.Regular))
            {
                FontStyle = System.Drawing.FontStyle.Regular;
            }
            else
            {
                FontStyle = System.Drawing.FontStyle.Bold;
            }

            int t1 = FontFamily.GetCellAscent(FontStyle);
            int t2 = FontFamily.GetCellDescent(FontStyle);
            int t3 = FontFamily.GetEmHeight(FontStyle);
            int t4 = FontFamily.GetLineSpacing(FontStyle);
        }
Exemplo n.º 15
0
        public sFont(String name, String path, int scale, int size, String fontName, bool replacement, bool isAlias = false)
        {
            String fontPath  = cProperties.getProperty("path_fonts");
            String skinPath  = cProperties.getProperty("path_skin");
            String skinsPath = cProperties.getProperty("path");

            pfc = new PrivateFontCollection();

            this.Name = name;
            this.Path = path;

            this.Scale       = scale;
            this.Replacement = replacement;
            this.Size        = size;
            this.FontName    = fontName;
            this.isAlias     = isAlias;

            //This way we have only the file name, but what happens if the fonts are in the skin directory ?
            //Lets check all posibilities
            Filename = Path.Substring(Path.LastIndexOf('/') > 0?Path.LastIndexOf('/') + 1:0);
            String AbsolutPathFont         = fontPath + "/" + Filename;
            String AbsolutPathSkinPathFont = skinsPath + "/" + skinPath + "/" + Filename;
            String RelativPathFont         = Path;
            // RelativPathSkinPathFont was the same path as AbsolutPathSkinPathFont
            String RelativPathSkinPathFont = skinsPath + "/" + skinPath + "/" + Path;

            // so changed it to look up in skin-path / fonts
            RelativPathSkinPathFont = skinsPath + "/" + skinPath + "/" + "fonts" + "/" + Path;

            RelativPathFont = Path;
            RelativPathFont = RelativPathFont.Replace("enigma2", "");
            RelativPathFont = RelativPathFont.Replace("usr", "");
            RelativPathFont = RelativPathFont.Replace("local", "");
            RelativPathFont = RelativPathFont.Replace("share", "");
            RelativPathFont = RelativPathFont.Replace("var", "");
            RelativPathFont = skinsPath + "/" + RelativPathFont;

            AbsolutPathFont         = AbsolutPathFont.Replace("\\", "/");
            AbsolutPathSkinPathFont = AbsolutPathSkinPathFont.Replace("\\", "/");
            RelativPathFont         = RelativPathFont.Replace("\\", "/");
            RelativPathSkinPathFont = RelativPathSkinPathFont.Replace("\\", "/");


            //RelativPathFont = fontPath.Replace("fonts", "") + RelativPathFont;

            String lookupPath = "";

            if (File.Exists(AbsolutPathFont))
            {
                lookupPath = new FileInfo(AbsolutPathFont).FullName;
            }
            else if (File.Exists(AbsolutPathSkinPathFont))
            {
                lookupPath = new FileInfo(AbsolutPathSkinPathFont).FullName;
            }
            else if (File.Exists(RelativPathFont))
            {
                lookupPath = new FileInfo(RelativPathFont).FullName;
            }
            else if (File.Exists(RelativPathSkinPathFont))
            {
                lookupPath = new FileInfo(RelativPathSkinPathFont).FullName;
            }
            else
            {
                Found = false;
                String errorMessage = "";
                errorMessage += fMain.GetTranslation("OpenSkinDesigner has searched in several places for the font") + ": '" + Filename + "'.\"\n\n";
                errorMessage += fMain.GetTranslation("Unfortunatly the search was not successful!") + "\n";
                errorMessage += "\n";
                errorMessage += fMain.GetTranslation("Search locations") + ":\n\n";
                errorMessage += new FileInfo(AbsolutPathFont).FullName + "\n\n";
                errorMessage += new FileInfo(AbsolutPathSkinPathFont).FullName + "\n\n";
                errorMessage += new FileInfo(RelativPathFont).FullName + "\n\n";
                errorMessage += new FileInfo(RelativPathSkinPathFont).FullName + "\n\n";

                // Openskindesigner contains lcd.ttf by default and should be existing...
                AbsolutPathFont = fontPath + "/" + "lcd.ttf";
                if (File.Exists(AbsolutPathFont))
                {
                    errorMessage += "\n" + fMain.GetTranslation("It uses 'lcd.tff' instead.") + "\n";
                }

                errorMessage += Environment.NewLine + Environment.NewLine + fMain.GetTranslation("Show this message again?");

                DialogResult dr = new DialogResult();
                if (MyGlobaleVariables.ShowMsgFontNotFound == true)
                {
                    dr = MessageBox.Show(errorMessage,
                                         fMain.GetTranslation("Error while loading fonts"),
                                         MessageBoxButtons.YesNo,
                                         MessageBoxIcon.Information,
                                         MessageBoxDefaultButton.Button1);
                }
                if (dr == DialogResult.No)
                {
                    MyGlobaleVariables.ShowMsgFontNotFound = false;
                }


                if (File.Exists(AbsolutPathFont))
                {
                    lookupPath = new FileInfo(AbsolutPathFont).FullName;
                }
                else
                {
                    return;
                }
            }

            try
            {
                pfc.AddFontFile(lookupPath);
            }
            catch (Exception error)
            {
                String errorMessage = "";
                errorMessage += fMain.GetTranslation("OpenSkinDesigner has tried to open the font") + " '" + Filename + "'.\n";
                errorMessage += fMain.GetTranslation("Unfortunatly this was not successful!") + "\n";
                errorMessage += fMain.GetTranslation("Either the font type is not supported by OpenSkinDesigner,") + " \n";
                errorMessage += fMain.GetTranslation("or it's not a valid font.") + "\n";
                errorMessage += "\n";
                errorMessage += fMain.GetTranslation("Location") + ":\n";
                errorMessage += "\t" + new FileInfo(lookupPath).FullName + "\n" + error + "\n";

                MessageBox.Show(errorMessage,
                                fMain.GetTranslation("Error while loading fonts"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information,
                                MessageBoxDefaultButton.Button1);

                return;
            }

            FontFamily = pfc.Families[0];
            String name2 = FontFamily.GetName(0);

            FontStyle = System.Drawing.FontStyle.Regular;
            if (FontFamily.IsStyleAvailable(System.Drawing.FontStyle.Regular))
            {
                FontStyle = System.Drawing.FontStyle.Regular;
            }
            else
            {
                FontStyle = System.Drawing.FontStyle.Bold;
            }

            int t1 = FontFamily.GetCellAscent(FontStyle);
            int t2 = FontFamily.GetCellDescent(FontStyle);
            int t3 = FontFamily.GetEmHeight(FontStyle);
            int t4 = FontFamily.GetLineSpacing(FontStyle);
        }
Exemplo n.º 16
0
        public sFont(String name, String path, int scale, bool replacement)
        {
            String fontPath = cProperties.getProperty("path_fonts");
            String skinPath = cProperties.getProperty("path_skin");
            String skinsPath = cProperties.getProperty("path");

            pfc = new PrivateFontCollection();

            Name = name; 
            Path = path;

            Scale = scale;
            Replacement = replacement;

            //This way we have only the file name, but what happens if the fonts are in the skin directory ?
            //Lets check all posibilities
            Filename = Path.Substring(Path.LastIndexOf('/')>0?Path.LastIndexOf('/')+1:0);
            String AbsolutPathFont = fontPath + "/" + Filename;
            String AbsolutPathSkinPathFont = skinsPath + "/" + skinPath + "/" + Filename;
            String RelativPathFont = Path;
            String RelativPathSkinPathFont = skinsPath + "/" + skinPath + "/" + Path;
            RelativPathFont = Path;
            RelativPathFont = RelativPathFont.Replace("enigma2", "");
            RelativPathFont = RelativPathFont.Replace("usr", "");
            RelativPathFont = RelativPathFont.Replace("local", "");
            RelativPathFont = RelativPathFont.Replace("share", "");
            RelativPathFont = RelativPathFont.Replace("var", "");
            RelativPathFont = skinsPath + "/" + RelativPathFont;

            AbsolutPathFont = AbsolutPathFont.Replace("\\", "/");
            AbsolutPathSkinPathFont = AbsolutPathSkinPathFont.Replace("\\", "/");
            RelativPathFont = RelativPathFont.Replace("\\", "/");
            RelativPathSkinPathFont = RelativPathSkinPathFont.Replace("\\", "/");


            //RelativPathFont = fontPath.Replace("fonts", "") + RelativPathFont;

            String lookupPath = "";
            if (File.Exists(AbsolutPathFont))
                lookupPath = new FileInfo(AbsolutPathFont).FullName;
            else if (File.Exists(AbsolutPathSkinPathFont))
                lookupPath = new FileInfo(AbsolutPathSkinPathFont).FullName;
            else if (File.Exists(RelativPathFont))
                lookupPath = new FileInfo(RelativPathFont).FullName;
            else if (File.Exists(RelativPathSkinPathFont))
                lookupPath = new FileInfo(RelativPathSkinPathFont).FullName;
            else
            {
                String errorMessage = "";
                errorMessage += "e2skinner2 has searched in several places for the font \"" + Filename + ".\"\n";
                errorMessage += "Unfortunatly the search was not successful.\n";
                errorMessage += "\n";
                errorMessage += "Search Locations:\n";
                errorMessage += "\t" + new FileInfo(AbsolutPathFont).FullName + "\n";
                errorMessage += "\t" + new FileInfo(AbsolutPathSkinPathFont).FullName + "\n";
                errorMessage += "\t" + new FileInfo(RelativPathFont).FullName + "\n";
                errorMessage += "\t" + new FileInfo(RelativPathSkinPathFont).FullName + "\n";

                MessageBox.Show(errorMessage,
                    "Error while loading fonts",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information,
                    MessageBoxDefaultButton.Button1);

                return;
            }

            try
            {
                pfc.AddFontFile(lookupPath);
            }
            catch (FileNotFoundException error)
            {
                String errorMessage = "";
                errorMessage += "e2skinner2 has tried to open the font \"" + Filename + "\".\n";
                errorMessage += "Unfortunatly this was not successful.\n";
                errorMessage += "Either the font type is not supported by e2kinner2,\n";
                errorMessage += "or it is not a vaild font.\n";
                errorMessage += "\n";
                errorMessage += "Location:\n";
                errorMessage += "\t" + new FileInfo(lookupPath).FullName + "\n" + error + "\n";

                MessageBox.Show(errorMessage,
                    "Error while loading fonts",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information,
                    MessageBoxDefaultButton.Button1);

                return;
            }

            FontFamily = pfc.Families[0];
            String name2 = FontFamily.GetName(0);
            FontStyle = System.Drawing.FontStyle.Regular;
            if (FontFamily.IsStyleAvailable(System.Drawing.FontStyle.Regular))
                FontStyle = System.Drawing.FontStyle.Regular;
            else
                FontStyle = System.Drawing.FontStyle.Bold;

            int t1 = FontFamily.GetCellAscent(FontStyle);
            int t2 = FontFamily.GetCellDescent(FontStyle);
            int t3 = FontFamily.GetEmHeight(FontStyle);
            int t4 = FontFamily.GetLineSpacing(FontStyle);
        }
Exemplo n.º 17
0
        private void InitializeBarCode()
        {
            InstalledFontCollection fc = new InstalledFontCollection();
            foreach (System.Drawing.FontFamily ff in fc.Families)
            {
                if (ff.Name.Contains("3 of 9"))
                {
                    barcodeFont = ff;
                    break;
                }
            }
            if (barcodeFont == null) throw new Exception("条形码字体不存在");

            TextBlock barGraph = new TextBlock();
            barGraph.FontFamily = new FontFamily(barcodeFont.Name);
            barGraph.FontSize = 50;
            barGraph.Text = barCodeString;
            TextBox barString = new TextBox();
            barString.PreviewMouseDoubleClick += new MouseButtonEventHandler(barString_PreviewMouseDoubleClick);
            barString.HorizontalAlignment = HorizontalAlignment.Center;
            barString.VerticalAlignment = VerticalAlignment.Center;
            barString.FontSize = 50;
            barString.TextChanged += new TextChangedEventHandler(barString_TextChanged);
            barString.Text = barCodeString;
            barString.BorderBrush = Brushes.Transparent;
            barString.Background = Brushes.Transparent;
            RowDefinition row1 = new RowDefinition();
            row1.Height = GridLength.Auto;
            RowDefinition row2 = new RowDefinition();
            row2.Height = GridLength.Auto;
            this.RowDefinitions.Add(row1);
            this.RowDefinitions.Add(row2);
            this.Children.Add(barGraph);
            this.Children.Add(barString);
            Grid.SetColumn(barGraph, 0);
            Grid.SetRow(barGraph, 0);
            Grid.SetColumn(barString, 0);
            Grid.SetRow(barString, 1);
        }
Exemplo n.º 18
0
 private FontFamily(System.Drawing.FontFamily fontFamily)
 {
     WrappedFontFamily = fontFamily;
 }
 private void SetFontFamily(System.Drawing.FontFamily family)
 {
     this.fontFamily = family;
     new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Assert();
     GC.SuppressFinalize(this.fontFamily);
 }
Exemplo n.º 20
0
        public WFFont GetFont(string familyName, double emSizeD, WFFontStyle wfs)
        {
            float emSize = (float)emSizeD;
#endif // WPF

#if DEBUG
            Stopwatch sw = Stopwatch.StartNew();
#endif // DEBUG

            if (string.IsNullOrEmpty(familyName))
            {
                familyName = System.Drawing.SystemFonts.DefaultFont.FontFamily.Name;
            }

            WFFont                    font      = null;
            List <WFFont>             fontGroup = null;
            System.Drawing.FontFamily family    = null;

            lock (this.fonts)
            {
                if (this.fonts.TryGetValue(familyName, out fontGroup))
                {
                    if (fontGroup.Count > 0)
                    {
                        family = fontGroup[0].FontFamily;
                    }

                    lock (fontGroup)
                    {
                        font = fontGroup.FirstOrDefault(f => f.Size == emSize && f.Style == wfs);
                    }
                }
            }

            if (font != null)
            {
                return(font);
            }

            if (family == null)
            {
                try
                {
                    family = new System.Drawing.FontFamily(familyName);
                }
                catch (ArgumentException ex)
                {
                    //throw new FontNotFoundException(ex.ParamName);
                    family = System.Drawing.SystemFonts.DefaultFont.FontFamily;
                    Logger.Log("resource pool", "font family error: " + familyName + ": " + ex.Message);
                }

                if (!family.IsStyleAvailable(wfs))
                {
                    try
                    {
                        wfs = FindFirstAvailableFontStyle(family);
                    }
                    catch
                    {
                        return(System.Drawing.SystemFonts.DefaultFont);
                    }
                }
            }

            lock (this.fonts)
            {
                if (fonts.TryGetValue(family.Name, out fontGroup))
                {
                    lock (fontGroup)
                    {
                        font = fontGroup.FirstOrDefault(f => f.Size == emSize && f.Style == wfs);
                    }
                }
            }

            if (font == null)
            {
                font = new WFFont(family, emSize, wfs);

                if (fontGroup == null)
                {
                    lock (this.fonts)
                    {
                        fonts.Add(family.Name, fontGroup = new List <WFFont> {
                            font
                        });
                    }
                    Logger.Log("resource pool", "font resource group added. font groups: " + fonts.Count);
                }
                else
                {
                    lock (fontGroup)
                    {
                        fontGroup.Add(font);
                    }
                    Logger.Log("resource pool", "font resource added. fonts: " + fontGroup.Count);
                }
            }

#if DEBUG
            sw.Stop();
            long ms = sw.ElapsedMilliseconds;
            if (ms > 10)
            {
                Debug.WriteLine("resource pool: font scan: " + sw.ElapsedMilliseconds + " ms.");
            }
#endif // DEBUG
            return(font);
        }
Exemplo n.º 21
0
        public void Text(string str, double X, double Y)
        {
            System.Drawing.StringFormat format = new System.Drawing.StringFormat();
            System.Drawing.FontFamily family = null;

            try
            {
                family = new System.Drawing.FontFamily(fontfamily[fontfamily.Count - 1]);
            }
            catch
            {
                family = System.Drawing.SystemFonts.DefaultFont.FontFamily;
            }

            path[path.Count - 1].AddString(str, family, 0, (float)fontsize[fontsize.Count - 1], new System.Drawing.Point((int)X, (int)Y), format);
        }
 public void AddString(string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.Point origin, System.Drawing.StringFormat format)
 {
 }
Exemplo n.º 23
0
        /// <summary>
        /// Write the summary report to the specified writer.
        /// </summary>
        /// <param name="dataStore">The data store to write a summary report from</param>
        /// <param name="simulationName">The simulation name to produce a summary report for</param>
        /// <param name="writer">Text writer to write to</param>
        /// <param name="apsimSummaryImageFileName">The file name for the logo. Can be null</param>
        /// <param name="outtype">Indicates the format to be produced</param>
        public static void WriteReport(
            DataStore dataStore,
            string simulationName,
            TextWriter writer,
            string apsimSummaryImageFileName,
            OutputType outtype)
        {
            Document document = null;
            RtfDocumentRenderer renderer = null;

            if (outtype == OutputType.html)
            {
                writer.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
                writer.WriteLine("<html>");
                writer.WriteLine("<head>");
                writer.WriteLine("<meta content='text/html; charset=UTF-8; http-equiv='content-type'>");
                writer.WriteLine("<style>");
                writer.WriteLine("h2 { color:darkblue; } ");
                writer.WriteLine("h3 { color:darkblue; } ");
                writer.WriteLine("table { border:1px solid black; border-collapse:collapse; width:100%; table-layout:fixed; text-align:left; }");
                writer.WriteLine("table.headered {text-align:right; }");
                writer.WriteLine("tr.total { color:darkorange; font-weight:bold; }");
                writer.WriteLine("table.headered td.col1 { text-align:left; font-weight:bold; }");
                writer.WriteLine("td { border:1px solid; }");
                writer.WriteLine("th { border:1px solid; text-align:right; background-color: palegoldenrod}");
                writer.WriteLine("th.col1 { text-align:left; }");
                writer.WriteLine("</style>");
                writer.WriteLine("</head>");
                writer.WriteLine("<body>");
            }
            else if (outtype == OutputType.rtf)
            {
                document = new Document();
                renderer = new RtfDocumentRenderer();

                // Get the predefined style Normal.
                Style style = document.Styles["Normal"];

                // Because all styles are derived from Normal, the next line changes the
                // font of the whole document. Or, more exactly, it changes the font of
                // all styles and paragraphs that do not redefine the font.
                style.Font.Name = "Arial";

                // Heading1 to Heading9 are predefined styles with an outline level. An outline level
                // other than OutlineLevel.BodyText automatically creates the outline (or bookmarks)
                // in PDF.
                style = document.Styles["Heading2"];
                style.Font.Size = 14;
                style.Font.Bold = true;
                style.Font.Color = Colors.DarkBlue;
                style.ParagraphFormat.PageBreakBefore = false;
                style.ParagraphFormat.SpaceAfter = 3;
                style.ParagraphFormat.SpaceBefore = 16;

                style = document.Styles["Heading3"];
                style.Font.Size = 12;
                style.Font.Bold = true;
                style.Font.Color = Colors.DarkBlue;
                style.ParagraphFormat.SpaceBefore = 10;
                style.ParagraphFormat.SpaceAfter = 2;

                // Create a new style called Monospace based on style Normal
                style = document.Styles.AddStyle("Monospace", "Normal");
                System.Drawing.FontFamily monoFamily = new System.Drawing.FontFamily(System.Drawing.Text.GenericFontFamilies.Monospace);
                style.Font.Name = monoFamily.Name;
                Section section = document.AddSection();
            }

            // Get the initial conditions table.
            DataTable initialConditionsTable = dataStore.GetData(simulationName, "InitialConditions");
            if (initialConditionsTable != null)
            {
                // Convert the 'InitialConditions' table in the DataStore to a series of
                // DataTables for each model.
                List<DataTable> tables = new List<DataTable>();
                ConvertInitialConditionsToTables(initialConditionsTable, tables);

                // Now write all tables to our report.
                for (int i = 0; i < tables.Count; i += 2)
                {
                    // Only write something to the summary file if we have something to write.
                    if (tables[i].Rows.Count > 0 || tables[i + 1].Rows.Count > 0)
                    {
                        string heading = tables[i].TableName;
                        WriteHeading(writer, heading, outtype, document);

                        // Write the manager script.
                        if (tables[i].Rows.Count == 1 && tables[i].Rows[0][0].ToString() == "Script code: ")
                        {
                            WriteScript(writer, tables[i].Rows[0], outtype, document);
                        }
                        else
                        {
                            // Write the properties table if we have any properties.
                            if (tables[i].Rows.Count > 0)
                            {
                                WriteTable(writer, tables[i], outtype, "PropertyTable", document);
                            }

                            // Write the general data table if we have any data.
                            if (tables[i + 1].Rows.Count > 0)
                            {
                                WriteTable(writer, tables[i + 1], outtype, "ApsimTable", document);
                            }
                        }

                        if (outtype == OutputType.html)
                            writer.WriteLine("<br/>");
                    }
                }
            }

            // Write out all messages.
            WriteHeading(writer, "Simulation log:", outtype, document);
            DataTable messageTable = GetMessageTable(dataStore, simulationName);
            WriteMessageTable(writer, messageTable, outtype, false, "MessageTable", document);

            if (outtype == OutputType.html)
            {
                writer.WriteLine("</body>");
                writer.WriteLine("</html>");
            }
            else if (outtype == OutputType.rtf)
            {
                string rtf = renderer.RenderToString(document, Path.GetTempPath());
                writer.Write(rtf);
            }
        }
Exemplo n.º 24
0
 public System.Drawing.Font GetFont(System.Drawing.FontFamily fontFamily, System.Drawing.FontStyle fontStyle = System.Drawing.FontStyle.Regular, float size = 10)
 {
     return(new System.Drawing.Font(fontFamily, size, fontStyle));
 }