印刷機能実現の説明(日本側に開発したライブラリの使用)

日本側に製造したライブラリの使用方法を説明します。(この内容は教育資料へ移動する良いです)

主要なクラス:

  • 【PrintForm】
  • 【PrintFormDataObject】
  • 【PFDOMNode】
  • 【FormTypeCommon】

■ PrintFormは印刷機能提供するクラスで、以外のは補助的なクラスである

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
 * "PrintForm" is a Class for printing.
 * This Class analyzes the XML data which had the format defined
 * and returns an analysis result(PrintFormDataObject).
 * You set data to print to "PrintFormDataObject" instance, or 
 * make "PrintFormDataObject" instance equivalent to it and set data.
 * Finally, call the "printOnceDataXMLData" method.
 * 
 * 
 * HOW TO USE "Print Form"
 *
 * 1. create PrintFormSetting instance. (WHEN XML DATA IS DIRECT READ)
 *
 *  PrintFormSettings pfSettings = new PrintFormSettings( null, null, null, null );
 *
 *  final String FORMDATA = 
 *   "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
 *  + "<print_form>\n"
 *  +  "<tag_name type=\"character\" offset=\"0\" />\n"
 *  +  "<form.linefeed />\n"
 *  + "</print_form>\n";
 *
 *  pfSettings.setmXmlData80mm(FORMDATA);
 *
 * 1. create PrintFormSetting instance. (WHEN XML DATA READ FROM DATABASE)
 *
 *   PrintFormSettings pfSettings = new PrintFormSettings(
 *       context, // context
 *       FormMasterSettings.RCT_GENERAL_58,  // 58mm form name
 *       FormMasterSettings.RCT_GENERAL_80,  // 80mm form name
 *       "00"); // print type "00": receipt
 *
 * 2. parse xml data
 *
 *  PrintFormDataObject pfdObj = PrintForm.parseXmlForm(pfSettings);
 *  
 * 3. set data
 *
 *  for(int idx = 0; idx < pfdObj.getmPfdomList80mm().size; idx++ ){
 *   if(pfdObj.getmPfdomList80mm().get(idx).getTagName().equals("tag_name")){
 *      pfdObj.getmPfdomList80mm().get(idx).getObjData().put("HELLO!!!!!");
 *   }
 *  }
 *
 * 4. print
 *
 *  PrintForm.printOnceDataXMLData(pfdObj, pfSettings);
 *
 */
 ```

 PrintFormDataObjectは58mm用紙インスタンスと88mmインスタンス用紙を含むクラスである
      具体的な情報はパッケージjp.co.casio.caios.framework.printを参考してください

## XMLに使用するラベル属性に関するクラスの説明

 FormTypeCommonはフォームの各Attributeを提供されている

``` xml
常用なAttributeを説明します
フォントのサイズdouble_size (booleanの値を指定します)
並べるalign 四つの値がある "LEFT_POS""RIGHT_POS""CENTER_POS""DIGIT_MARK_POS"
オフセットoffset
他の内容はクラスFormTypeCommonを参照してください

■ PFDOMNodeは印刷の型を提供されている

1
2
3
4
5
6
型によって、typeの値は以下の通り
文字列:"character"
日付:"date" 渡す内容はデータのlong値としてください
バーコード:"barcode"
ロゴ:"graphic"
他の内容はクラスPFDOMNodeを参照してください

サンプル

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
public class CustomerBarCodePrint {
      private static final String      TITLE= "cust_barcodesheet_title";
      private static final String      BARCODE_IMG      = "barcode_img";
      private static final String      BARCODE_VAL      = "barcode_val";
      private static final String      PUBLISH_DATE      = "publish_date";
      private static final String      PUBLISH_TEXT      = "publish_text";
      private final static String      FORM_CODE_58      = "CUSTOMER_BAR_58";
      private final static String      FORM_CODE_80      = "CUSTOMER_BAR_80";
      private final static int      RESULT_SUCCESS      = 0;      // 正常に終了しました。

