Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: xfa/src/fxbarcode/datamatrix/BC_EdifactEncoder.cpp

Issue 1172793002: Merge to XFA: Use stdint.h types throughout PDFium. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 // Original code is licensed as follows: 6 // Original code is licensed as follows:
7 /* 7 /*
8 * Copyright 2006-2007 Jeremias Maerki. 8 * Copyright 2006-2007 Jeremias Maerki.
9 * 9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * Licensed under the Apache License, Version 2.0 (the "License");
(...skipping 17 matching lines...) Expand all
28 #include "BC_SymbolInfo.h" 28 #include "BC_SymbolInfo.h"
29 #include "BC_EncoderContext.h" 29 #include "BC_EncoderContext.h"
30 #include "BC_HighLevelEncoder.h" 30 #include "BC_HighLevelEncoder.h"
31 #include "BC_EdifactEncoder.h" 31 #include "BC_EdifactEncoder.h"
32 CBC_EdifactEncoder::CBC_EdifactEncoder() 32 CBC_EdifactEncoder::CBC_EdifactEncoder()
33 { 33 {
34 } 34 }
35 CBC_EdifactEncoder::~CBC_EdifactEncoder() 35 CBC_EdifactEncoder::~CBC_EdifactEncoder()
36 { 36 {
37 } 37 }
38 FX_INT32 CBC_EdifactEncoder::getEncodingMode() 38 int32_t CBC_EdifactEncoder::getEncodingMode()
39 { 39 {
40 return EDIFACT_ENCODATION; 40 return EDIFACT_ENCODATION;
41 } 41 }
42 void CBC_EdifactEncoder::Encode(CBC_EncoderContext &context, FX_INT32 &e) 42 void CBC_EdifactEncoder::Encode(CBC_EncoderContext &context, int32_t &e)
43 { 43 {
44 CFX_WideString buffer; 44 CFX_WideString buffer;
45 while (context.hasMoreCharacters()) { 45 while (context.hasMoreCharacters()) {
46 FX_WCHAR c = context.getCurrentChar(); 46 FX_WCHAR c = context.getCurrentChar();
47 encodeChar(c, buffer, e); 47 encodeChar(c, buffer, e);
48 if (e != BCExceptionNO) { 48 if (e != BCExceptionNO) {
49 return; 49 return;
50 } 50 }
51 context.m_pos++; 51 context.m_pos++;
52 FX_INT32 count = buffer.GetLength(); 52 int32_t count = buffer.GetLength();
53 if (count >= 4) { 53 if (count >= 4) {
54 context.writeCodewords(encodeToCodewords(buffer, 0, e)); 54 context.writeCodewords(encodeToCodewords(buffer, 0, e));
55 if (e != BCExceptionNO) { 55 if (e != BCExceptionNO) {
56 return; 56 return;
57 } 57 }
58 buffer.Delete(0, 4); 58 buffer.Delete(0, 4);
59 FX_INT32 newMode = CBC_HighLevelEncoder::lookAheadTest(context.m_msg , context.m_pos, getEncodingMode()); 59 int32_t newMode = CBC_HighLevelEncoder::lookAheadTest(context.m_msg, context.m_pos, getEncodingMode());
60 if (newMode != getEncodingMode()) { 60 if (newMode != getEncodingMode()) {
61 context.signalEncoderChange(ASCII_ENCODATION); 61 context.signalEncoderChange(ASCII_ENCODATION);
62 break; 62 break;
63 } 63 }
64 } 64 }
65 } 65 }
66 buffer += (FX_WCHAR)31; 66 buffer += (FX_WCHAR)31;
67 handleEOD(context, buffer, e); 67 handleEOD(context, buffer, e);
68 } 68 }
69 void CBC_EdifactEncoder::handleEOD(CBC_EncoderContext &context, CFX_WideString b uffer, FX_INT32 &e) 69 void CBC_EdifactEncoder::handleEOD(CBC_EncoderContext &context, CFX_WideString b uffer, int32_t &e)
70 { 70 {
71 FX_INT32 count = buffer.GetLength(); 71 int32_t count = buffer.GetLength();
72 if (count == 0) { 72 if (count == 0) {
73 return; 73 return;
74 } 74 }
75 if (count == 1) { 75 if (count == 1) {
76 context.updateSymbolInfo(e); 76 context.updateSymbolInfo(e);
77 if (e != BCExceptionNO) { 77 if (e != BCExceptionNO) {
78 return; 78 return;
79 } 79 }
80 FX_INT32 available = context.m_symbolInfo->m_dataCapacity - context.getC odewordCount(); 80 int32_t available = context.m_symbolInfo->m_dataCapacity - context.getCo dewordCount();
81 FX_INT32 remaining = context.getRemainingCharacters(); 81 int32_t remaining = context.getRemainingCharacters();
82 if (remaining == 0 && available <= 2) { 82 if (remaining == 0 && available <= 2) {
83 return; 83 return;
84 } 84 }
85 } 85 }
86 if (count > 4) { 86 if (count > 4) {
87 e = BCExceptionIllegalStateCountMustNotExceed4; 87 e = BCExceptionIllegalStateCountMustNotExceed4;
88 return; 88 return;
89 } 89 }
90 FX_INT32 restChars = count - 1; 90 int32_t restChars = count - 1;
91 CFX_WideString encoded = encodeToCodewords(buffer, 0, e); 91 CFX_WideString encoded = encodeToCodewords(buffer, 0, e);
92 if (e != BCExceptionNO) { 92 if (e != BCExceptionNO) {
93 return; 93 return;
94 } 94 }
95 FX_BOOL endOfSymbolReached = !context.hasMoreCharacters(); 95 FX_BOOL endOfSymbolReached = !context.hasMoreCharacters();
96 FX_BOOL restInAscii = endOfSymbolReached && restChars <= 2; 96 FX_BOOL restInAscii = endOfSymbolReached && restChars <= 2;
97 if (restChars <= 2) { 97 if (restChars <= 2) {
98 context.updateSymbolInfo(context.getCodewordCount() + restChars, e); 98 context.updateSymbolInfo(context.getCodewordCount() + restChars, e);
99 if (e != BCExceptionNO) { 99 if (e != BCExceptionNO) {
100 return; 100 return;
101 } 101 }
102 FX_INT32 available = context.m_symbolInfo->m_dataCapacity - context.getC odewordCount(); 102 int32_t available = context.m_symbolInfo->m_dataCapacity - context.getCo dewordCount();
103 if (available >= 3) { 103 if (available >= 3) {
104 restInAscii = FALSE; 104 restInAscii = FALSE;
105 context.updateSymbolInfo(context.getCodewordCount() + encoded.GetLen gth(), e); 105 context.updateSymbolInfo(context.getCodewordCount() + encoded.GetLen gth(), e);
106 if (e != BCExceptionNO) { 106 if (e != BCExceptionNO) {
107 return; 107 return;
108 } 108 }
109 } 109 }
110 } 110 }
111 if (restInAscii) { 111 if (restInAscii) {
112 context.resetSymbolInfo(); 112 context.resetSymbolInfo();
113 context.m_pos -= restChars; 113 context.m_pos -= restChars;
114 } else { 114 } else {
115 context.writeCodewords(encoded); 115 context.writeCodewords(encoded);
116 } 116 }
117 context.signalEncoderChange(ASCII_ENCODATION); 117 context.signalEncoderChange(ASCII_ENCODATION);
118 } 118 }
119 void CBC_EdifactEncoder::encodeChar(FX_WCHAR c, CFX_WideString &sb, FX_INT32 &e) 119 void CBC_EdifactEncoder::encodeChar(FX_WCHAR c, CFX_WideString &sb, int32_t &e)
120 { 120 {
121 if (c >= ' ' && c <= '?') { 121 if (c >= ' ' && c <= '?') {
122 sb += c; 122 sb += c;
123 } else if (c >= '@' && c <= '^') { 123 } else if (c >= '@' && c <= '^') {
124 sb += (FX_WCHAR)(c - 64); 124 sb += (FX_WCHAR)(c - 64);
125 } else { 125 } else {
126 CBC_HighLevelEncoder::illegalCharacter(c, e); 126 CBC_HighLevelEncoder::illegalCharacter(c, e);
127 } 127 }
128 } 128 }
129 CFX_WideString CBC_EdifactEncoder::encodeToCodewords(CFX_WideString sb, FX_INT32 startPos, FX_INT32 &e) 129 CFX_WideString CBC_EdifactEncoder::encodeToCodewords(CFX_WideString sb, int32_t startPos, int32_t &e)
130 { 130 {
131 FX_INT32 len = sb.GetLength() - startPos; 131 int32_t len = sb.GetLength() - startPos;
132 if (len == 0) { 132 if (len == 0) {
133 e = BCExceptionNoContents; 133 e = BCExceptionNoContents;
134 return (FX_LPWSTR)""; 134 return (FX_LPWSTR)"";
135 } 135 }
136 FX_WCHAR c1 = sb.GetAt(startPos); 136 FX_WCHAR c1 = sb.GetAt(startPos);
137 FX_WCHAR c2 = len >= 2 ? sb.GetAt(startPos + 1) : 0; 137 FX_WCHAR c2 = len >= 2 ? sb.GetAt(startPos + 1) : 0;
138 FX_WCHAR c3 = len >= 3 ? sb.GetAt(startPos + 2) : 0; 138 FX_WCHAR c3 = len >= 3 ? sb.GetAt(startPos + 2) : 0;
139 FX_WCHAR c4 = len >= 4 ? sb.GetAt(startPos + 3) : 0; 139 FX_WCHAR c4 = len >= 4 ? sb.GetAt(startPos + 3) : 0;
140 FX_INT32 v = (c1 << 18) + (c2 << 12) + (c3 << 6) + c4; 140 int32_t v = (c1 << 18) + (c2 << 12) + (c3 << 6) + c4;
141 FX_WCHAR cw1 = (FX_WCHAR) ((v >> 16) & 255); 141 FX_WCHAR cw1 = (FX_WCHAR) ((v >> 16) & 255);
142 FX_WCHAR cw2 = (FX_WCHAR) ((v >> 8) & 255); 142 FX_WCHAR cw2 = (FX_WCHAR) ((v >> 8) & 255);
143 FX_WCHAR cw3 = (FX_WCHAR) (v & 255); 143 FX_WCHAR cw3 = (FX_WCHAR) (v & 255);
144 CFX_WideString res; 144 CFX_WideString res;
145 res += cw1; 145 res += cw1;
146 if (len >= 2) { 146 if (len >= 2) {
147 res += cw2; 147 res += cw2;
148 } 148 }
149 if (len >= 3) { 149 if (len >= 3) {
150 res += cw3; 150 res += cw3;
151 } 151 }
152 return res; 152 return res;
153 } 153 }
OLDNEW
« no previous file with comments | « xfa/src/fxbarcode/datamatrix/BC_EdifactEncoder.h ('k') | xfa/src/fxbarcode/datamatrix/BC_Encoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698