How to: Text Formatting With EMS

text formatting with EMS

We have seen how you can use the User Data Header (UDH) in an SMS message to combine several SMS messages into one bigger one. Here is another application of the UDH:

Text formatting in SMS

Remember that the UDH consists of Information Elements (IE) that each has the following structure

Length Value Description
1 octet IEI Information Element Identifier. This determines what this IE is about.
1 octet IE length The length of the data belonging to this IE in octets.
n octets IE data The meaning of the content varies per IEI.

 

The text formatting is controlled by just one IE. Here is a description:

 

Length Value Description
1 octet IEI = 0x0A IEI 0x0A is used to describe text formatting.
1 octet IE length = 0×04 The length of the data is 0×03 or 0×04 depending on whether the color octet(below) is used.
1 octet start position The formatting described in the formatting octet (below) applies to start the character at the position indicated here.
1 octet length The formatting applies to the number of characters indicated by this octet. The value 0 means that the formatting is the new default formatting.
1 octet formatting This octet indicates:

  • How the text is to be aligned
  • The size of the text
  • Whether the text is bold, italic, underlined or strikethrough
1 octet color This octet is optional, its presence is through the IE length octet. This octet controls both background and foreground colors.

Now the only thing that is left to describe the formatting and color octets is more detail:

The formatting octet’s 8 bits have the following meaning:

Bits Value Meaning
1 and 0
(right most bits)
0 = 0×00
1 = 0×01
2 = 0×02
3 = 0×03
Left aligned
Center aligned
Right aligned
Default
3 and 2 0 = 0×00
1 = 0×04
2 = 0×08
3 = 0x0C
Normal size
Large text
Small text
Unused
4 0 = 0×00
1 = 0×10
Bold off
Bold on
5 0 = 0×00
1 = 0×20
Italic off
Italic on
6 0 = 0×00
1 = 0×40
Underline off
Underline on
7 0 = 0×00
1= 0×80
Strikethrough off
Strikethrough on

 

The values can be combined using the bitwise OR. For instance, a formatting octet with value 0×39 would mean center-aligned, small text, bold and italic.

The color octet consists of 2 4 bit values:

Bits Value Meaning
3-0 (right most bits) 0 = 0×00
1 = 0×01
2 = 0×02
3 = 0×03
4 = 0×04
5 = 0×05
6 = 0×06
7 = 0×07
8 = 0×08
9 = 0×09
10 = 0x0A
11 = 0x0B
12 = 0x0C
13 = 0x0D
14 = 0x0E
15 = 0x0F
Text black
Text dark grey
Text dark red
Text dark yellow
Text dark green
Text dark cyan
Text dark blue
Text dark magenta
Text grey
Text white
Text bright red
Text bright yellow
Text bright green
Text bright cyan
Text bright blue
Text bright magenta
7-4 (left most bits) 0 = 0×00
1 = 0×10
2 = 0×20
3 = 0×30
4 = 0×40
5 = 0×50
6 = 0×60
7 = 0×70
8 = 0×80
9 = 0×90
10 = 0xA0
11 = 0xB0
12 = 0xC0
13 = 0xD0
14 = 0xE0
15 = 0xF0
Background black
Background dark grey
Background dark red
Background dark yellow
Background dark green
Background dark cyan
Background dark blue
background dark magenta
Background grey
Background white
Background bright red
Background bright yellow
Background bright green
Background bright cyan
Background bright blue
background bright magenta

 

Again you can use a bitwise OR to combine any text and background color.

Now for a complete walkthrough of an example SMS with some text formatting. Here is the AT command to send the message:

AT+CMGS=100
0041000B915121551532F40000631A0A031906200A032104100A032705040A032E05080A0438
07002B8ACD29A85D9ECFC3E7F21C340EBB41E3B79B1E4EBB41697A989D1EB340E2379BCC02B1
C3F27399059AB7C36C3628EC2683C66FF65B5E2683E8653C1D

 

Here is the detailed analysis to help you understand it:

Size Value Description
1 octet 0×00 We don’t supply a SMSC number.
1 octet 0×41 PDU type and options. This is a plain SUBMIT-PDU and there is a UDH present.
1 octet 0×02 Our message reference.
1 octet 0x0B Size of destination telephone number (in digits)
1 octet 0×91 International numbering plan.
6 octets 0x5121551532f4 This represents the destination and it translates to 1 512 555 1234
1 octet 0×00 Protocol identifier.
1 octet 0×00 Data Coding Scheme. DCS 0×00 stands for a plain GSM-7 encoded text message.
1 octet 0×63 User Data Length or payload size (in septets).
1 octet 0x1A User Data Header Length or UDHL. Size of the UDH in octets.
1 octet 0x0A Start of a text formatting IEI.
1 octet 0×03 IE length is 3 octets
1 octet 0×19 Start formatting at the 25th character
1 octet 0×06 Formatting is for 6 characters
1 octet 0×20 Use italic text
1 octet 0x0A Start of a text formatting IEI.
1 octet 0×03 IE length is 3 octets
1 octet 0×21 Start formatting at the 33rd character
1 octet 0×04 Formatting is for 4 characters
1 octet 0×10 Use bold text
1 octet 0x0A Start of a text formatting IEI.
1 octet 0×03 IE length is 3 octets
1 octet 0×27 Start formatting at the 39th character
1 octet 0×05 Formatting is for 5 characters
1 octet 0×04 Use large text
1 octet 0x0A Start of a text formatting IEI.
1 octet 0×03 IE length is 3 octets
1 octet 0x2E Start formatting at the 46th character
1 octet 0×05 Formatting is for 5 characters
1 octet 0×08 Use small text
1 octet 0x0A Start of a text formatting IEI.
1 octet 0×04 IE length is 4 octets
1 octet 0×38 Start formatting at the 56th character
1 octet 0×07 Formatting is for 5 characters
1 octet 0×00 No text formatting
1 octet 0x2B Background dark red and text bright yellow
54 octets The remainder of the octets contain the text:“EMS messages can contain italic, bold, large, small and colored text”

The text produced by the messages (when received on a phone that supports all EMS features used) would look like this:

EMS messages can contain italicbold, large, small and colored text

A phone that doesn’t support some or all of the EMS features used will simply skip over the IEs it doesn’t know and produce the text without the indicated markup

Total
0
Shares
Related Posts
>