Beispiel #1
0
        bool IsCaptionInRect(CaptionFont captionFont)
        {
            SizeF size = this.CreateGraphics().MeasureString(CaptionText, captionFont.CreateFont(), 10000);

            if (FormMain.UserConfig.ReduceFontSizeByWindowWidth && size.Width > (float)Width - 20.0f)
            {
                return(false);
            }

            if (FormMain.UserConfig.ReduceFontSizeByWindowHeight && size.Height > (float)Height - 27.0f)
            {
                return(false);
            }

            return(true);
        }
Beispiel #2
0
 public CaptionFont(CaptionFont captionFont)
 {
     Name                = captionFont.Name;
     Size                = captionFont.Size;
     BorderSize          = captionFont.BorderSize;
     Italic              = captionFont.Italic;
     Bold                = captionFont.Bold;
     IsDirectionVertical = captionFont.IsDirectionVertical;
     IsInitialized       = captionFont.IsInitialized;
     //HighForeColor = captionFont.HighForeColor;
     //LowForeColor = captionFont.LowForeColor;
     //BorderColor = captionFont.HighForeColor;
     //this.Colors = new CaptionColors(captionFont.Colors);
     this.Colors = captionFont.Colors;
     foreBrush   = captionFont.foreBrush;
     borderBrush = captionFont.BorderBrush;
 }
Beispiel #3
0
        //字幕描画 全体
        private void FormCaption_Paint(object sender, PaintEventArgs e)
        {
            if (borderVisible)
            {
                //枠描画
                Rectangle rect = this.ClientRectangle;

                rect.Inflate(new Size(-2, -2));
                e.Graphics.DrawRectangle(new Pen(Brushes.YellowGreen, 4), rect);
            }


            float fontSize = 0.0f;

            if (CaptionText != "")
            {
                //字幕描画

                Rectangle captionRect = this.ClientRectangle;

                const int offsetY = 7;
                captionRect.Y       = offsetY;
                captionRect.Height -= offsetY;

                captionRect.Inflate(-10, -10);

                CaptionFont captionFont = FormMain.UserConfig.CaptionFont;

                if (isAAMode_)
                {
                    const float minSize = 6.0f;

                    captionFont      = new CaptionFont(FormMain.UserConfig.AACaptionFont);
                    captionFont.Bold = true;
                    float highSize = captionFont.Size;
                    float lowSize  = highSize / 2;

                    while (true)
                    {
                        captionFont.Size = highSize;
                        if (IsCaptionInRect(captionFont))
                        {
                            break;
                        }

                        captionFont.Size = lowSize;
                        if (IsCaptionInRect(captionFont))
                        {
                            float size = (highSize + lowSize) / 2;
                            captionFont.Size = size;

                            if (IsCaptionInRect(captionFont))
                            {
                                lowSize = size;
                            }
                            else
                            {
                                highSize = size;
                            }
                        }
                        else
                        {
                            highSize = lowSize;
                            lowSize  = highSize / 2;
                        }

                        if (lowSize < minSize)
                        {
                            lowSize = minSize;
                        }

                        if (System.Math.Abs(highSize - lowSize) < 1.0f)
                        {
                            captionFont.Size = lowSize;
                            break;
                        }
                    }
                }
                fontSize = captionFont.Size;
                DrawCaption(e.Graphics, captionRect, CaptionText, captionFont, isAAMode_);
            }
            DrawTitle(e);
        }
Beispiel #4
0
        public static void DrawCaption(Graphics g, Rectangle captionRect, string captionText, CaptionFont captionFont, bool isAAMode)
        {
            System.Drawing.Font font = captionFont.CreateFont();

            StringFormat stringFormat = new StringFormat();

            //TextFormatFlags txtFormatFlags = new TextFormatFlags();
            //txtFormatFlags = TextFormatFlags.Top | TextFormatFlags.Left;
            if (captionFont.IsDirectionVertical)
            {
                stringFormat.FormatFlags = StringFormatFlags.DirectionVertical | StringFormatFlags.DirectionRightToLeft;
            }
            List <Point> offsets = new List <Point>();

            for (int i = 0; i < captionFont.BorderSize; i++)
            {
                offsets.Add(new Point(i, -captionFont.BorderSize + i));
                offsets.Add(new Point(captionFont.BorderSize - i, i));
                offsets.Add(new Point(-i, captionFont.BorderSize - i));
                offsets.Add(new Point(-captionFont.BorderSize + i, -i));
            }
            captionRect.X = captionRect.Left + FormMain.UserConfig.CaptionIndentLeftPadding;
            captionRect.Y = captionRect.Top + FormMain.UserConfig.CaptionIndentTopPadding;
            foreach (Point ofs in offsets)
            {
                Rectangle borderRect = captionRect;

                borderRect.X += ofs.X;
                borderRect.Y += ofs.Y;

                if (isAAMode)
                {
                    //TextRenderer.DrawText(g, captionText, font, borderRect, FormMain.UserConfig.AACaptionFont.Colors.BorderColor, txtFormatFlags);
                    g.DrawString(captionText, font, captionFont.BorderBrush, borderRect.X, borderRect.Y);
                }
                else
                {
                    //TextRenderer.DrawText(g, captionText, font, borderRect, FormMain.UserConfig.CaptionFont.Colors.BorderColor, txtFormatFlags);
                    g.DrawString(captionText, font, captionFont.BorderBrush, borderRect, stringFormat);
                }
            }

            if (isAAMode)
            {
                //TextRenderer.DrawText(g, captionText, font, captionRect, FormMain.UserConfig.AACaptionFont.Colors.HighForeColor, txtFormatFlags);
                g.DrawString(captionText, font, captionFont.GetForeBrush(captionRect), captionRect.X, captionRect.Y);
            }
            else
            {
                //TextRenderer.DrawText(g, captionText, font, captionRect, FormMain.UserConfig.CaptionFont.Colors.HighForeColor, txtFormatFlags);
                g.DrawString(captionText, font, captionFont.GetForeBrush(captionRect), captionRect, stringFormat);
            }
        }