Difference between revisions of "Calc/Implementation/Svtools Numfmt"

From Apache OpenOffice Wiki
Jump to: navigation, search
Line 55: Line 55:
 
ScanType(): determine the type of this format code, which is listed as following (eScannedType)
 
ScanType(): determine the type of this format code, which is listed as following (eScannedType)
  
#define NUMBERFORMAT_DEFINED 0x001 /// Format defined by user
+
#define NUMBERFORMAT_DEFINED 0x001 /// Format defined by user
#define NUMBERFORMAT_DATE         0x002 /// Number as date
+
#define NUMBERFORMAT_DATE         0x002 /// Number as date
#define NUMBERFORMAT_TIME 0x004 /// Number as time
+
#define NUMBERFORMAT_TIME 0x004 /// Number as time
#define NUMBERFORMAT_CURRENCY 0x008 /// Number as currency
+
#define NUMBERFORMAT_CURRENCY 0x008 /// Number as currency
#define NUMBERFORMAT_NUMBER         0x010 /// Any "normal" number format
+
#define NUMBERFORMAT_NUMBER         0x010 /// Any "normal" number format
#define NUMBERFORMAT_SCIENTIFIC 0x020 /// Number as scientific
+
#define NUMBERFORMAT_SCIENTIFIC 0x020 /// Number as scientific
#define NUMBERFORMAT_FRACTION 0x040 /// Number as fraction
+
#define NUMBERFORMAT_FRACTION 0x040 /// Number as fraction
#define NUMBERFORMAT_PERCENT 0x080 /// Number as percent
+
#define NUMBERFORMAT_PERCENT 0x080 /// Number as percent
#define NUMBERFORMAT_TEXT 0x100 /// Text format
+
#define NUMBERFORMAT_TEXT 0x100 /// Text format
#define NUMBERFORMAT_DATETIME 0x006 /// Number as date and time
+
#define NUMBERFORMAT_DATETIME 0x006 /// Number as date and time
#define NUMBERFORMAT_LOGICAL 0x400 /// Number as boolean value
+
#define NUMBERFORMAT_LOGICAL 0x400 /// Number as boolean value
#define NUMBERFORMAT_UNDEFINED 0x800 /// Format undefined yet in analyzing
+
#define NUMBERFORMAT_UNDEFINED 0x800 /// Format undefined yet in analyzing
  
  

Revision as of 08:44, 12 June 2012

1. Architecture Introduction


Number format module is in the path of ".\lib\svtools\", which is a basic and public module, is used by other application, not only spreadsheet. There are 2 way to access number format module, uno api and call directly. This module has an UNO interface layer, provides unified APIs for other application and test module.

ICU is an important component for number format, following type format code need to call ICU APIs to get final result:

standard date and time, basic number, currency data.

1..jpg

The number format module located in src path of “…\lib\svtools\source\numbers”. There are 4 main classes in this module.

2.jpg

Class SvNumberformat represents a number format, which contain 4 sections, info to each section is stored in the array named "NumFor[]". Function GetOutputString() could return the result of specific input content formatted according to one format code. In constructed function of class SvNumberformat,

File:5.jpg

SvNumberFormatter is a container, which has a table named aFTable. If a new format code will be added, should call function PutEntry(), which will call constructed function of class SvNumberformat to get a number format object, and insert it to aFTable. The structure of aFTable is as following:

SV_COUNTRY_LANGUAGE_OFFSET(5000) | SV_COUNTRY_LANGUAGE_OFFSET |...... | ......


There are many language sections in this table, each language section offset is 5000.

  1. define SV_COUNTRY_LANGUAGE_OFFSET 5000 // Max count of formats per country/language

Each number format object will insert to specific section according to its language type. All system default local language and English(USA) format code will be added to this table when initializing.

Class ImpSvNumberformatScan could make lexical analysis to number format code and collect info(e.g. type, integer place, decimal place…), put each token to array sStrArray[], and put each token’s type to array nTypeArray[]. The key function of this class is ScanFormat.

xub_StrLen ImpSvNumberformatScan::ScanFormat( String& rString, String& rComment ) {

   xub_StrLen res = Symbol_Division(rString);	// lexical analysis
   if (!res)
       res = ScanType(rString);            // determine the type of this format code

if (!res) res = FinalScan( rString, rComment ); // collect info return res; // res = error position // res = 0 => Format ok }

Symbol_Division(): lexical analysis, generate 2 array, put each token’s string to array sStrArray[], and put each token’s type to array nTypeArray[].

ScanType(): determine the type of this format code, which is listed as following (eScannedType)

#define NUMBERFORMAT_DEFINED		 0x001	/// Format defined by user
#define NUMBERFORMAT_DATE	         0x002	/// Number as date
#define NUMBERFORMAT_TIME		 0x004	/// Number as time
#define NUMBERFORMAT_CURRENCY		 0x008	/// Number as currency
#define NUMBERFORMAT_NUMBER	         0x010	/// Any "normal" number format
#define NUMBERFORMAT_SCIENTIFIC		 0x020	/// Number as scientific
#define NUMBERFORMAT_FRACTION		 0x040	/// Number as fraction
#define NUMBERFORMAT_PERCENT		 0x080	/// Number as percent
#define NUMBERFORMAT_TEXT		 0x100	/// Text format
#define NUMBERFORMAT_DATETIME		 0x006	/// Number as date and time
#define NUMBERFORMAT_LOGICAL		 0x400	/// Number as boolean value
#define NUMBERFORMAT_UNDEFINED		 0x800	/// Format undefined yet in analyzing


FinalScan(): Get all other detail info for further calculate, e.g. integer bit, decimal place …

Class ImpSvNumberInputScan could determine whether a format code is legal or illegal, and provide date/time/string service. Class SvxNumberFormatTabPage and Class SvxNumberFormatShell are UI view and shell controller, there is member SvNumberFormatter pFormatter in the shell, to finish all number format logical operation. There 2 kinds of number format code will be inserted into table when initializing spreadsheet. One is built-in code, which located in path “…\lib\i18npool\source\localedata\data”, there are some xml files, each one related to one locale’s format code, e.g. zh_CN.xml, en_US.xml, de_DE.xml… . Two locale’s format code will be loaded automatically, en_US.xml and system default locale. If user change locale in language category list-box, new locale’s format code list will be loaded. Another is hardcode format code, in source code “…\lib\svtools\source\numbers\zforlist.cxx”. In the construct function of class SvNumberFormatter, some codes will be inserted into format table in hardcode way. Following is part source code snapshot.

4.jpg

Following sequence chart describes a whole flow to create a new number format and insert into format table.

3.jpg

Personal tools