Offset algorithm of the font model in the font library

Source: Internet
Author: User
Tags modulus

This article is written to the author of this article:

Http://blog.csdn.net/king_bingge/article/details/8779494

 

A csdn blog can contain up to 1000 characters in reply, and cannot contain these words. You have to pay attention to each other when sending private messages, and you cannot send messages when leaving messages, he set up another verification question for the qq of the gabo. I can't guess his name, so I 'd like to post it here.

I don't know if the blogger's formula is understood. I pretend that he still doesn't understand it. Come and help him solve it. The following text only represents personal opinions.
The blogger once turned an article called "Information Processing exchange with Chinese character encoding Character Set GB2312-80" I believe this article he must have understood.

The Chinese character input method is called the location code input method, which is based on the principle of differentiation in the article he reproduced.

When I was a child, I once sorted out the location codes of Common Chinese characters. I remember that the first Chinese character was "ah" and the location code was 1601. At that time, I was particularly impressed by the fact that the location code was 94 from 01 to 94, with 94 characters in total starting from 01 to 94. In my impression, the first three areas are punctuation marks, and there are some special symbol areas in the middle, such as ① ② ③. The Chinese characters start from the 16-zone. We will leave it alone.

First, let's talk about the relationship between the location code and the Chinese character internal code.

The inner code of Chinese characters is divided into two bytes. The high byte corresponds to the area of the location code, and the low byte corresponds to the bit, but note that it is not directly equal, the two bytes are the partition code and bit code plus 160. I don't know why I want to add 160 characters. It may be to distinguish the 127 characters of ASCII, but I think it can be distinguished by + 128, but it still adds 160. This is exactly why there are only 94 partition codes. 160 + 94 = 254, the maximum size of a single byte is 255, but 255 is a special value (all 1 in binary and all 0 are special values) cannot be used.

In this case, taking "ah" as an example, its internal code algorithm, high byte = 160 + code 16 = 176, low byte = 160 + bit code 1 = 161, the hexadecimal value is 0xb0a1, And the decimal value is 176*256 + 161 = 45217. Verify that you can open notepad and hold down the Alt key, use the number key area (note that only the keypad on the right of the big keyboard is the numlock number key area, which may not work on the notebook). If you enter 45217, the word "ah" appears.

In another example, my name is Han, and the "Han" code is 2611. Its inner code, high byte = 160 + code 16 = 186, low byte = 160 + Code 11 = 171, the hexadecimal value is 0 xbaab, And the decimal value is (26 + 160) * 256 + (11 + 160) = 47787. Open notepad, ALT + 47787, the word "Korean" can appear on the notepad.

Okay. Let's talk about the model. Since it is a 16x16 font, we can think of that each Chinese Character occupies 16 rows * 16 columns = 16 rows * 8 columns * 2, that is, 16*2 bytes.

Offset calculation is simple. The offset of the nth text is offset = (n-1) * 16*2.

Let us assume that the font starts from the 1st-bit in Area 1st and 94 characters in each area, then the K-bit text in Area J is equivalent to the (J-1) * 94 + k text, applied to the formula above, n = (J-1) * 94 + k, its modulus offset is offset = (J-1) * 94 + k-1) * 16*2.

But as mentioned above, the first Chinese character "ah" is in Zone 16, rather than Zone 1. 1 ~ There are no Chinese Characters in zone 15, so some font files have removed the fonts in the first 15 areas to save space (this is really not the case, in this way, the full-angle punctuation marks are removed, and the full-angle punctuation marks cannot be displayed.) in this way, the K-bit text in section J (J ≥16) is displayed, it is equivalent to the first (j-16) * 94 + k text in the font, its modulus offset is offset = (j-16) * 94 + k-1) * 16*2.

In combination with the relationship between the internal code and the location code, the high-byte Hi low-byte Chinese characters, the corresponding internal code is:

J = Hi-160

K = low-160

The offset is

Area 1 start Font: offset = (J-1) * 94 + k-1) * 16*2 = (hi-160-1) * 94 + low-160-1) * 16*2 = (hi-0xa1) * 94 + low-0xa1) * 16*2

Area 16 start Font: offset = (j-16) * 94 + k-1) * 16*2 = (hi-160-16) * 94 + low-160-1) * 16*2 = (hi-0xb0) * 94 + low-0xa1) * 16*2

For example, "Ah"

In the font library starting from Area 1, the offset is (176-0xa1) * 94 + 161-0xa1) * 16*2 = 45120 = 0xb040

In the font library starting from Area 16, the offset is (176-0xb0) * 94 + 161-0xa1) * 16*2 = 0

"Han"

In the font library starting from Area 1, the offset is (186-0xa1) * 94 + 171-0xa1) * 16*2 = 75520 = 0x012700

In the font library starting from Area 16, the offset is (186-0xb0) * 94 + 171-0xa1) * 16*2 = 30400 = 0x76c0

 

Let's take a look at the author's two sentences of code:

Pos = (High8bit-0xb0) * 94 + Low8bit-0xa1) * 2*16;

This sentence is obviously a character library starting with Area 16;

// Pos = (High8bit-0xa0) * 94 + Low8bit-0xa0) * 2*16;

This sentence looks like a font starting from Area 1, but its high position should be 0 x A1 instead of 0x0; otherwise, the corresponding word cannot be obtained, the words in the same region are obtained.

 

That's all. My QQ account is 34368900. I hope I can communicate more. I just got started with stm32. I have many questions that need to be taught by the blogger.

Related Article

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.