missing project/build files
[client-tools.git] / src / external / 3rd / application / UiFontBuilder / PreviewDialog.cpp
blobbc7aebe8d6cf9f954a76d68fd131fdf62969b975
1 // PreviewDialog.cpp : implementation file
2 //
4 #include "stdafx.h"
5 #include "PreviewDialog.h"
7 #include "UIFontBuilder.h"
8 #include "FontGlyphCode.h"
10 #ifdef _DEBUG
11 #define new DEBUG_NEW
12 #undef THIS_FILE
13 static char THIS_FILE[] = __FILE__;
14 #endif
16 /////////////////////////////////////////////////////////////////////////////
17 // CPreviewDialog dialog
19 using Unicode::unicode_char_t;
21 CPreviewDialog::CPreviewDialog(CWnd* pParent, const std::set<unicode_char_t> & idSet, CFont * font, int fontSizePixels)
22 : CDialog(CPreviewDialog::IDD, pParent)
24 //{{AFX_DATA_INIT(CPreviewDialog)
25 m_textInfoValue = _T("");
26 m_textInfoExcludedValue = _T("");
27 //}}AFX_DATA_INIT
29 m_idSet = idSet;
31 TCHAR buf [1024];
33 _snwprintf (buf, 1023, _T("%d characters in range.\n"), m_idSet.size ());
35 m_textInfoExcludedValue = _T ("0 characters excluded.\n");
36 m_textInfoValue = buf;
38 m_font = font;
39 m_fontSizePixels = fontSizePixels;
43 void CPreviewDialog::DoDataExchange(CDataExchange* pDX)
45 CDialog::DoDataExchange(pDX);
46 //{{AFX_DATA_MAP(CPreviewDialog)
47 DDX_Control(pDX, IDC_LIST_PREVIEW, m_listPreview);
48 DDX_Text(pDX, IDC_TEXT_INFO, m_textInfoValue);
49 DDX_Text(pDX, IDC_TEXT_INFO_EXCLUDED, m_textInfoExcludedValue);
50 //}}AFX_DATA_MAP
54 BEGIN_MESSAGE_MAP(CPreviewDialog, CDialog)
55 //{{AFX_MSG_MAP(CPreviewDialog)
56 ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_PREVIEW, OnItemchangedListPreview)
57 //}}AFX_MSG_MAP
58 END_MESSAGE_MAP()
60 /////////////////////////////////////////////////////////////////////////////
61 // CPreviewDialog message handlers
63 BOOL CPreviewDialog::OnInitDialog()
65 CDialog::OnInitDialog();
67 m_listPreview.SetFont (m_font);
69 m_listPreview.InsertColumn (0, _T("Code"), LVCFMT_LEFT, 100);
70 m_listPreview.InsertColumn (1, _T("Sample"), LVCFMT_LEFT, 100);
71 m_listPreview.InsertColumn (2, _T("A"), LVCFMT_LEFT, 100);
72 m_listPreview.InsertColumn (3, _T("B"), LVCFMT_LEFT, 100);
73 m_listPreview.InsertColumn (4, _T("C"), LVCFMT_LEFT, 100);
74 m_listPreview.InsertColumn (5, _T("Glyph"), LVCFMT_LEFT, 100);
76 TCHAR buf[2] = {0,0};
78 TCHAR numbuf[5] = {0,0,0,0,0};
80 CDC *myDC = GetDC();
81 HDC ScreenDC;
82 ScreenDC = (HDC)(*myDC);
84 HFONT TheFont;
85 LOGFONT lfont;
87 m_font->GetLogFont (&lfont);
89 TheFont = CreateFont(
90 m_fontSizePixels,
91 0,
92 0,
93 0,
94 lfont.lfWeight,
98 DEFAULT_CHARSET,
99 OUT_DEFAULT_PRECIS,
100 CLIP_DEFAULT_PRECIS,
101 PROOF_QUALITY,
102 DEFAULT_PITCH | FF_DONTCARE,
103 lfont.lfFaceName );
105 myDC->SelectObject(TheFont);
107 size_t i = 0;
109 for (std::set<unicode_char_t>::const_iterator iter = m_idSet.begin (); iter != m_idSet.end (); ++iter, ++i)
111 buf[0] = *iter;
113 _snwprintf (numbuf, 4, _T ("%04x"), *iter);
114 m_listPreview.InsertItem (i, numbuf);
115 m_listPreview.SetItemData (i, *iter);
117 m_listPreview.SetItemText (i, 1, buf);
119 ABCFLOAT abcf;
120 USHORT const index = GetTTUnicodeGlyphIndex(ScreenDC, *iter);
121 if(index == 0)
122 abcf.abcfA = abcf.abcfB = abcf.abcfC = -1;
123 else
125 if(!myDC->GetCharABCWidths(*iter, *iter, &abcf))
127 int err = GetLastError();
128 TCHAR t[512];
129 _snwprintf(t, 512, _T("%x\n"), err);
130 OutputDebugString(t);
134 _snwprintf (numbuf, 4, _T ("%4.1f"), abcf.abcfA);
135 m_listPreview.SetItemText(i, 2, numbuf);
136 _snwprintf (numbuf, 4, _T ("%4.1f"), abcf.abcfB);
137 m_listPreview.SetItemText(i, 3, numbuf);
138 _snwprintf (numbuf, 4, _T ("%4.1f"), abcf.abcfC);
139 m_listPreview.SetItemText(i, 4, numbuf);
140 _snwprintf (numbuf, 4, _T ("%4d"), index);
141 m_listPreview.SetItemText(i, 5, numbuf);
144 // TODO: Add extra initialization here
146 return TRUE; // return TRUE unless you set the focus to a control
147 // EXCEPTION: OCX Property Pages should return FALSE
150 //-----------------------------------------------------------------
152 const CPreviewDialog::ExclusionVector_t & CPreviewDialog::getExclusionVector () const
154 return m_exclusionVector;
158 void CPreviewDialog::OnOK()
160 // TODO: Add extra validation here
161 POSITION pos = m_listPreview.GetFirstSelectedItemPosition ();
163 while (pos)
165 int nItem = m_listPreview.GetNextSelectedItem (pos);
166 m_exclusionVector.push_back (static_cast<Unicode::unicode_char_t>(m_listPreview.GetItemData (nItem)));
169 CDialog::OnOK();
172 void CPreviewDialog::OnItemchangedListPreview(NMHDR*, LRESULT* pResult)
175 //NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
177 // TODO: this gets called every type the selection changes, so we should really
178 // try to do the text field update less often!
180 size_t selcount = m_listPreview.GetSelectedCount ();
182 TCHAR buf[128];
184 _snwprintf (buf, 127, _T("%d characters excluded."), selcount);
186 m_textInfoExcludedValue = buf;
188 UpdateData (false);
190 *pResult = 0;