{"id":825,"date":"2020-03-07T11:56:36","date_gmt":"2020-03-07T11:56:36","guid":{"rendered":"https:\/\/mobiletidings.com\/?p=825"},"modified":"2020-03-07T11:56:36","modified_gmt":"2020-03-07T11:56:36","slug":"text-formatting-with-ems","status":"publish","type":"post","link":"https:\/\/techsofar.com\/text-formatting-with-ems\/","title":{"rendered":"How to: Text Formatting With EMS"},"content":{"rendered":"

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:<\/p>\n

Text formatting in SMS<\/h3>\n

Remember that the UDH consists of Information Elements (IE) that each has the following structure<\/p>\n\n\n\n\n\n\n
Length<\/strong><\/td>\nValue<\/strong><\/td>\nDescription<\/strong><\/td>\n<\/tr>\n
1 octet<\/td>\nIEI<\/td>\nInformation Element Identifier. This determines what this IE is about.<\/td>\n<\/tr>\n
1 octet<\/td>\nIE length<\/td>\nThe length of the data belonging to this IE in octets.<\/td>\n<\/tr>\n
n octets<\/td>\nIE data<\/td>\nThe meaning of the content varies per IEI.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

 <\/p>\n

The text formatting is controlled by just one IE. Here is a description:<\/p>\n

 <\/p>\n\n\n\n\n\n\n\n\n\n
Length<\/strong><\/td>\nValue<\/strong><\/td>\nDescription<\/strong><\/td>\n<\/tr>\n
1 octet<\/td>\nIEI = 0x0A<\/td>\nIEI 0x0A is used to describe text formatting.<\/td>\n<\/tr>\n
1 octet<\/td>\nIE length = 0\u00d704<\/td>\nThe length of the data is 0\u00d703 or 0\u00d704 depending on whether the color octet(below) is used.<\/td>\n<\/tr>\n
1 octet<\/td>\nstart position<\/td>\nThe formatting described in the formatting octet (below) applies to start the character at the position indicated here.<\/td>\n<\/tr>\n
1 octet<\/td>\nlength<\/td>\nThe formatting applies to the number of characters indicated by this octet. The value 0 means that the formatting is the new default formatting.<\/td>\n<\/tr>\n
1 octet<\/td>\nformatting<\/td>\nThis octet indicates:<\/p>\n
    \n
  • How the text is to be aligned<\/li>\n
  • The size of the text<\/li>\n
  • Whether the text is bold, italic, underlined or strikethrough<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n
1 octet<\/td>\ncolor<\/td>\nThis octet is optional, its presence is through the IE length octet. This octet controls both background and foreground colors.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

Now the only thing that is left to describe the formatting and color octets is more detail:<\/p>\n

The formatting octet\u2019s 8 bits have the following meaning:<\/p>\n\n\n\n\n\n\n\n\n\n
Bits<\/strong><\/td>\nValue<\/strong><\/td>\nMeaning<\/strong><\/td>\n<\/tr>\n
1 and 0
\n(right most bits)<\/td>\n
0 = 0\u00d700
\n1 = 0\u00d701
\n2 = 0\u00d702
\n3 = 0\u00d703<\/td>\n
Left aligned
\nCenter aligned
\nRight aligned
\nDefault<\/td>\n<\/tr>\n
3 and 2<\/td>\n0 = 0\u00d700
\n1 = 0\u00d704
\n2 = 0\u00d708
\n3 = 0x0C<\/td>\n
Normal size
\nLarge text
\nSmall text
\nUnused<\/td>\n<\/tr>\n
4<\/td>\n0 = 0\u00d700
\n1 = 0\u00d710<\/td>\n
Bold off
\nBold on<\/td>\n<\/tr>\n
5<\/td>\n0 = 0\u00d700
\n1 = 0\u00d720<\/td>\n
Italic off
\nItalic on<\/td>\n<\/tr>\n
6<\/td>\n0 = 0\u00d700
\n1 = 0\u00d740<\/td>\n
Underline off
\nUnderline on<\/td>\n<\/tr>\n
7<\/td>\n0 = 0\u00d700
\n1= 0\u00d780<\/td>\n
Strikethrough off
\nStrikethrough on<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

 <\/p>\n

The values can be combined using the bitwise OR. For instance, a formatting octet with value 0\u00d739 would mean center-aligned, small text, bold and italic.<\/p>\n

The color octet consists of 2 4 bit values:<\/p>\n\n\n\n\n\n
Bits<\/strong><\/td>\nValue<\/strong><\/td>\nMeaning<\/strong><\/td>\n<\/tr>\n
3-0 (right most bits)<\/td>\n0 = 0\u00d700
\n1 = 0\u00d701
\n2 = 0\u00d702
\n3 = 0\u00d703
\n4 = 0\u00d704
\n5 = 0\u00d705
\n6 = 0\u00d706
\n7 = 0\u00d707
\n8 = 0\u00d708
\n9 = 0\u00d709
\n10 = 0x0A
\n11 = 0x0B
\n12 = 0x0C
\n13 = 0x0D
\n14 = 0x0E
\n15 = 0x0F<\/td>\n
Text black
\nText dark grey
\nText dark red
\nText dark yellow
\nText dark green
\nText dark cyan
\nText dark blue
\nText dark magenta
\nText grey
\nText white
\nText bright red
\nText bright yellow
\nText bright green
\nText bright cyan
\nText bright blue
\nText bright magenta<\/td>\n<\/tr>\n
7-4 (left most bits)<\/td>\n0 = 0\u00d700
\n1 = 0\u00d710
\n2 = 0\u00d720
\n3 = 0\u00d730
\n4 = 0\u00d740
\n5 = 0\u00d750
\n6 = 0\u00d760
\n7 = 0\u00d770
\n8 = 0\u00d780
\n9 = 0\u00d790
\n10 = 0xA0
\n11 = 0xB0
\n12 = 0xC0
\n13 = 0xD0
\n14 = 0xE0
\n15 = 0xF0<\/td>\n
Background black
\nBackground dark grey
\nBackground dark red
\nBackground dark yellow
\nBackground dark green
\nBackground dark cyan
\nBackground dark blue
\nbackground dark magenta
\nBackground grey
\nBackground white
\nBackground bright red
\nBackground bright yellow
\nBackground bright green
\nBackground bright cyan
\nBackground bright blue
\nbackground bright magenta<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

 <\/p>\n

Again you can use a bitwise OR to combine any text and background color.<\/p>\n

Now for a complete walkthrough of an example SMS with some text formatting. Here is the AT command to send the message:<\/p>\n

\n
AT+CMGS=100\n0041000B915121551532F40000631A0A031906200A032104100A032705040A032E05080A0438\n07002B8ACD29A85D9ECFC3E7F21C340EBB41E3B79B1E4EBB41697A989D1EB340E2379BCC02B1\nC3F27399059AB7C36C3628EC2683C66FF65B5E2683E8653C1D<\/pre>\n<\/div>\n

 <\/p>\n

Here is the detailed analysis to help you understand it:<\/p>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Size<\/strong><\/td>\nValue<\/strong><\/td>\nDescription<\/strong><\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d700<\/td>\nWe don\u2019t supply a SMSC number.<\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d741<\/td>\nPDU type and options. This is a plain SUBMIT-PDU and there is a UDH present.<\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d702<\/td>\nOur message reference.<\/td>\n<\/tr>\n
1 octet<\/td>\n0x0B<\/td>\nSize of destination telephone number (in digits)<\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d791<\/td>\nInternational numbering plan.<\/td>\n<\/tr>\n
6 octets<\/td>\n0x5121551532f4<\/td>\nThis represents the destination and it translates to 1 512 555 1234<\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d700<\/td>\nProtocol identifier.<\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d700<\/td>\nData Coding Scheme. DCS 0\u00d700 stands for a plain GSM-7 encoded text message.<\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d763<\/td>\nUser Data Length or payload size (in septets).<\/td>\n<\/tr>\n
1 octet<\/td>\n0x1A<\/td>\nUser Data Header Length or UDHL. Size of the UDH in octets.<\/td>\n<\/tr>\n
1 octet<\/td>\n0x0A<\/td>\nStart of a text formatting IEI.<\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d703<\/td>\nIE length is 3 octets<\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d719<\/td>\nStart formatting at the 25th character<\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d706<\/td>\nFormatting is for 6 characters<\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d720<\/td>\nUse italic text<\/td>\n<\/tr>\n
1 octet<\/td>\n0x0A<\/td>\nStart of a text formatting IEI.<\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d703<\/td>\nIE length is 3 octets<\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d721<\/td>\nStart formatting at the 33rd character<\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d704<\/td>\nFormatting is for 4 characters<\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d710<\/td>\nUse bold text<\/td>\n<\/tr>\n
1 octet<\/td>\n0x0A<\/td>\nStart of a text formatting IEI.<\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d703<\/td>\nIE length is 3 octets<\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d727<\/td>\nStart formatting at the 39th character<\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d705<\/td>\nFormatting is for 5 characters<\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d704<\/td>\nUse large text<\/td>\n<\/tr>\n
1 octet<\/td>\n0x0A<\/td>\nStart of a text formatting IEI.<\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d703<\/td>\nIE length is 3 octets<\/td>\n<\/tr>\n
1 octet<\/td>\n0x2E<\/td>\nStart formatting at the 46th character<\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d705<\/td>\nFormatting is for 5 characters<\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d708<\/td>\nUse small text<\/td>\n<\/tr>\n
1 octet<\/td>\n0x0A<\/td>\nStart of a text formatting IEI.<\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d704<\/td>\nIE length is 4 octets<\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d738<\/td>\nStart formatting at the 56th character<\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d707<\/td>\nFormatting is for 5 characters<\/td>\n<\/tr>\n
1 octet<\/td>\n0\u00d700<\/td>\nNo text formatting<\/td>\n<\/tr>\n
1 octet<\/td>\n0x2B<\/td>\nBackground dark red and text bright yellow<\/td>\n<\/tr>\n
54 octets<\/td>\n<\/td>\nThe remainder of the octets contain the text:\u201cEMS messages can contain italic, bold, large, small and colored text\u201d<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

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

EMS messages can contain\u00a0italic<\/em>,\u00a0bold<\/strong>,\u00a0large,\u00a0small\u00a0and\u00a0colored<\/span>\u00a0text<\/p>\n

A phone that doesn\u2019t support some or all of the EMS features used will simply skip over the IEs it doesn\u2019t know and produce the text without the indicated markup<\/p>\n","protected":false},"excerpt":{"rendered":"We have seen how you can use the User Data Header (UDH) in an SMS message to combine…\n","protected":false},"author":2,"featured_media":826,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/techsofar.com\/wp-content\/uploads\/2020\/03\/text-formatting.jpg","_links":{"self":[{"href":"https:\/\/techsofar.com\/wp-json\/wp\/v2\/posts\/825"}],"collection":[{"href":"https:\/\/techsofar.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techsofar.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techsofar.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/techsofar.com\/wp-json\/wp\/v2\/comments?post=825"}],"version-history":[{"count":0,"href":"https:\/\/techsofar.com\/wp-json\/wp\/v2\/posts\/825\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techsofar.com\/wp-json\/wp\/v2\/media\/826"}],"wp:attachment":[{"href":"https:\/\/techsofar.com\/wp-json\/wp\/v2\/media?parent=825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techsofar.com\/wp-json\/wp\/v2\/categories?post=825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techsofar.com\/wp-json\/wp\/v2\/tags?post=825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}