      /**
       * 顧客バーコードの情報を印刷する
       *
       * @param context
       *      context
       * @param title
       *      タイトル
       * @param barcode
       *       バーコード
       * @param publishDate
       *       long型の印刷日付. 例えば:システムの日付を渡す <br>
       *      Date date = new Date();<br>
       *      long publishDate = date.getTime();
       * @param publish
       *      "発行"の印字
       * @return
       */
      public static int print(Context context, String title, String barcode,
      long publishDate, String publish) {

if (TextUtils.isEmpty(barcode) == true) {
      return RESULT_SUCCESS;
}
//---------------CustomerPrintForm で「・parse xml data」を行う------------↓
// 印字フォームマスター
CustomerPrintForm customerPrintForm = new CustomerPrintForm();
customerPrintForm.getQueryCursorList(context, null, null, null);

CustomerPrintForm printForm;
String mXmlData58mm;
String mXmlData80mm;

// 本業務のXMLをDBから取得する(二つ用紙)
printForm = customerPrintForm.getRecord(FORM_CODE_58);
if (printForm != null) {
      mXmlData58mm = printForm
.getStringAttribute(CustomerPrintForm.FIELD_PRTFORMDATA);
} else {
      mXmlData58mm = "";
}
printForm = customerPrintForm.getRecord(FORM_CODE_80);
if (printForm != null) {
      mXmlData80mm = printForm
.getStringAttribute(CustomerPrintForm.FIELD_PRTFORMDATA);
} else {
      mXmlData80mm = "";
}
//--------------------------------------------------------------------------↑
//------------------------------------create PrintFormSetting instance------↓

// 印字フォームをPrintFormSettingsに設定する
String prtType = "00"; // for receipt
FormCurrencySymbol currencySym = RegisterSettings
      .getFormCurrencySymbol();

PrintFormSettings pfSettings = new PrintFormSettings(context, null,
      null, prtType, currencySym);
pfSettings.setmXmlData58mm(mXmlData58mm);
pfSettings.setmXmlData80mm(mXmlData80mm);
//--------------------------------------------------------------------------↑
//--------------------------------set Data----------------------------------↓
// 印刷データをセットする
PrintFormDataObject pfdObj = PrintForm.parseXmlForm(pfSettings);
for (int idx = 0; idx < pfdObj.getmPfdomList80mm().size(); idx++) {
      String tagName = pfdObj.getmPfdomList80mm().get(idx).getTagName();
      PFDOMNode nodeData = pfdObj.getmPfdomList80mm().get(idx)
.getObjData();
      setNoteData(title, barcode, publishDate, publish, tagName, nodeData);
}

for (int idx = 0; idx < pfdObj.getmPfdomList58mm().size(); idx++) {
      String tagName = pfdObj.getmPfdomList58mm().get(idx).getTagName();
      PFDOMNode nodeData = pfdObj.getmPfdomList58mm().get(idx)
.getObjData();
      setNoteData(title, barcode, publishDate, publish, tagName, nodeData);
}
//--------------------------------------------------------------------------↑
//-------------------------print--------------------------------------------↓
// 印刷を実行する      
int ret = PrintForm.printOnceDataXMLData(pfdObj, pfSettings);
//--------------------------------------------------------------------------↑

if (ret != 0) {
      return ret;
}
return RESULT_SUCCESS;
      }

      private static void setNoteData(String title, String barcode,
      long publishDate, String publish, String tagName, PFDOMNode nodeData) {
if (TITLE.equals(tagName) == true) {
      nodeData.put(title);
} else if (BARCODE_IMG.equals(tagName) == true
      || BARCODE_VAL.equals(tagName) == true) {
      nodeData.put(barcode);
} else if (PUBLISH_DATE.equals(tagName) == true) {
      nodeData.put(publishDate);
} else if (PUBLISH_TEXT.equals(tagName) == true) {
      nodeData.put(publish);
}
      }