Ejemplo n.º 1
0
        protected void CreateDrawTextList()
        {
            LastItemRenderTextHeight = 0;
            textDrawLists            = null;
            Matrix m = PresentationSource.FromVisual(Application.Current.MainWindow).CompositionTarget.TransformToDevice;

            if (Items == null)
            {
                return;
            }
            textDrawLists = new List <List <Tuple <Brush, GlyphRun> > >(Items.Count);

            if (ItemFontNormal == null || ItemFontNormal.GlyphType == null ||
                ItemFontTitle == null || ItemFontTitle.GlyphType == null)
            {
                return;
            }
            ItemFontNormal.PrepareCache();
            ItemFontTitle.PrepareCache();

            {
                double          selfLeft     = Canvas.GetLeft(this);
                double          sizeTitle    = Math.Max(Settings.Instance.FontSizeTitle, 1);
                double          sizeNormal   = Math.Max(Settings.Instance.FontSize, 1);
                double          indentTitle  = sizeTitle * 1.7;
                double          indentNormal = IsTitleIndent ? indentTitle : 2;
                SolidColorBrush colorTitle   = CommonManager.Instance.CustTitle1Color;
                SolidColorBrush colorNormal  = CommonManager.Instance.CustTitle2Color;

                foreach (ProgramViewItem info in Items)
                {
                    var textDrawList = new List <Tuple <Brush, GlyphRun> >();
                    textDrawLists.Add(textDrawList);

                    double innerLeft = info.LeftPos + BorderLeftSize / 2;
                    //0.26は細枠線での微調整
                    double innerTop    = info.TopPos + BorderTopSize / 2 - 0.26;
                    double innerWidth  = info.Width - BorderLeftSize;
                    double innerHeight = info.Height - BorderTopSize;
                    double useHeight;

                    //分
                    string min = (info.EventInfo.StartTimeFlag == 0 ? "?" : info.EventInfo.start_time.Minute.ToString("d02"));
                    if (RenderText(min, textDrawList, ItemFontTitle, sizeTitle * 0.95,
                                   innerWidth - 1, innerHeight,
                                   innerLeft + 1, innerTop, out useHeight, colorTitle, m, selfLeft) == false)
                    {
                        info.TitleDrawErr        = true;
                        LastItemRenderTextHeight = info.Height;
                        continue;
                    }

                    //タイトル
                    string title = info.EventInfo.ShortInfo == null ? "" : info.EventInfo.ShortInfo.event_name;
                    if (ReplaceDictionaryTitle != null)
                    {
                        title = CommonManager.ReplaceText(title, ReplaceDictionaryTitle);
                    }
                    if (RenderText(title.Length > 0 ? title : " ", textDrawList, ItemFontTitle, sizeTitle,
                                   innerWidth - sizeTitle * 0.5 - indentTitle, innerHeight,
                                   innerLeft + indentTitle, innerTop, out useHeight, colorTitle, m, selfLeft) == false)
                    {
                        info.TitleDrawErr        = true;
                        LastItemRenderTextHeight = info.Height;
                        continue;
                    }
                    if (info.Height < sizeTitle)
                    {
                        //高さ足りない
                        info.TitleDrawErr = true;
                    }
                    LastItemRenderTextHeight = useHeight + sizeNormal * 0.5;

                    if (info.EventInfo.ShortInfo != null)
                    {
                        //説明
                        string detail = info.EventInfo.ShortInfo.text_char;
                        //詳細
                        detail += ExtInfoMode == false || info.EventInfo.ExtInfo == null ? "" : "\r\n\r\n" + info.EventInfo.ExtInfo.text_char;
                        if (ReplaceDictionaryNormal != null)
                        {
                            detail = CommonManager.ReplaceText(detail, ReplaceDictionaryNormal);
                        }
                        RenderText(detail, textDrawList, ItemFontNormal, sizeNormal,
                                   innerWidth - sizeTitle * 0.5 - indentNormal, innerHeight - LastItemRenderTextHeight,
                                   innerLeft + indentNormal, innerTop + LastItemRenderTextHeight, out useHeight, colorNormal, m, selfLeft);
                        LastItemRenderTextHeight += useHeight + sizeNormal * 0.25;
                    }
                    LastItemRenderTextHeight = Math.Floor(LastItemRenderTextHeight + BorderTopSize + sizeNormal * 0.5);
                    LastItemRenderTextHeight = Math.Min(LastItemRenderTextHeight, info.Height);
                }
            }
        }
