Anonymous avatar Anonymous committed 8da43a3 Merge

Merged

Comments (0)

Files changed (14)

Add a comment to this file

src/apps/lang/res_cht/res_cht.rc

Binary file modified.

Add a comment to this file

src/apps/lang/res_eng/res_eng.rc

Binary file modified.

Add a comment to this file

src/apps/lang/res_french/res_fre.rc

Binary file modified.

Add a comment to this file

src/apps/lang/res_german/res_german.rc

Binary file modified.

Add a comment to this file

src/apps/lang/res_rus/res_rus.rc

Binary file modified.

src/apps/mplayerc/UserInterface/Dialogs/OptionSubtitlePage_Win.cc

 #include "../../MainFrm.h"
 #include "../../Controller/SPlayerDefs.h"
 #include "../../Controller/PlayerPreference.h"
-#include <sstream>
 
-OptionSubtitlePage::OptionSubtitlePage()
-: m_mainstyle(0)
-, m_secstyle(0)
-, m_dOldMainSize(-1)
-, m_dOldSecondSize(-1)
-, m_crOldMainColor(0)
-, m_crOldSecondColor(0)
+OptionSubtitlePage::OptionSubtitlePage(void):
+  m_mainstyle(0),
+  m_secstyle(0)
 {
   // init style entry height
   m_styleentry_height = ::GetSystemMetrics(SM_CYICON)*7/5;
     it != text_ar.end(); it++)
     m_secsubtitlestyle.AddString(it->c_str());
   RECT rc_stylelist;
-
-  m_subtitlestyle.SubclassWindow(GetDlgItem(IDC_LIST));
+  m_subtitlestyle.Attach(GetDlgItem(IDC_LIST));
   m_subtitlestyle.GetWindowRect(&rc_stylelist);
   m_styleentry_width = rc_stylelist.right - rc_stylelist.left;
   RefreshStyles();
 
   AppSettings& s = AfxGetAppSettings();
-
-  // main style
+  // calculate current settings according to AppSettings class s.subdefstyle
+  // retrieve subtitle style settings, and check which available style is closest to
+  // the given settings, then set |m_mainstyle| to corresponding one.
+  // s.subdefstyle compare font type, font color, border color shadow color
   for (int i = 0; i < SubtitleStyle::GetStyleCount(); i++)
   {
     SubtitleStyle::STYLEPARAM* sp = NULL;
-    if (SubtitleStyle::GetStyleParams(i, -1, &sp) && s.subdefstyle.fontName == sp->fontname)
+    if (SubtitleStyle::GetStyleParams(i, -1, &sp) && sp->fontcolor == s.subdefstyle.colors[0] 
+    && sp->strokecolor == s.subdefstyle.colors[2] && sp->shadowcolor == s.subdefstyle.colors[3] 
+    && (sp->_fontname == SubtitleStyle::DetectFontType((LPCTSTR)s.subdefstyle.fontName)) //����
+      )
     {
       m_subtitlestyle.SetCurSel(i);
-      m_mainstyle = i;
       break;
     }
   }
 
-  if (m_subtitlestyle.GetCount() > 0 && m_subtitlestyle.GetCurSel() < 0)
-  {
-    m_subtitlestyle.SetCurSel(0);
-    m_mainstyle = 0;
-  }
-
-  // second style
-  for (int i = 0; i < SubtitleStyle::GetStyleCount(); i++)
-  {
-    SubtitleStyle::STYLEPARAM* sp = NULL;
-    if (SubtitleStyle::GetStyleParams(-1, i, &sp) && s.subdefstyle2.fontName == sp->fontname)
-    {
-      m_secstyle = i;
-      break;
-    }
-  }
-
-  if (m_secstyle == -1)
-    m_secstyle = 0;
-
   m_secsubtitlestyle.SetCurSel((s.subdefstyle2.scrAlignment == 2)?1:0);
 
   m_fetchsubtitlefromshooter = s.autoDownloadSVPSub;
 
-  // init which subtitle should be set combo box
-  std::wstring sSetSubtitle = (LPCTSTR)ResStr(IDS_SET_SUBTITLE);
-  std::wstring sSetSubtitlePart1(sSetSubtitle.begin(), sSetSubtitle.begin() + sSetSubtitle.find(L'|'));
-  std::wstring sSetSubtitlePart2(sSetSubtitle.begin() + sSetSubtitle.find(L'|') + 1, sSetSubtitle.end());
-  m_cmbSetSubtitle.Attach(GetDlgItem(IDC_CMB_SET_SUBTITLE));
-  m_cmbSetSubtitle.AddString(sSetSubtitlePart1.c_str());
-  m_cmbSetSubtitle.AddString(sSetSubtitlePart2.c_str());
-  m_cmbSetSubtitle.SetCurSel(0);
-
-  // init the subtitle's old size and color
-  m_dOldMainSize = s.subdefstyle.fontSize;
-  m_dOldSecondSize = s.subdefstyle2.fontSize;
-  m_crOldMainColor = s.subdefstyle.colors[0];
-  m_crOldSecondColor = s.subdefstyle2.colors[0];
-
-  // init the subtitle's size and color controls
-  m_edtFontSize.Attach(GetDlgItem(IDC_EDIT_SUBTITLE_FONTSIZE));
-  m_btnFontColor.Attach(GetDlgItem(IDC_BUTTON_SUBTITLE_FONTCOLOR));
-  m_spnFontSize.Attach(GetDlgItem(IDC_SPIN_SUBTITLE_FONTSIZE));
-
-  m_spnFontSize.SetRange(10, 25);
-  m_spnFontSize.SetPos(s.subdefstyle.fontSize);
-
   // Init the subtitle save path radio buttons
   WTL::CButton rdoSaveSame = (WTL::CButton)GetDlgItem(IDC_RADIO_SAVESUBTITLE_SAME_FOLDER);
   WTL::CButton rdoSaveCustom = (WTL::CButton)GetDlgItem(IDC_RADIO_SAVESUBTITLE_CUSTOM_FOLDER);
 {
   m_secsubtitlestyle.Detach();
   m_subtitlestyle.Detach();
-  m_edtFontSize.Detach();
-  m_spnFontSize.Detach();
-  m_btnFontColor.Detach();
 }
 
 void OptionSubtitlePage::OnSubtitleStyleChange(UINT uNotifyCode, int nID, CWindow wndCtl)
 {
-  switch (m_cmbSetSubtitle.GetCurSel())
-  {
-  case 0:
-    {
-      // set the main subtitle style
-      m_mainstyle = m_subtitlestyle.GetCurSel();
-      break;
-    }
-
-  case 1:
-    {
-      // set the second subtitle style
-      m_secstyle = m_subtitlestyle.GetCurSel();
-      break;
-    }
-  }
+  m_mainstyle = m_subtitlestyle.GetCurSel();
 }
 
 // Let user select the save path
   btnCustomFolder.EnableWindow(TRUE);
 }
 
