Extract symbols from TrueType fonts

Source: Internet
Author: User

GIS friends are no stranger to map symbols. The various elements on the map become colorful because of the symbols. The symbol I want to talk about here refers to the dot symbol.

All those who have used the MO, AE, and other GIS platforms for secondary development know that when setting the point element symbol, there is a kind of symbol type which is TrueType symbol, there is a font attribute to specify the TrueType font, and there is a charactorindex attribute to specify the index number of the symbol. Through these two attributes, you can get a symbol. Correspondingly, in ArcGIS desktop software, there is a point-based symbol selection tool that can list all the symbols in the specified font, allowing users to select the appropriate symbol.

I used to read a lot of materials on how to implement this function, but I had little to learn about it. // most of the effort was to extract the font from the font file. When I had to check the ASCII code table a few days ago, I checked the previously seen symbols and found that the two were actually the same set of things, but they were just two different representations.

It can be understood that the characters in the ASCII Code (for example, 97 represents 'A', and 'A' is one character in ASCII) are represented by different fonts and different symbols are obtained, the principle is still unclear, but knowing this doesn't prevent us from making a perfect symbol selector.

There are two implementation methods, but the two methods are essentially the same. The first method is very simple to implement and well controlled. It is best to use it only when displaying symbols, but it cannot show a wide range of results. The second method is implemented through GDI +. by extracting the pattern of each symbol (that is, the outline of the symbol) as the path, you can implement many advanced presentation functions, you can also use the extracted path directly on the map and draw it together with the map element set.

// The first implementation method

Label [] labsymbols = new label [256];

For (INT I = 0; I <256; I ++)
{
Labsymbols [I]. font = # The font you specified #;
Labsymbols [I]. Text = new string (convert. tochar (I), 1 );
}

/// Method 2

Private void drawcharactorsoutlines (ref graphics g)
{
System. Drawing. drawing2d. graphicspath Ooutline = new system. Drawing. drawing2d. graphicspath ();
Int isymbolindex = 0;
G. textrenderinghint = textrenderinghint. antialiasgridfit;

For (INT I = 0; I <16; I ++)
{
For (Int J = 0; j <16; j ++)
{
String scharactor = new string (convert. tochar (isymbolindex ++), 1 );
Ooutline = new system. Drawing. drawing2d. graphicspath ();
Ooutline. addstring (scharactor, this. _ curfont. fontfamily, (INT) fontstyle. regular, this. _ fontsize-7, new point (J * This. _ fontsize, I * This. _ fontsize), stringformat. genericdefault );
G. fillpath (New solidbrush (color. Black), Ooutline );
Ooutline. Dispose ();
}
}
}

The above is the sample code written in C #. I have already written a complete symbol Selection control. If necessary, contact me.

(From: http://blog.163.com/lionyue@126/blog/static/10793071200801935736483)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.