Exemplo n.º 1
0
        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <param name="webSiteAddress"></param>
        /// <param name="isIPad"></param>
        /// <param name="pathParts"></param>
        /// <returns></returns>
        public Image CreateIPhoneSplash(string webSiteAddress, bool isIPad, List <string> pathParts)
        {
            if (!isIPad && pathParts.Where(pp => pp.Equals("file-ipad", StringComparison.OrdinalIgnoreCase)).Any())
            {
                isIPad = true;
            }

            Image result;
            float titleSize, addressSize, lineHeight;

            if (!isIPad)
            {
                result      = Images.Clone_IPhoneSplash();
                titleSize   = 24f;
                addressSize = 12f;
                lineHeight  = 40f;
            }
            else
            {
                result      = Images.Clone_IPadSplash();
                titleSize   = 36f;
                addressSize = 14f;
                lineHeight  = 50f;
            }

            lock (_SyncLock) {
                using (Graphics graphics = Graphics.FromImage(result)) {
                    graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
                    graphics.SmoothingMode     = SmoothingMode.HighQuality;

                    RectangleF titleBounds   = new RectangleF(5, (result.Height - 5) - (lineHeight * 2f), result.Width - 10f, lineHeight);
                    RectangleF addressBounds = new RectangleF(5, titleBounds.Bottom + 5, result.Width - 10f, lineHeight);

                    // It looks like we can occasionally have an issue here under Mono when Tahoma isn't installed and Mono
                    // throws an exception instead of falling back to a default font. We don't really care too much about the
                    // text on the splash image so if we get exceptions here just swallow them
                    try {
                        Font titleFont = _FontCache.BuildFont("Tahoma", titleSize);
                        graphics.DrawString("Virtual Radar Server", titleFont, Brushes.White, titleBounds, new StringFormat()
                        {
                            Alignment     = StringAlignment.Center,
                            LineAlignment = StringAlignment.Far,
                            FormatFlags   = StringFormatFlags.NoWrap,
                        });

                        Font addressFont = GetFontForRectangle("Tahoma", FontStyle.Regular, addressSize, graphics, addressBounds.Width, addressBounds.Height, webSiteAddress);
                        graphics.DrawString(webSiteAddress, addressFont, Brushes.LightGray, addressBounds, new StringFormat()
                        {
                            Alignment     = StringAlignment.Center,
                            LineAlignment = StringAlignment.Near,
                            FormatFlags   = StringFormatFlags.NoWrap,
                            Trimming      = StringTrimming.EllipsisCharacter,
                        });
                    } catch (Exception ex) {
                        var log = Factory.Singleton.Resolve <ILog>().Singleton;
                        log.WriteLine("Swallowed exception while generating {0} splash: {1}", isIPad ? "iPad" : "iPhone", ex.Message);
                    }
                }
            }

            return(result);
        }