-// change subtitle's size
-void OptionSubtitlePage::OnSubtitleSizeChange(UINT uNotifyCode, int nID, CWindow wndCtl)
-{
-  AppSettings &s = AfxGetAppSettings();
-
-  switch (m_cmbSetSubtitle.GetCurSel())
-  {
-  case 0:
-    {
-      // main subtitle
-      // m_dOldMainSize must init before do the following job
-      if (m_dOldMainSize == -1)
-        return;
-
-      wchar_t szSize[32] = {0};
-      m_edtFontSize.GetWindowText(szSize, 31);
-      s.subdefstyle.fontSize = ::_wtol(szSize);
-
-      m_subtitlestyle.Invalidate();
-      break;
-    }
-
-  case 1:
-    {
-      // second subtitle
-      // m_dOldSecondSize must init before do the following job
-      if (m_dOldSecondSize == -1)
-        return;
-
-      wchar_t szSize[32] = {0};
-      m_edtFontSize.GetWindowText(szSize, 31);
-      s.subdefstyle2.fontSize = ::_wtol(szSize);
-
-      m_subtitlestyle.Invalidate();
-      break;
-    }
-  }
-}
-
-// change subtitle's color
-void OptionSubtitlePage::OnSubtitleColorChange(UINT uNotifyCode, int nID, CWindow wndCtl)
-{
-  AppSettings &s = AfxGetAppSettings();
-
-  switch (m_cmbSetSubtitle.GetCurSel())
-  {
-  case 0:
-    {
-      // main subtitle
-      WTL::CColorDialog dlgColor(s.subdefstyle.colors[0]);
-      if (dlgColor.DoModal() == IDOK)
-      {
-        s.subdefstyle.colors[0] = s.subdefstyle.colors[1] = dlgColor.GetColor();
-
-        m_subtitlestyle.Invalidate();
-        m_btnFontColor.Invalidate();
-      }
-      break;
-    }
-
-  case 1:
-    {
-      // second subtitle
-      WTL::CColorDialog dlgColor(s.subdefstyle2.colors[0]);
-      if (dlgColor.DoModal() == IDOK)
-      {
-        s.subdefstyle2.colors[0] = s.subdefstyle2.colors[1] = dlgColor.GetColor();
-
-        m_subtitlestyle.Invalidate();
-        m_btnFontColor.Invalidate();
-      }
-      break;
-    }
-  }
-}
-
-void OptionSubtitlePage::OnComboSetSubtitleChange(UINT uNotifyCode, int nID, CWindow wndCtl)
-{
-  AppSettings &s = AfxGetAppSettings();
-
-  switch (m_cmbSetSubtitle.GetCurSel())
-  {
-  case 0:
-    {
-      // main subtitle
-      m_spnFontSize.SetPos(s.subdefstyle.fontSize);
-      m_btnFontColor.Invalidate();
-      m_subtitlestyle.SetCurSel(m_mainstyle);
-      m_subtitlestyle.Invalidate();
-      break;
-    }
-
-  case 1:
-    {
-      // second subtitle
-      m_spnFontSize.SetPos(s.subdefstyle2.fontSize);
-      m_btnFontColor.Invalidate();
-      m_subtitlestyle.SetCurSel(m_secstyle);
-      m_subtitlestyle.Invalidate();
-      break;
-    }
-  }
-}
-
 void OptionSubtitlePage::DrawItem(LPDRAWITEMSTRUCT lpdis)
 {
-  AppSettings &s = AfxGetAppSettings();
-  switch (lpdis->CtlID)
-  {
-  case IDC_LIST:
-    {
-      if (m_cmbSetSubtitle.GetCurSel() == 0)
-      {
-        // main subtitle
-        SubtitleStyle::Paint(lpdis->hDC, &lpdis->rcItem, lpdis->itemID, -1,
-          (lpdis->itemState & ODS_SELECTED)?true:false);
-      } 
-      else
-      {
-        // second subtitle
-        SubtitleStyle::Paint(lpdis->hDC, &lpdis->rcItem, -1, lpdis->itemID,
-          (lpdis->itemState & ODS_SELECTED)?true:false);
-      }
-      break;
-    }
-
-  case IDC_BUTTON_SUBTITLE_FONTCOLOR:
-    {
-      WTL::CRect rcColorButton;
-      m_btnFontColor.GetClientRect(&rcColorButton);
-      WTL::CDC dc(lpdis->hDC);
-      if (m_cmbSetSubtitle.GetCurSel() == 0)
-      {
-        // main subtitle
-        dc.FillSolidRect(rcColorButton, s.subdefstyle.colors[0]);
-      } 
-      else
-      {
-        // second subtitle
-        dc.FillSolidRect(rcColorButton, s.subdefstyle2.colors[0]);
-      }
-
-      break;
-    }
-  }
+  SubtitleStyle::Paint(lpdis->hDC, &lpdis->rcItem, lpdis->itemID, -1,
+    (lpdis->itemState & ODS_SELECTED)?true:false);
 }
 
 void OptionSubtitlePage::MeasureItem(LPMEASUREITEMSTRUCT lpmis)
     lpmis->itemHeight = m_styleentry_height;
 }
 
+int OptionSubtitlePage::OnSetActive()
+{
+  return 0;
+}
+
 void OptionSubtitlePage::ApplySubtitleStyle()
 {
   DoDataExchange(TRUE);
   AppSettings& s = AfxGetAppSettings();
-
-  SubtitleStyle::STYLEPARAM* sp_main = 0;
-  SubtitleStyle::STYLEPARAM* sp_sec = 0;
-  SubtitleStyle::GetStyleParams(m_mainstyle, -1, &sp_main);
-  SubtitleStyle::GetStyleParams(-1, m_secstyle, &sp_sec);
-
-  if (sp_main)
+  // retrieve variables from screen
+  SubtitleStyle::STYLEPARAM* sp = NULL;
+  if (SubtitleStyle::GetStyleParams(m_subtitlestyle.GetCurSel(), -1, &sp))
   {
-    s.subdefstyle.colors[0] = s.subdefstyle.colors[1] = sp_main->fontcolor;
-    s.subdefstyle.colors[2] = sp_main->strokecolor;
-    s.subdefstyle.colors[3] = sp_main->shadowcolor;
-    s.subdefstyle.fontName = sp_main->fontname;
-    s.subdefstyle.fontSize = sp_main->fontsize;
-    s.subdefstyle.fontWeight = (sp_main->fontname == L"WenQuanYi Micro Hei" 
-                                || sp_main->fontname == L"\x6587\x6CC9\x9A7F\x5FAE\x737C\x9ED1"  // Chinese for "WenQuanYi Micro Hei"
+    s.subdefstyle.colors[0] = s.subdefstyle.colors[1] = sp->fontcolor;
+    s.subdefstyle.colors[2] = sp->strokecolor;
+    s.subdefstyle.colors[3] = sp->shadowcolor;
+    s.subdefstyle.fontName = sp->fontname;
+    s.subdefstyle.fontSize = sp->fontsize;
+    s.subdefstyle.fontWeight = (sp->fontname == L"WenQuanYi Micro Hei" 
+                                || sp->fontname == L"\x6587\x6CC9\x9A7F\x5FAE\x737C\x9ED1"  // Chinese for "WenQuanYi Micro Hei"
                                 )?FW_BOLD:FW_NORMAL; // Using BOLD if it is font WenQuanYi
     s.subdefstyle.scrAlignment = 2;
-    s.subdefstyle.shadowDepthX = s.subdefstyle.shadowDepthY = sp_main->shadowoffset;
-    s.subdefstyle.outlineWidthX = s.subdefstyle.outlineWidthY = sp_main->strokesize;
-  }
+    s.subdefstyle.shadowDepthX = s.subdefstyle.shadowDepthY = sp->shadowoffset;
+    s.subdefstyle.outlineWidthX = s.subdefstyle.outlineWidthY = sp->strokesize;
 
-  if (sp_sec)
-  {
-    s.subdefstyle2.colors[0] = s.subdefstyle2.colors[1] = sp_sec->fontcolor;
-    s.subdefstyle2.colors[2] = sp_sec->strokecolor;
-    s.subdefstyle2.colors[3] = sp_sec->shadowcolor;
-    s.subdefstyle2.fontName = sp_sec->fontname;
-    s.subdefstyle2.fontSize = sp_sec->fontsize;
-    s.subdefstyle2.fontWeight = (sp_sec->fontname == L"WenQuanYi Micro Hei" 
-                                || sp_sec->fontname == L"\x6587\x6CC9\x9A7F\x5FAE\x737C\x9ED1"  // Chinese for "WenQuanYi Micro Hei"
-                                )?FW_BOLD:FW_NORMAL; // Using BOLD if it is font WenQuanYi
-    s.subdefstyle2.scrAlignment = 2;
-    s.subdefstyle2.shadowDepthX = s.subdefstyle2.shadowDepthY = sp_sec->shadowoffset;
-    s.subdefstyle2.outlineWidthX = s.subdefstyle2.outlineWidthY = sp_sec->strokesize;
+    s.subdefstyle2 = s.subdefstyle;
   }
   s.subdefstyle2.scrAlignment = ( m_secsubtitlestyle.GetCurSel() == 1)?2:8;
 
   m_subtitlestyle.SetCount(SubtitleStyle::GetStyleCount(false));
   m_subtitlestyle.Invalidate();
 }
-
-BOOL OptionSubtitlePage::OnQueryCancel()
-{
-  // restore the font size and color
-  AppSettings& s = AfxGetAppSettings();
-  s.subdefstyle.fontSize = m_dOldMainSize;
-  s.subdefstyle.colors[0] = s.subdefstyle2.colors[1] = m_crOldMainColor;
-  s.subdefstyle2.fontSize = m_dOldSecondSize;
-  s.subdefstyle2.colors[0] = s.subdefstyle2.colors[1] = m_crOldSecondColor;
-
-  return FALSE;  // FALSE = allow cancel, TRUE = prevent cancel
-}

src/apps/mplayerc/UserInterface/Dialogs/OptionSubtitlePage_Win.h

 #define OPTIONSUBTITLEPAGE_WIN_H
 
 #include "../../resource.h"
-#include "SubtitleListBox.h"
 
 class OptionSubtitlePage:
   public WTL::CPropertyPageImpl<OptionSubtitlePage>,
   BEGIN_MSG_MAP(OptionSubtitlePage)
     MSG_WM_INITDIALOG(OnInitDialog)
     MSG_WM_DESTROY(OnDestroy)
-    COMMAND_HANDLER_EX(IDC_CMB_SET_SUBTITLE, CBN_SELCHANGE, OnComboSetSubtitleChange)
     COMMAND_HANDLER_EX(IDC_LIST, LBN_SELCHANGE, OnSubtitleStyleChange)
-    COMMAND_HANDLER_EX(IDC_EDIT_SUBTITLE_FONTSIZE, EN_CHANGE, OnSubtitleSizeChange)
-    COMMAND_HANDLER_EX(IDC_BUTTON_SUBTITLE_FONTCOLOR, BN_CLICKED, OnSubtitleColorChange)
     COMMAND_HANDLER_EX(IDC_BUTTON_SAVESUBTITLE_CUSTOM_FOLDER, BN_CLICKED, OnBrowserForFolder)
     COMMAND_HANDLER_EX(IDC_RADIO_SAVESUBTITLE_SAME_FOLDER, BN_CLICKED, OnSelectSameFolder)
     COMMAND_HANDLER_EX(IDC_RADIO_SAVESUBTITLE_CUSTOM_FOLDER, BN_CLICKED, OnSelectCustomFolder)
   void OnSelectSameFolder(UINT uNotifyCode, int nID, CWindow wndCtl);
   void OnSelectCustomFolder(UINT uNotifyCode, int nID, CWindow wndCtl);
 
-  void OnSubtitleSizeChange(UINT uNotifyCode, int nID, CWindow wndCtl);
-  void OnSubtitleColorChange(UINT uNotifyCode, int nID, CWindow wndCtl);
-
-  void OnComboSetSubtitleChange(UINT uNotifyCode, int nID, CWindow wndCtl);
-
   // owner-draw logic for subtitle styles
   void DrawItem(LPDRAWITEMSTRUCT lpdis);
   void MeasureItem(LPMEASUREITEMSTRUCT lpmis);
 
-  // apply/cancel handler
+  // activate/apply handler
+  int OnSetActive();
   int OnApply();
-  BOOL OnQueryCancel();
 
   void RefreshStyles();
 
 private:
-  WTL::CComboBox  m_cmbSetSubtitle;
   WTL::CComboBox  m_secsubtitlestyle;
-  WTL::CEdit      m_edtFontSize;
-  WTL::CButton    m_btnFontColor;
-  WTL::CUpDownCtrl m_spnFontSize;  // spin control
-  CSubtitleListBox  m_subtitlestyle;
+  WTL::CListBox   m_subtitlestyle;
 
   WTL::CString    m_sCustomPath;
 
-  double          m_dOldMainSize;
-  double          m_dOldSecondSize;
-  COLORREF        m_crOldMainColor;
-  COLORREF        m_crOldSecondColor;
-
   int m_mainstyle;
   int m_secstyle;
 

src/apps/mplayerc/UserInterface/Dialogs/SubtitleListBox.cc

-#include "stdafx.h"
-#include "SubtitleListBox.h"
-#include "..\Support\SubtitleStyle.h"
-
-CSubtitleListBox::CSubtitleListBox()
-{
-
-}
-
-CSubtitleListBox::~CSubtitleListBox()
-{
-
-}
-
-void CSubtitleListBox::OnMouseMove(UINT nFlags, CPoint point)
-{
-  AppSettings &s = AfxGetAppSettings();
-
-  // create tooltip
-  if (!::IsWindow(m_tip.m_hWnd))
-  {
-    DWORD dwTransparent = s.bUserAeroUI() ? WS_EX_TRANSPARENT : 0;
-    m_tip.CreateEx(WS_EX_NOACTIVATE | WS_EX_TOPMOST | dwTransparent, _T("SVPLayered"),
-                   _T("TIPS"), WS_POPUP, CRect(20,20,21,21), 0, 0);
-
-    if (s.bUserAeroUI())
-    {
-      m_tip.ModifyStyleEx(0, WS_EX_LAYERED);
-      m_tip.SetLayeredWindowAttributes(0, s.lAeroTransparent, LWA_ALPHA);
-    }
-  }
-
-  // show or hide tooltip
-  BOOL bOutside = FALSE;
-  int nItem = ItemFromPoint(point, bOutside);
-  static int nLastItem = -1;
-  if (!bOutside && nItem >= 0)
-  {
-    // clear stat
-    if (nLastItem != nItem)
-    {
-      m_tip.ClearStat();
-      nLastItem = nItem;
-    }
-
-    // show tooltip
-    SubtitleStyle::STYLEPARAM *sp = 0;
-    SubtitleStyle::GetStyleParams(nItem, -1, &sp);
-    if (sp)
-    {
-      if (!m_tip.IsWindowVisible())
-      {
-        m_tip.SetTips(sp->fontname, TRUE, 0, 500);
-      }
-    }
-  }
-  else
-  {
-    nLastItem = -1;
-  }
-}

src/apps/mplayerc/UserInterface/Dialogs/SubtitleListBox.h

-#pragma once
-
-#include "..\..\SeekBarTip.h"
-
-class CSubtitleListBox : public ATL::CWindowImpl<CSubtitleListBox, WTL::CListBox >
-{
-public:
-  CSubtitleListBox();
-  ~CSubtitleListBox();
-
-  BEGIN_MSG_MAP_EX(CSubtitleListBox)
-    MSG_WM_MOUSEMOVE(OnMouseMove)
-  END_MSG_MAP()
-
-private:
-  void OnMouseMove(UINT nFlags, CPoint point);
-
-private:
-  CSeekBarTip  m_tip;
-};

src/apps/mplayerc/UserInterface/Support/SubtitleStyle.cc

 #include "../../mplayerc.h"
 #include "../../resource.h"
 
-// defined for use with EnumFontProc
+// built-in definition for main subtitle styles
+static SubtitleStyle::STYLEPARAM g_styleparams[] = 
+{
+  // blue border
+  {SubtitleStyle::SimHei, L"SimHei", 20, 0x00FFFFFF, 1, 0x00996633, 1, 0x00333333, 90, 50},
+  {SubtitleStyle::SimSun, L"SimSun", 16, 0x00FFFFFF, 2, 0x00996633, 0, 0x00000000, 90, 50},
+  // white
+  {SubtitleStyle::SimHei, L"SimHei", 20, 0x00FFFFFF, 1, 0x00333333, 0, 0, 90, 50},
+  {SubtitleStyle::SimHei, L"SimHei", 20, 0x00FFFFFF, 2, 0x00333333, 1, 0x00333333, 90, 50},
+  // yellow
+  {SubtitleStyle::SimHei, L"SimHei", 20, 0x0000ecec, 2, 0x000f0f0f, 1, 0x00333333, 90, 50},
+  {SubtitleStyle::KaiTi, L"KaiTi", 16, 0x0086E1FF, 2, 0x0006374A, 1, 0x00333333, 90, 50},
+  {SubtitleStyle::KaiTi, L"KaiTi", 16, 0x00FFFFFF, 2, 0x00996633, 0, 0x00000000, 90, 50},
+
+};
+
+// built-in definition for secondary subtitle styles
+static SubtitleStyle::STYLEPARAM g_secstyleparams[] =
+{
+  {SubtitleStyle::None, L"", 0, 0, 0, 0, 0, 0, 10, 50},
+  {SubtitleStyle::None, L"", 0, 0, 0, 0, 0, 0, 91, 50}
+};
+
 static bool g_styleparams_inited = false;
 
-static std::vector<SubtitleStyle::STYLEPARAM > g_vtStyleParams;  // main subtitle
-static std::vector<SubtitleStyle::STYLEPARAM > g_vtSecStyleParams; // second subtitle
+const static wchar_t* fontlist_simhei[] = {
+  L"Microsoft YaHei",
+  L"WenQuanYi Micro Hei",
+  L"SimHei",
+  L"\x5FAE\x8F6F\x96C5\x9ED1",              // Chinese for "Microsoft YaHei"
+  L"\x6587\x6CC9\x9A7F\x5FAE\x737C\x9ED1",  // Chinese for "WenQuanYi Micro Hei"
+  L"\x9ED1\x4F53"                           // Chinese for "SimHei"
+  L"Segoe UI",
+  L"Arial"
+};
+
+const static wchar_t* fontlist_simsun[] = {
+  L"SimSun",
+  L"\x5B8B\x4F53",                          // Chinese for "SimSun"
+  L"Trebuchet MS"
+};
+
+const static wchar_t* fontlist_kaiti[] = {
+  L"KaiTi",
+  L"\x6977\x4F53",                          // Chinese for "KaiTi"
+  L"\x6977\x4F53_GB2312",                   // Chinese for "KaiTi_GB2312"
+  L"Georgia"
+};
+
+std::vector<std::wstring> g_sampletexts;  // text pieces to paint samples in SubtitleStyle::Paint
+
+// defined for use with EnumFontProc
+typedef struct _ENUMPARAMS {
+  int*    fontcount;
+  wchar_t realname[32];
+}ENUMPARAMS;
 
 int CALLBACK EnumFontProc(ENUMLOGFONTEX* lpelfe, NEWTEXTMETRICEX* lpntme, DWORD FontType, LPARAM lParam)
 {
-  // enum only Chinese font(font name is also Chinese)
-  //if ((unsigned char)(*(lpelfe->elfFullName)) > (unsigned char)('z'))
-  if (*(lpelfe->elfFullName) > L'~')
-  {
-    // dynamic create main and second subtitle styles
-    SubtitleStyle::STYLEPARAM styleparam;
-    ::wcscpy(styleparam.fontname, lpelfe->elfFullName);
-    styleparam.fontsize = 20;  // default is 20, will be changed
-    styleparam.fontcolor = 0x00FFFFFF; // will be changed
-    styleparam.strokesize = 1;
-    styleparam.strokecolor = 0x00333333;
-    styleparam.shadowoffset = 1;
-    styleparam.shadowcolor = 0x00333333;
-    styleparam.pos_vert = 90;
-    styleparam.pos_horz = 50;
-
-    g_vtStyleParams.push_back(styleparam);
-    g_vtSecStyleParams.push_back(styleparam);
-  }
-
-  return 1;
+  // EnumFontProc is called only when a font is enumerated, so we knew
+  // this font is available.
+  ENUMPARAMS* ep = (ENUMPARAMS*)lParam;
+  (*ep->fontcount)++;
+  wcscpy_s(ep->realname, 32, lpelfe->elfFullName);
+  return 0; // stop enum
 }
 
-void InitStyleParams()
+bool SubtitleStyle::GetStyleParams(int index_main, int index_sec, STYLEPARAM** param_refout)
 {
+  // initialize fonts first time this method is called
   if (!g_styleparams_inited)
   {
-    // init main and second subtitle style
+    // this process determines if our preferred fonts are available in system
+    // if so, we choose to copy the preferred font name to STYLEPARAM.fontname
+#ifdef _WINDOWS_
     WTL::CDC      dc;
     WTL::CLogFont lf;
     dc.CreateCompatibleDC();
 
-    lf.lfCharSet        = GB2312_CHARSET;  // only enum Chinese font
+    lf.lfCharSet        = DEFAULT_CHARSET;
     lf.lfPitchAndFamily = 0;
-    lf.lfFaceName[0] = '\0';
-    ::EnumFontFamiliesEx(dc, &lf, (FONTENUMPROC)EnumFontProc, 0, 0);
 
+    int stylecount = GetStyleCount();
+    for (int i = 0; i < stylecount; i++)
+    {
+      wchar_t** fontlist = NULL;
+      int fontlist_count = 0;
+      switch (g_styleparams[i]._fontname)
+      {
+      case SimHei:
+        fontlist = (wchar_t**)fontlist_simhei;
+        fontlist_count = sizeof(fontlist_simhei)/sizeof(fontlist_simhei[0]);
+        break;
+      case SimSun:
+        fontlist = (wchar_t**)fontlist_simsun;
+        fontlist_count = sizeof(fontlist_simsun)/sizeof(fontlist_simsun[0]);
+        break;
+      case KaiTi:
+        fontlist = (wchar_t**)fontlist_kaiti;
+        fontlist_count = sizeof(fontlist_kaiti)/sizeof(fontlist_kaiti[0]);
+        break;
+      }
+
+      if (!fontlist)
+        continue;
+
+      for (int j = 0; j < fontlist_count; j++)
+      {
+        int font_count = 0;
+        ENUMPARAMS ep = {&font_count, L""};
+        wcscpy_s(lf.lfFaceName, 32, fontlist[j]);
+        ::EnumFontFamiliesEx(dc, &lf, (FONTENUMPROC)EnumFontProc, (LPARAM)&ep, 0);
+        if (font_count > 0)
+        {
+          wcscpy_s(g_styleparams[i].fontname, 128, ep.realname);
+          break;
+        }
+      }
+    }
+#endif
     g_styleparams_inited = true;
   }
-}
 
-std::vector<std::wstring> g_sampletexts;  // text pieces to paint samples in SubtitleStyle::Paint
+  if (index_main < 0 || index_main >= sizeof(g_styleparams)/sizeof(g_styleparams[0]))
+    return false;
 
-bool SubtitleStyle::GetStyleParams(int index_main, int index_sec, STYLEPARAM** param_refout)
-{
-  // initialize fonts first time this method is called
-  InitStyleParams();
+  *param_refout = (STYLEPARAM*)&g_styleparams[index_main];
 
-  // get the main style
-  if (index_main >= 0 && index_main <= g_vtStyleParams.size() - 1)
+  // are we retrieving a secondary entry?
+  if (index_sec >= 0)
   {
-    // get the default style, but will change its size and color according to the appsettings
-    *param_refout = &(g_vtStyleParams[index_main]);
+    if (index_sec < 0 || index_sec >= sizeof(g_secstyleparams)/sizeof(g_secstyleparams[0]))
+      return false;
 
-    AppSettings &s = AfxGetAppSettings();
-    if (s.subdefstyle.fontSize > 0)
-      (*param_refout)->fontsize = s.subdefstyle.fontSize;
-    (*param_refout)->fontcolor = s.subdefstyle.colors[0];
-
+    *param_refout = (STYLEPARAM*)&g_secstyleparams[index_sec];
     return true;
   }
 
-  // are we retrieving a secondary entry?
-  if (index_sec >= 0 && index_sec <= g_vtSecStyleParams.size() - 1)
-  {
-    *param_refout = &g_vtSecStyleParams[index_sec];
-
-    AppSettings &s = AfxGetAppSettings();
-    if (s.subdefstyle2.fontSize > 0)
-      (*param_refout)->fontsize = s.subdefstyle2.fontSize;
-    (*param_refout)->fontcolor = s.subdefstyle2.colors[0];
-
-    return true;
-  }
-
-  return false;
+  return true;
 }
 
 int SubtitleStyle::GetStyleCount(bool secondary /* = false */)
 {
-  // initialize fonts first time this method is called
-  InitStyleParams();
-
   if (secondary)
-    return g_vtSecStyleParams.size();
-  return g_vtStyleParams.size();
+    return sizeof(g_secstyleparams)/sizeof(g_secstyleparams[0]);
+  return sizeof(g_styleparams)/sizeof(g_styleparams[0]);
 }
 
+int SubtitleStyle::DetectFontType(std::wstring fontname)
+{
+  for (int fonttype = SimHei; fonttype < KaiTi; fonttype++)
+  {
+    wchar_t** fontlist = NULL;
+    int fontlist_count = 0;
+    switch (fonttype)
+    {
+    case SimHei:
+      fontlist = (wchar_t**)fontlist_simhei;
+      fontlist_count = sizeof(fontlist_simhei)/sizeof(fontlist_simhei[0]);
+      break;
+    case SimSun:
+      fontlist = (wchar_t**)fontlist_simsun;
+      fontlist_count = sizeof(fontlist_simsun)/sizeof(fontlist_simsun[0]);
+      break;
+    case KaiTi:
+      fontlist = (wchar_t**)fontlist_kaiti;
+      fontlist_count = sizeof(fontlist_kaiti)/sizeof(fontlist_kaiti[0]);
+      break;
+    }
+
+    if (!fontlist)
+      continue;
+
+    for (int i = 0; i < fontlist_count; i++)
+    {
+      if (fontname == fontlist[i])
+        return fonttype;
+    }
+  }
+
+  return None;
+}
 void SubtitleStyle::Paint(HDC dc, RECT* rc, int index_main, int index_sec, bool selected /* = false */)
 {
-  STYLEPARAM* sp_main = 0;
-  STYLEPARAM* sp_sec = 0;
-  GetStyleParams(index_main, -1, &sp_main);
-  GetStyleParams(-1, index_sec, &sp_sec);
-  if ((!sp_main && !sp_sec) || (sp_main && sp_sec))
-    return;  // only allow paint main subtitle or second subtitle
+  STYLEPARAM* sp_main = NULL;
+  STYLEPARAM* sp_sec = NULL;
+  if (!GetStyleParams(index_main, -1, &sp_main))
+    return;
+  if (index_sec >= 0)
+    GetStyleParams(index_main, index_sec, &sp_sec);
 
   // there is a trick in this routine to achieve better appearance with GDI font rendering
   // we create a memory dc that is 4x as large as the target rectangle, paint the large
     ::GradientFill(mdc, vert, 2, &gRect, 1, GRADIENT_FILL_RECT_V);
   }
 
+  // create font
+  WTL::CLogFont lf;
+  lf.lfHeight   = sp_main->fontsize*5/2;
+  lf.lfQuality  = ANTIALIASED_QUALITY;
+  lf.lfCharSet  = DEFAULT_CHARSET;
+  wcscpy_s(lf.lfFaceName, 32, sp_main->fontname);
+
   // load sample text
   if (g_sampletexts.size() == 0)
   {
     text.LoadString(IDS_SUBTITLESTYLES);
     Strings::Split(text, L"|", g_sampletexts);
   }
-  std::wstring sSampleText = sp_main ? g_sampletexts[0] : g_sampletexts[1];
 
-  // some pre-paint jobs
-  STYLEPARAM *pPaintStyleParam = 0;
-  pPaintStyleParam = sp_main ? sp_main : sp_sec;
-
-  // create font
-  WTL::CLogFont lf;
-  lf.lfHeight   = pPaintStyleParam->fontsize * 5 / 2;
-  lf.lfQuality  = ANTIALIASED_QUALITY;
-  lf.lfCharSet  = DEFAULT_CHARSET;
-  wcscpy_s(lf.lfFaceName, 32, pPaintStyleParam->fontname);
+  // determine actual text to paint
+  std::wstring sample_text = g_sampletexts[0];
+  // paint secondary subtitle?
+  if (index_sec >= 0)
+  {
+    if (sp_sec->pos_vert <= 50)
+      sample_text = g_sampletexts[1];
+    else if (sp_sec->pos_vert > sp_main->pos_vert)
+    {
+      sample_text += L"\r\n";
+      sample_text += g_sampletexts[1];
+      // in secondary subtitle painting, we choose to make the font smaller a bit
+      lf.lfHeight = lf.lfHeight*2/3;
+    }
+    else
+    {
+      sample_text = g_sampletexts[1];
+      sample_text += L"\r\n";
+      sample_text += g_sampletexts[0];
+      // in secondary subtitle painting, we choose to make the font smaller a bit
+      lf.lfHeight = lf.lfHeight*2/3;
+    }
+  }
 
   WTL::CFont font;
   font.CreateFontIndirect(&lf);
   // determine vertical and horizontal center of the |rc|
   WTL::CRect rc_textraw(0, 0, bmp_width, bmp_height);
   mdc.SetBkMode(TRANSPARENT);
-  mdc.DrawText(sSampleText.c_str(), -1, &rc_textraw, DT_CALCRECT|DT_EDITCONTROL);
+  mdc.DrawText(sample_text.c_str(), -1, &rc_textraw, DT_CALCRECT|DT_EDITCONTROL);
   int offset_y = (bmp_height - rc_textraw.Height())/2;
   int offset_x = ::GetSystemMetrics(SM_CXSMICON);
   rc_textraw.OffsetRect(offset_x, offset_y);
   // now we have |rc_textraw| as the center position of sample text
 
   // paint logic 1. shadow
-  if (pPaintStyleParam->shadowoffset > 0)
+  if (sp_main->shadowoffset > 0)
   {
-    rc_textraw.OffsetRect(pPaintStyleParam->shadowoffset*3, pPaintStyleParam->shadowoffset*3);
+    rc_textraw.OffsetRect(sp_main->shadowoffset*3, sp_main->shadowoffset*3);
     // blend the shadow lighter a bit
-    int color = (0x00FFFFFF + pPaintStyleParam->shadowcolor)/2;
+    int color = (0x00FFFFFF + sp_main->shadowcolor)/2;
     mdc.SetTextColor(color);
     // we choose to apply 1 pixel stroke for the shadow to make it look nicer
     // * + = original text dot position
     for (int i = 0; i < sizeof(seq_x)/sizeof(seq_x[0]); i++)
     {
       rc_textraw.OffsetRect(seq_x[i], seq_y[i]);
-      mdc.DrawText(sSampleText.c_str(), -1, &rc_textraw, DT_EDITCONTROL);
+      mdc.DrawText(sample_text.c_str(), -1, &rc_textraw, DT_EDITCONTROL);
     }
     rc_textraw.OffsetRect(-1, 0);
-    rc_textraw.OffsetRect(-pPaintStyleParam->shadowoffset*3, -pPaintStyleParam->shadowoffset*3);
+    rc_textraw.OffsetRect(-sp_main->shadowoffset*3, -sp_main->shadowoffset*3);
   }
 
   // paint logic 2. stroke
-  if (pPaintStyleParam->strokesize > 0)
+  if (sp_main->strokesize > 0)
   {
-    mdc.SetTextColor(pPaintStyleParam->strokecolor);
+    mdc.SetTextColor(sp_main->strokecolor);
     // we only support two kinds of stroke, 1 pixel, and 2 pixels
     // for 1 pixel stroke, simulation strategy is:
     // * + = original text dot position
     // [S] [S] [S]          [1] [5] [2]
     // [S] [+] [S]    =>    [7] [+] [8]
     // [S] [S] [S]          [4] [6] [3]
-    if (pPaintStyleParam->strokesize == 1)
+    if (sp_main->strokesize == 1)
     {
       int seq_x[] = {-1, 2, 0, -2,  1/*5*/, 0, -1, 2};
       int seq_y[] = {-1, 0, 2,  0, -2/*5*/, 2, -1, 0};
       for (int i = 0; i < sizeof(seq_x)/sizeof(seq_x[0]); i++)
       {
         rc_textraw.OffsetRect(seq_x[i], seq_y[i]);
-        mdc.DrawText(sSampleText.c_str(), -1, &rc_textraw, DT_EDITCONTROL);
+        mdc.DrawText(sample_text.c_str(), -1, &rc_textraw, DT_EDITCONTROL);
       }
       rc_textraw.OffsetRect(-1, 0);
     }
       for (int i = 0; i < sizeof(seq_x)/sizeof(seq_x[0]); i++)
       {
         rc_textraw.OffsetRect(seq_x[i], seq_y[i]);
-        mdc.DrawText(sSampleText.c_str(), -1, &rc_textraw, DT_EDITCONTROL);
+        mdc.DrawText(sample_text.c_str(), -1, &rc_textraw, DT_EDITCONTROL);
       }
       rc_textraw.OffsetRect(2, 0);
     }
   }
 
   // paint logic 3. body
