public PresenterWindow(MainWindow mw) { double dpiX = PresentationSource.FromVisual(Application.Current.MainWindow).CompositionTarget.TransformToDevice.M11; double dpiY = PresentationSource.FromVisual(Application.Current.MainWindow).CompositionTarget.TransformToDevice.M22; this.mw = mw; Setting.Load(); ContentRendered += PresenterWindow_ContentRendered; // single monitor warning if (sc.Length < 2) { MessageBox.Show("화면 표시 장치가 하나입니다. 이 경우 별도의 설정이 없으면 화면을 모두 덮는 창이 나타나며, Shift+ESC로 닫을 수 있습니다.", "TextPresenter51456"); } // load and apply presenterScreen property if (!int.TryParse(Setting.GetAttribute("presenterScreen"), out presenterScreen)) { presenterScreen = sc.Length; } if (presenterScreen > sc.Length) { presenterScreen = sc.Length; } // specify the position and the size of PresenterWindow // default: top-left of last monitor on fullscreen System.Drawing.Rectangle r = sc[presenterScreen - 1].Bounds; Left = r.Left / dpiX; Top = r.Top / dpiY; Width = r.Width / dpiX; Height = r.Height / dpiY; InitializeComponent(); ApplySettings(); }
public void ApplySettings() { /* 여기서 다룰 항목 * FontFamily * FontSize * TextBlock.LineHeight * TextBlock.TextAlignment * Foreground * HorizontalAlignment * VerticalAlignment */ int textPosition, textAlign; double marginBasic, marginOverflow, fontSize, lineHeight, screenRatioSimulationWidth, screenRatioSimulationHeight; bool screenRatioSimulation, fontWeightBold = false, fontStyleItalic = false; string fontFamily; // load and apply properties /* * if (!int.TryParse(Setting.GetAttribute("presenterScreen"), out presenterScreen)) { * presenterScreen = System.Windows.Forms.Screen.AllScreens.Length; * } */ if (!double.TryParse(Setting.GetAttribute("marginBasic"), out marginBasic) || marginBasic < 0) { marginBasic = 5; } if (!double.TryParse(Setting.GetAttribute("marginOverflow"), out marginOverflow) || marginOverflow < 0) { marginOverflow = 1; } if (!int.TryParse(Setting.GetAttribute("textPosition"), out textPosition) || textPosition < 1 || textPosition > 9) { textPosition = 5; } if (!int.TryParse(Setting.GetAttribute("textAlign"), out textAlign) || textAlign < 1 || textAlign > 3) { textAlign = 2; } if ((fontFamily = Setting.GetAttribute("fontFamily")) == null) { fontFamily = "Malgun Gothic"; } if (Setting.GetAttribute("fontWeight").Equals("bold")) { fontWeightBold = true; } if (Setting.GetAttribute("fontStyle").Equals("italic")) { fontStyleItalic = true; } if (!double.TryParse(Setting.GetAttribute("fontSize"), out fontSize) || fontSize <= 0) { fontSize = 8.75; } if (!double.TryParse(Setting.GetAttribute("lineHeight"), out lineHeight) || lineHeight < 0) { lineHeight = 140; } if (!bool.TryParse(Setting.GetAttribute("screenRatioSimulation"), out screenRatioSimulation)) { screenRatioSimulation = false; } if (!double.TryParse(Setting.GetAttribute("screenRatioSimulationWidth"), out screenRatioSimulationWidth) || screenRatioSimulationWidth <= 0) { screenRatioSimulationWidth = 4; } if (!double.TryParse(Setting.GetAttribute("screenRatioSimulationHeight"), out screenRatioSimulationHeight) || screenRatioSimulationHeight <= 0) { screenRatioSimulationHeight = 3; } // Screen ratio simulation if (screenRatioSimulation) { double currentRatio = (double)sc[presenterScreen - 1].Bounds.Width / sc[presenterScreen - 1].Bounds.Height; double simulationRatio = screenRatioSimulationWidth / screenRatioSimulationHeight; double ratio = currentRatio / simulationRatio; if (ratio < 1) // < 1: wider simulation ratio { GridExCol1.Width = zeroPixels; GridExCol2.Width = oneStar; GridExCol3.Width = zeroPixels; GridExRow1.Height = oneStar; GridExRow2.Height = new GridLength(sc[presenterScreen - 1].Bounds.Height * ratio, GridUnitType.Pixel); GridExRow3.Height = oneStar; fontSize = fontSize * ratio; } else { GridExCol1.Width = oneStar; GridExCol2.Width = new GridLength(sc[presenterScreen - 1].Bounds.Width / ratio, GridUnitType.Pixel); GridExCol3.Width = oneStar; GridExRow1.Height = zeroPixels; GridExRow2.Height = oneStar; GridExRow3.Height = zeroPixels; } } else { GridExCol1.Width = zeroPixels; GridExCol2.Width = oneStar; GridExCol3.Width = zeroPixels; GridExRow1.Height = zeroPixels; GridExRow2.Height = oneStar; GridExRow3.Height = zeroPixels; } // unit correction fontSize /= 100; lineHeight /= 100; // FontFamily try { LabelPresenterText.FontFamily = new FontFamily(fontFamily); } catch (Exception e) { Console.WriteLine(e.Message); LabelPresenterText.FontFamily = new FontFamily("Malgun Gothic"); } LabelPresenterText.FontWeight = fontWeightBold ? FontWeights.Bold : FontWeights.Regular; LabelPresenterText.FontStyle = fontStyleItalic ? FontStyles.Italic : FontStyles.Normal; // FontSize LabelPresenterText.FontSize = MiscConverter.RelativeToAbsolute(fontSize, Height); // TextBlock.LineHeight LabelPresenterText.SetValue(TextBlock.LineHeightProperty, MiscConverter.RelativeToAbsolute(fontSize * lineHeight, Height)); // TextBlock.TextAlignment switch (textAlign) { case 1: // Left LabelPresenterText.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Left); break; case 3: // Right LabelPresenterText.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Right); break; default: // 2 or invalid value -> Center LabelPresenterText.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center); break; } // Foreground LabelPresenterText.Foreground = Brushes.White; // Alignment if ((textPosition - 1) / 3 == 0) { // 1, 2, 3 -> Top LabelPresenterText.VerticalAlignment = VerticalAlignment.Top; GridRow1.Height = new GridLength(marginBasic, GridUnitType.Star); GridRow2.Height = new GridLength(100 - marginBasic - marginOverflow, GridUnitType.Star); GridRow3.Height = new GridLength(marginOverflow, GridUnitType.Star); } else if ((textPosition - 1) / 3 == 2) { // 7, 8, 9 -> Bottom LabelPresenterText.VerticalAlignment = VerticalAlignment.Bottom; GridRow1.Height = new GridLength(marginOverflow, GridUnitType.Star); GridRow2.Height = new GridLength(100 - marginBasic - marginOverflow, GridUnitType.Star); GridRow3.Height = new GridLength(marginBasic, GridUnitType.Star); } else { // 4, 5, 6, invalid value -> Center LabelPresenterText.VerticalAlignment = VerticalAlignment.Center; GridRow1.Height = new GridLength(marginOverflow, GridUnitType.Star); GridRow2.Height = new GridLength(100 - 2 * marginOverflow, GridUnitType.Star); GridRow3.Height = new GridLength(marginOverflow, GridUnitType.Star); } if (textPosition % 3 == 1) { // 1, 4, 7 -> Left LabelPresenterText.HorizontalAlignment = HorizontalAlignment.Left; GridCol1.Width = new GridLength(marginBasic, GridUnitType.Star); GridCol2.Width = new GridLength(100 - marginBasic - marginOverflow, GridUnitType.Star); GridCol3.Width = new GridLength(marginOverflow, GridUnitType.Star); } else if (textPosition % 3 == 0) { // 3, 6, 9 -> Right LabelPresenterText.HorizontalAlignment = HorizontalAlignment.Right; GridCol1.Width = new GridLength(marginOverflow, GridUnitType.Star); GridCol2.Width = new GridLength(100 - marginBasic - marginOverflow, GridUnitType.Star); GridCol3.Width = new GridLength(marginBasic, GridUnitType.Star); } else { // 2, 5, 8, invalid value -> Center LabelPresenterText.HorizontalAlignment = HorizontalAlignment.Center; GridCol1.Width = new GridLength(marginOverflow, GridUnitType.Star); GridCol2.Width = new GridLength(100 - 2 * marginOverflow, GridUnitType.Star); GridCol3.Width = new GridLength(marginOverflow, GridUnitType.Star); } }
// Thread threadRemote; public void GetTitleColor() { try { titleColor = MiscConverter.IntToSolidColorBrush(MiscConverter.StringToIntColor(Setting.GetAttribute("titleColor"))); } catch (Exception ex) { Console.WriteLine(ex.Message); titleColor = MiscConverter.IntToSolidColorBrush(0xffff00); } if (freePresentationText != null) { // free text presentation: don't change contents UpdateFree(); } if (WrapPanelPageList != null && WrapPanelPageList.Children.Count > 1) { // if a text file is open, the minimum of Count is 2 int len = textList.Count; for (int i = 1; i < len; i++) { if (isTitleList[i]) { (WrapPanelPageList.Children[i - 1] as Button).Foreground = titleColor; } } } if (isTitleList != null) { if (PgmContent != null && isTitleList[pgmManager.PageNumber]) { PgmContent.Foreground = titleColor; if (pw != null) { pw.LabelPresenterText.Foreground = titleColor; } } if (PvwContent != null && isTitleList[pvwManager.PageNumber]) { PvwContent.Foreground = titleColor; } } }
// Load current settings from Setting class private void GetSettings() { if (!int.TryParse(Setting.GetAttribute("presenterScreen"), out presenterScreen)) { presenterScreen = System.Windows.Forms.Screen.AllScreens.Length; } if (!int.TryParse(Setting.GetAttribute("textEncoding"), out textEncoding)) { textEncoding = 0; } switch (textEncoding) { case 0: // default case 1200: // UTF-16 LE case 1201: // UTF-16 BE case 65001: // UTF-8 break; default: textEncoding = 0; break; } if (!decimal.TryParse(Setting.GetAttribute("marginBasic"), out marginBasic) || marginBasic < 0) { marginBasic = 5; } if (!decimal.TryParse(Setting.GetAttribute("marginOverflow"), out marginOverflow) || marginOverflow < 0) { marginOverflow = 1; } if (!int.TryParse(Setting.GetAttribute("textPosition"), out textPosition) || textPosition < 1 || textPosition > 9) { textPosition = 5; } if (!int.TryParse(Setting.GetAttribute("textAlign"), out textAlign) || textAlign < 1 || textAlign > 3) { textAlign = 2; } if ((fontFamily = Setting.GetAttribute("fontFamily")) == null) { fontFamily = "Malgun Gothic"; } if (Setting.GetAttribute("fontWeight").Equals("bold")) { fontWeightBold = true; } if (Setting.GetAttribute("fontStyle").Equals("italic")) { fontStyleItalic = true; } if (!decimal.TryParse(Setting.GetAttribute("fontSize"), out fontSize) || fontSize <= 0) { fontSize = 8.75m; } try { string tempTitleColor = Setting.GetAttribute("titleColor"); if (tempTitleColor == null) { titleColor = 0xffff00; } else { titleColor = MiscConverter.StringToIntColor(tempTitleColor); } } catch (Exception ex) { // invalid color format Console.WriteLine(ex.Message); titleColor = 0xffff00; } if (!decimal.TryParse(Setting.GetAttribute("lineHeight"), out lineHeight) || lineHeight < 0) { lineHeight = 140; } if (!bool.TryParse(Setting.GetAttribute("screenRatioSimulation"), out screenRatioSimulation)) { screenRatioSimulation = false; } if (!int.TryParse(Setting.GetAttribute("screenRatioSimulationWidth"), out screenRatioSimulationWidth) || screenRatioSimulationWidth <= 0) { screenRatioSimulationWidth = 4; } if (!int.TryParse(Setting.GetAttribute("screenRatioSimulationHeight"), out screenRatioSimulationHeight) || screenRatioSimulationHeight <= 0) { screenRatioSimulationHeight = 3; } }
private void OpenTxtFile(bool resetPvw) { Encoding encoding; if (resetPvw) { pvwManager.PageNumber = 1; } if (!int.TryParse(Setting.GetAttribute("textEncoding"), out int textEncoding) || textEncoding == 0) { textEncoding = 0; encoding = Encoding.Default; } else { try { encoding = Encoding.GetEncoding(textEncoding); } catch (Exception ex) { MessageBox.Show( ex.Message + "\n프로그램의 인코딩 설정(" + textEncoding.ToString() + ")이 잘못되었습니다.", "TextPresenter51456"); textEncoding = 0; encoding = Encoding.Default; } } // read the selected file try { System.IO.StreamReader sr = new System.IO.StreamReader(filePath + fileName, encoding); string fullText = sr.ReadToEnd(); sr.Close(); fullText = newLineUnifier.Replace(fullText, "\n"); // unify newline characters fullText = trimmer.Replace(fullText, ""); // trimming newlines textList = new List <string>(pageBreaker.Split(fullText)); // split pages textList.Insert(0, ""); // leave index 0 empty for convenience textList.Add(""); // add an empty page at the end WindowMainWindow.Title = "TextPresenter51456 - " + fileName + " (" + filePath + ")"; } catch (Exception e) { string errMsg = "Fail to read the file"; errMsg += "\nMessage: " + e.Message; errMsg += "\nSource" + e.Source; MessageBox.Show(errMsg, "TextPresenter51456"); return; } // show the file read as the page list try { int len = textList.Count; int i = 1; Style pageListItemStyle = FindResource("PageListItem") as Style; isTitleList = new List <bool>(len) { false }; WrapPanelPageList.Children.Clear(); // construct page list while (i < len) { // unify escaped comments if (commentEscaped.IsMatch(textList[i])) { textList[i] = commentEscaped.Replace(textList[i], @"/\/"); } // remove comments if (pageComment.IsMatch(textList[i])) // page comment -> remove the page { textList.RemoveAt(i); textList.Capacity -= 1; len -= 1; continue; } if (middleFullLineComment.IsMatch(textList[i])) // full line comment (the middle line of the page) -> remove the line { textList[i] = middleFullLineComment.Replace(textList[i], "\n"); } if (firstFullLineComment.IsMatch(textList[i])) // full line comment (the 1st line of the page) -> remove the line { textList[i] = firstFullLineComment.Replace(textList[i], ""); } if (lastFullLineComment.IsMatch(textList[i])) // full line comment (the last line of the page) -> remove the line { textList[i] = lastFullLineComment.Replace(textList[i], ""); } if (partialLineComment.IsMatch(textList[i])) // partial line comment -> remove the comment { textList[i] = partialLineComment.Replace(textList[i], "$1"); } // correct escaped comments if (commentEscaped.IsMatch(textList[i])) { textList[i] = commentEscaped.Replace(textList[i], "//"); } Button pageListItem = new Button { Style = pageListItemStyle, Tag = i }; if (sharp.IsMatch(textList[i])) // remove beginning #s and make these pages "header pages" { textList[i] = sharp.Replace(textList[i], ""); isTitleList.Add(true); pageListItem.Foreground = titleColor; } else { isTitleList.Add(false); } if (sharpEscaped.IsMatch(textList[i])) // escaped # (\#) { textList[i] = sharpEscaped.Replace(textList[i], "#$1"); } pageListItem.Content = textList[i]; WrapPanelPageList.Children.Add(pageListItem); i++; } pgmManager.LastPageNumber = pvwManager.LastPageNumber = len - 1; LabelPageIndicator.Content = "/" + (len - 1).ToString(); UpdatePvw(); } catch (Exception e) { string errMsg = "Failed to display the file"; errMsg += "\nMessage: " + e.Message; errMsg += "\nSource" + e.Source; MessageBox.Show(errMsg, "TextPresenter51456"); } MenuItemRefresh.IsEnabled = true; Session.New(PgmContent.Content as string, textList[pvwManager.PageNumber], textList[pgmManager.PageNumber + 1]); }