1.1 --- a/Server/MainForm.cs Sun Aug 31 21:34:58 2014 +0200
1.2 +++ b/Server/MainForm.cs Mon Sep 01 19:23:36 2014 +0200
1.3 @@ -41,9 +41,6 @@
1.4
1.5 InitializeComponent();
1.6 UpdateStatus();
1.7 -
1.8 - //
1.9 - tableLayoutPanel.CellBorderStyle = (checkBoxShowBorders.Checked ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None);
1.10 //We have a bug when drawing minimized and reusing our bitmap
1.11 iBmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height, PixelFormat.Format32bppArgb);
1.12 iCreateBitmap = false;
1.13 @@ -53,11 +50,6 @@
1.14 {
1.15 StartServer();
1.16
1.17 - //
1.18 - CheckFontHeight();
1.19 - //
1.20 -
1.21 -
1.22 if (Properties.Settings.Default.DisplayConnectOnStartup)
1.23 {
1.24 OpenDisplayConnection();
1.25 @@ -105,6 +97,20 @@
1.26 /// </summary>
1.27 void CheckFontHeight()
1.28 {
1.29 + //Show font height and width
1.30 + labelFontHeight.Text = "Font height: " + cds.Font.Height;
1.31 + float charWidth = IsFixedWidth(cds.Font);
1.32 + if (charWidth == 0.0f)
1.33 + {
1.34 + labelFontWidth.Visible = false;
1.35 + }
1.36 + else
1.37 + {
1.38 + labelFontWidth.Visible = true;
1.39 + labelFontWidth.Text = "Font width: " + charWidth;
1.40 + }
1.41 +
1.42 + //Now check font height and show a warning if needed.
1.43 if (marqueeLabelBottom.Font.Height > marqueeLabelBottom.Height)
1.44 {
1.45 labelWarning.Text = "WARNING: Selected font is too height by " + (marqueeLabelBottom.Font.Height - marqueeLabelBottom.Height) + " pixels!";
1.46 @@ -342,13 +348,41 @@
1.47 }
1.48 }
1.49
1.50 + /// <summary>
1.51 + /// Check if the given font has a fixed character pitch.
1.52 + /// </summary>
1.53 + /// <param name="ft"></param>
1.54 + /// <returns>0.0f if this is not a monospace font, otherwise returns the character width.</returns>
1.55 + public float IsFixedWidth(Font ft)
1.56 + {
1.57 + Graphics g = CreateGraphics();
1.58 + char[] charSizes = new char[] { 'i', 'a', 'Z', '%', '#', 'a', 'B', 'l', 'm', ',', '.' };
1.59 + float charWidth = g.MeasureString("I", ft, Int32.MaxValue, StringFormat.GenericTypographic).Width;
1.60 +
1.61 + bool fixedWidth = true;
1.62 +
1.63 + foreach (char c in charSizes)
1.64 + if (g.MeasureString(c.ToString(), ft, Int32.MaxValue, StringFormat.GenericTypographic).Width != charWidth)
1.65 + fixedWidth = false;
1.66 +
1.67 + if (fixedWidth)
1.68 + {
1.69 + return charWidth;
1.70 + }
1.71 +
1.72 + return 0.0f;
1.73 + }
1.74 +
1.75 private void UpdateStatus()
1.76 {
1.77 //Synchronize UI with settings
1.78 //Load settings
1.79 +
1.80 + checkBoxShowBorders.Checked = cds.ShowBorders;
1.81 + tableLayoutPanel.CellBorderStyle = (cds.ShowBorders ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None);
1.82 marqueeLabelTop.Font = cds.Font;
1.83 marqueeLabelBottom.Font = cds.Font;
1.84 - checkBoxShowBorders.Checked = cds.ShowBorders;
1.85 + CheckFontHeight();
1.86 checkBoxConnectOnStartup.Checked = Properties.Settings.Default.DisplayConnectOnStartup;
1.87 checkBoxReverseScreen.Checked = cds.ReverseScreen;
1.88 comboBoxDisplayType.SelectedIndex = cds.DisplayType;
1.89 @@ -689,7 +723,7 @@
1.90 client.Texts[j] = textField;
1.91 }
1.92 j++;
1.93 - }
1.94 + }
1.95 //Only support two lines for now
1.96 for (int i = 0; i < aTextFields.Count; i++)
1.97 {