-  mdc.SetTextColor(pPaintStyleParam->fontcolor);
-  mdc.DrawText(sSampleText.c_str(), -1, &rc_textraw, DT_EDITCONTROL);
+  mdc.SetTextColor(sp_main->fontcolor);
+  mdc.DrawText(sample_text.c_str(), -1, &rc_textraw, DT_EDITCONTROL);
 
   // restore context
   mdc.SelectFont(old_font);
   POINT OldOrg = {0};
   ::SetBrushOrgEx(dc, 0, 0, &OldOrg);
   ::StretchBlt(dc, rc->left, rc->top, bmp_width/2, bmp_height/2, 
-               mdc, 0, 0, bmp_width, bmp_height, SRCCOPY);
+    mdc, 0, 0, bmp_width, bmp_height, SRCCOPY);
   mdc.SelectBitmap(old_bmp);
 }

src/apps/mplayerc/UserInterface/Support/SubtitleStyle.h

 class SubtitleStyle
 {
 public:
+  typedef enum _FontName {
+    None, SimHei, SimSun, KaiTi
+  }FontName;
+
   typedef struct _STYLEPARAM{
+    FontName  _fontname;
     wchar_t   fontname[128];
     int fontsize;
     int fontcolor;      // color is 0x00bbggrr
 
   static bool GetStyleParams(int index_main, int index_sec, STYLEPARAM** param_refout);
   static int GetStyleCount(bool secondary = false);
+  static int DetectFontType(std::wstring fontname);
 #ifdef _WINDOWS_
   static void Paint(HDC dc, RECT* rc, int index_main, int index_sec, bool selected = false);
 #endif
Add a comment to this file

src/apps/mplayerc/mplayerc.rc

Binary file modified.

src/apps/mplayerc/mplayerc_vs2005.vcproj

-<?xml version="1.0" encoding="windows-1250"?>
+<?xml version="1.0" encoding="windows-1250"?>
 <VisualStudioProject
 	ProjectType="Visual C++"
 	Version="9.00"
 					RelativePath=".\UserInterface\Dialogs\Snapshot_Win.h"
 					>
 				</File>
-				<File
-					RelativePath=".\UserInterface\Dialogs\SubtitleListBox.cc"
-					>
-				</File>
-				<File
-					RelativePath=".\UserInterface\Dialogs\SubtitleListBox.h"
-					>
-				</File>
 			</Filter>
 			<Filter
 				Name="Support"
Add a comment to this file

src/apps/mplayerc/resource.h

Binary file modified.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.