Ejemplo n.º 2
0
        protected void CreateDrawTextList()
        {
            textDrawDict = new Dictionary <ProgramViewItem, List <TextDrawItem> >();
            Matrix m = PresentationSource.FromVisual(Application.Current.MainWindow).CompositionTarget.TransformToDevice;

            if (Items == null)
            {
                return;
            }

            if (ItemFontNormal == null || ItemFontNormal.GlyphType == null ||
                ItemFontTitle == null || ItemFontTitle.GlyphType == null)
            {
                return;
            }
            ItemFontNormal.PrepareCache();
            ItemFontTitle.PrepareCache();

            try
            {
                double selfLeft     = Canvas.GetLeft(this);
                double sizeMin      = Settings.Instance.FontSizeTitle - 1;
                double sizeTitle    = Settings.Instance.FontSizeTitle;
                double sizeNormal   = Settings.Instance.FontSize;
                double indentTitle  = Math.Floor(sizeMin * 1.7);
                double indentNormal = Math.Floor(Settings.Instance.EpgTitleIndent ? indentTitle : 2);
                Brush  colorTitle   = CommonManager.Instance.CustTitle1Color;
                Brush  colorNormal  = CommonManager.Instance.CustTitle2Color;

                double height1stLine = Math.Max(Settings.Instance.FontHeightTitle, Settings.Instance.FontHeightTitle);

                // あらかじめベースラインをそろえるために計算しておく。
                // 今は sizeMin と sizeTitle 同じだけどね…
                double baselineMin    = Math.Max(sizeMin * ItemFontTitle.GlyphType.Baseline, sizeTitle * ItemFontTitle.GlyphType.Baseline);
                double baselineNormal = sizeNormal * ItemFontNormal.GlyphType.Baseline;

                foreach (ProgramViewItem info in Items)
                {
                    List <TextDrawItem> textDrawList = new List <TextDrawItem>();
                    textDrawDict[info] = textDrawList;
                    if (info.Height > 2)
                    {
                        if (info.Height < height1stLine) // ModifierMinimumHeight してるので足りなくならないハズ。
                        {
                            //高さ足りない
                            info.TitleDrawErr = true;
                        }

                        double x           = info.LeftPos - selfLeft;
                        double y           = info.TopPos;
                        double height      = info.Height;
                        double width       = info.Width;
                        double totalHeight = 0;

                        // offset
                        x      += 2;
                        width  -= 2;
                        y      += 1;
                        height -= 1;

                        // margin 設定
                        width -= 4;

                        //分
                        string min       = (info.EventInfo.StartTimeFlag != 1 ? "未定 " : info.EventInfo.start_time.Minute.ToString("d02"));
                        double useHeight = 0;
                        if (RenderText(min, ref textDrawList, ItemFontTitle, sizeMin, width, height, x, y + baselineMin, ref useHeight, colorTitle, m) == false)
                        {
                            info.TitleDrawErr = true;
                            continue;
                        }

                        //番組情報
                        if (info.EventInfo.ShortInfo != null)
                        {
                            //タイトル
                            if (info.EventInfo.ShortInfo.event_name.Length > 0)
                            {
                                if (RenderText(info.EventInfo.ShortInfo.event_name, ref textDrawList, ItemFontTitle, sizeTitle, width - indentTitle, height - totalHeight, x + indentTitle, y + totalHeight + baselineMin, ref useHeight, colorTitle, m) == false)
                                {
                                    info.TitleDrawErr = true;
                                    continue;
                                }
                                totalHeight += Math.Floor(useHeight + 4); // 説明との間隔は 4px にする
                            }
                            //説明
                            if (info.EventInfo.ShortInfo.text_char.Length > 0)
                            {
                                if (RenderText(info.EventInfo.ShortInfo.text_char, ref textDrawList, ItemFontNormal, sizeNormal, width - indentNormal, height - totalHeight, x + indentNormal, y + totalHeight + baselineNormal, ref useHeight, colorNormal, m) == false)
                                {
                                    continue;
                                }
                                //totalHeight += useHeight + 4; // 詳細との間隔は 4px にする
                            }

                            //詳細
//                            if (info.EventInfo.ExtInfo != null)
//                            {
//                                if (info.EventInfo.ExtInfo.text_char.Length > 0)
//                                {
//                                    if (RenderText(info.EventInfo.ExtInfo.text_char, ref textDrawList, ItemFontNormal, sizeNormal, width - widthOffset, height - totalHeight, x + widthOffset, y + totalHeight + baselineNormal, ref useHeight, colorNormal, m) == false)
//                                    {
//                                        continue;
//                                    }
//                                    totalHeight += useHeight;
//                                }
//                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
            }
        }