Click here to Skip to main content
12,950,618 members (58,900 online)
Click here to Skip to main content
Add your own
alternative version

Stats

96.2K views
1.8K downloads
30 bookmarked
Posted 3 Jun 2003

XCharMap - A dialog to display a character map

, 3 Jun 2003 CPOL
Rate this:
Please Sign up or sign in to vote.
XCharMap demonstrates the use of CXCharMap, a class that displays a character map similar to the Windows Character Map utility.
<!-- Add the rest of your HTML here -->

Introduction

In some apps, the user may want to select how to display certain characters. For example, in text editors, it is common to have option to display whitespace (space and tab). When I had this requirement recently, I tried to use Microsoft's Character Map to allow user to select the display characters. Unfortunately, unless you are willing to use clipboard, there is no way to seamlessly integrate Character Map into your app. So here is XCharMap, my implementation of Character Map as a convenient dialog that you can customize to meet your needs.

The XCharMap Dialog

        XCharMap screenshot

The XCharMap dialog displays 256 characters in selected font. In dialog caption, the character code under the cursor is displayed in hex, octal, and decimal. Below character grid are optional UI elements, which you can remove from the display by calling XCharMap APIs. When user left-clicks (or right-clicks) a character, it is displayed in left-click/right-click box. The last character that was left-clicked may be copied to Characters to copy edit box by clicking on Select. Clicking on Copy will then transfer contents of edit box to clipboard.

To remove Characters to copy UI elements, you can call

  • CXCharMap::EnableCharsToCopy(FALSE).

To remove left-click/right-click UI elements, you can call

  • CXCharMap::EnableClicks(FALSE).

When both sets of UI elements are removed, the XCharMap dialog will be shrunk to fit character grid. To remove character code display in dialog caption, you can call

  • CXCharMap::EnableCharacterCode(FALSE).

Here is code from XCharMapTestDlg.cpp that shows how to call CXCharMap and disable all optional UI elements:

void CXCharMapTestDlg::OnTest()
{
    CXCharMap dlg;

    dlg.EnableCharsToCopy(FALSE);
    dlg.EnableClicks(FALSE);
    dlg.EnableCharacterCode(FALSE);

    if (dlg.DoModal() == IDOK)
    {
        // process return here
        TRACE(_T("m_nLeftClickRow=%d\n"), dlg.m_nLeftClickRow);
        TRACE(_T("m_nLeftClickCol=%d\n"), dlg.m_nLeftClickCol);
        TRACE(_T("m_nRightClickRow=%d\n"), dlg.m_nRightClickRow);
        TRACE(_T("m_nRightClickCol=%d\n"), dlg.m_nRightClickCol);
    }
} 

How To Use

To integrate IsOpenType() into your app, you first need to add following files to your project:

  • Clipboard.cpp
  • Clipboard.h
  • GetFontFile.cpp
  • GetFontFile.h
  • IsOpenType.cpp
  • IsOpenType.h
  • XCharGrid.cpp
  • XCharGrid.h
  • XCharMap.cpp
  • XCharMap.h
  • XFontPreviewCombo.cpp
  • XFontPreviewCombo.h

Next, include the header file XCharMap.h in appropriate project files. Now you are ready to start using CXCharMap.

Limitations

Currently the XCharMap implementation does not support Unicode.

Acknowledgments and references

Revision History

Version 1.0 - 2003 June 4

  • Initial public release.

Usage

This software is released into the public domain. You are free to use it in any way you like. If you modify it or extend it, please to consider posting new code here for everyone to share. This software is provided "as is" with no expressed or implied warranty. I accept no liability for any damage or loss of business that this software may cause.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Hans Dietrich
Software Developer (Senior) Hans Dietrich Software
United States United States
I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.

Recently, I have moved to Los Angeles where I am doing consulting and development work.

For consulting and custom software development, please see www.hdsoft.org.






You may also be interested in...

Comments and Discussions

 
GeneralUnicode version Pin
E Olivier17-Aug-04 23:46
memberE Olivier17-Aug-04 23:46 
GeneralDetecting OpenType Fonts Pin
gjr29-Apr-04 21:38
membergjr29-Apr-04 21:38 
GeneralRe: Detecting OpenType Fonts Pin
Hans Dietrich30-Apr-04 0:34
memberHans Dietrich30-Apr-04 0:34 
GeneralRe: Detecting OpenType Fonts Pin
gjr30-Apr-04 18:27
membergjr30-Apr-04 18:27 
GeneralRe: Detecting OpenType Fonts Pin
gjr1-May-04 21:09
membergjr1-May-04 21:09 
Hans
I think the problem is just that the code is not checking for the CFF version of OTF font files. (For those interested in font arcana the OpenType format details are available at MS site 'Organization of an OpenType Font' at http://www.microsoft.com/typography/otspec/otff.htm#otttables).

If we are pretty sure that the file is SOME form of font file I think you can test for OpenType under Windows (not MAC) with code along the lines of:
// Quick & dirty combination
// pFileBuf points to start of file data
const LONG lVersion = *(LONG *)pFileBuf; // the DWORD version
_CASSERT(!(sizeof(TT_OFFSET_TABLE) % 4)); // Compile time ASSERT - Must be 4 byte alignment
const LONG lDSIGTag = *(LONG *)(pFileBuf + sizeof(TT_OFFSET_TABLE)); // the DWORD Tag
const bool bFoundTTF =
(0x00000100 == lVersion && // Big Endian 0x00010000 = v1.0 - OpenType font contains TrueType outlines
0x47495344 == lDSIGTag); // Big Endian 0x44534947 = 'DSIG - Tag

bool bFoundOTF;
if (bFoundTTF)
{ // Is TrueType OTF
bFoundOTF = true;
} // Is TrueType OTF
else
{ // NOT TrueType OTF - try CFF
const bool bFoundCFF = (0x4F54544F == lVersion); // Big Endian 0x4F54544F = 'OTTO' - OpenType font contains CFF data
bFoundOTF = bFoundCFF;
} // NOT TrueType OTF - try CFF

I can't think of any Windows OpenType file that will not be correctly identified by this test and I have used a more elaborate version of it in another context without finding a non conforming font file.

Rgds
gjr

gjr
Generalunicode... Pin
Manikandan28-Mar-04 20:31
memberManikandan28-Mar-04 20:31 
AnswerRe: unicode... Pin
Hans Dietrich2-Apr-11 4:16
mentorHans Dietrich2-Apr-11 4:16 
GeneralDoes not display chars of Windings font Pin
Pnirff13-Jun-03 0:02
memberPnirff13-Jun-03 0:02 
GeneralRe: Does not display chars of Windings font Pin
Hans Dietrich13-Jun-03 1:57
memberHans Dietrich13-Jun-03 1:57 
GeneralRe: Does not display chars of Windings font Pin
Pnirff13-Jun-03 3:47
memberPnirff13-Jun-03 3:47 
GeneralUseless Pin
John R. Shaw5-Jun-03 15:23
memberJohn R. Shaw5-Jun-03 15:23 
GeneralRe: Useless Pin
Stephan Poirier9-Jun-03 20:11
memberStephan Poirier9-Jun-03 20:11 
GeneralRe: Useless Pin
John R. Shaw10-Jun-03 2:16
memberJohn R. Shaw10-Jun-03 2:16 
GeneralRe: Useless Pin
Stephan Poirier10-Jun-03 13:37
memberStephan Poirier10-Jun-03 13:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170525.1 | Last Updated 4 Jun 2003
Article Copyright 2003 by Hans Dietrich
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid