| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
| 6 // Original code is licensed as follows: | |
| 7 /* | |
| 8 * Copyright 2007 ZXing authors | |
| 9 * | |
| 10 * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 11 * you may not use this file except in compliance with the License. | |
| 12 * You may obtain a copy of the License at | |
| 13 * | |
| 14 * http://www.apache.org/licenses/LICENSE-2.0 | |
| 15 * | |
| 16 * Unless required by applicable law or agreed to in writing, software | |
| 17 * distributed under the License is distributed on an "AS IS" BASIS, | |
| 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 19 * See the License for the specific language governing permissions and | |
| 20 * limitations under the License. | |
| 21 */ | |
| 22 | |
| 23 #include <stdint.h> | |
| 24 | |
| 25 #include "xfa/src/fxbarcode/datamatrix/BC_DataMatrixVersion.h" | |
| 26 #include "xfa/src/fxbarcode/utils.h" | |
| 27 | |
| 28 CFX_PtrArray* CBC_DataMatrixVersion::VERSIONS = NULL; | |
| 29 | |
| 30 void CBC_DataMatrixVersion::Initialize() { | |
| 31 VERSIONS = new CFX_PtrArray(); | |
| 32 } | |
| 33 void CBC_DataMatrixVersion::Finalize() { | |
| 34 for (int32_t i = 0; i < VERSIONS->GetSize(); i++) { | |
| 35 delete ((CBC_DataMatrixVersion*)(VERSIONS->GetAt(i))); | |
| 36 } | |
| 37 VERSIONS->RemoveAll(); | |
| 38 delete VERSIONS; | |
| 39 } | |
| 40 CBC_DataMatrixVersion::CBC_DataMatrixVersion(int32_t versionNumber, | |
| 41 int32_t symbolSizeRows, | |
| 42 int32_t symbolSizeColumns, | |
| 43 int32_t dataRegionSizeRows, | |
| 44 int32_t dataRegionSizeColumns, | |
| 45 ECBlocks* ecBlocks) { | |
| 46 m_versionNumber = versionNumber; | |
| 47 m_symbolSizeRows = symbolSizeRows; | |
| 48 m_symbolSizeColumns = symbolSizeColumns; | |
| 49 m_dataRegionSizeRows = dataRegionSizeRows; | |
| 50 m_dataRegionSizeColumns = dataRegionSizeColumns; | |
| 51 m_ecBlocks = ecBlocks; | |
| 52 int32_t total = 0; | |
| 53 int32_t ecCodewords = ecBlocks->GetECCodewords(); | |
| 54 const CFX_PtrArray& ecbArray = ecBlocks->GetECBlocks(); | |
| 55 for (int32_t i = 0; i < ecbArray.GetSize(); i++) { | |
| 56 total += ((ECB*)ecbArray[i])->GetCount() * | |
| 57 (((ECB*)ecbArray[i])->GetDataCodewords() + ecCodewords); | |
| 58 } | |
| 59 m_totalCodewords = total; | |
| 60 } | |
| 61 CBC_DataMatrixVersion::~CBC_DataMatrixVersion() { | |
| 62 delete m_ecBlocks; | |
| 63 } | |
| 64 int32_t CBC_DataMatrixVersion::GetVersionNumber() { | |
| 65 return m_versionNumber; | |
| 66 } | |
| 67 int32_t CBC_DataMatrixVersion::GetSymbolSizeRows() { | |
| 68 return m_symbolSizeRows; | |
| 69 } | |
| 70 int32_t CBC_DataMatrixVersion::GetSymbolSizeColumns() { | |
| 71 return m_symbolSizeColumns; | |
| 72 } | |
| 73 int32_t CBC_DataMatrixVersion::GetDataRegionSizeRows() { | |
| 74 return m_dataRegionSizeRows; | |
| 75 } | |
| 76 int32_t CBC_DataMatrixVersion::GetDataRegionSizeColumns() { | |
| 77 return m_dataRegionSizeColumns; | |
| 78 } | |
| 79 int32_t CBC_DataMatrixVersion::GetTotalCodewords() { | |
| 80 return m_totalCodewords; | |
| 81 } | |
| 82 ECBlocks* CBC_DataMatrixVersion::GetECBlocks() { | |
| 83 return m_ecBlocks; | |
| 84 } | |
| 85 void CBC_DataMatrixVersion::ReleaseAll() { | |
| 86 for (int32_t i = 0; i < VERSIONS->GetSize(); i++) { | |
| 87 delete (CBC_DataMatrixVersion*)VERSIONS->GetAt(i); | |
| 88 } | |
| 89 VERSIONS->RemoveAll(); | |
| 90 } | |
| 91 CBC_DataMatrixVersion* CBC_DataMatrixVersion::GetVersionForDimensions( | |
| 92 int32_t numRows, | |
| 93 int32_t numColumns, | |
| 94 int32_t& e) { | |
| 95 if ((numRows & 0x01) != 0 || (numColumns & 0x01) != 0) { | |
| 96 e = BCExceptionNotFound; | |
| 97 return NULL; | |
| 98 } | |
| 99 if (VERSIONS->GetSize() == 0) { | |
| 100 VERSIONS->Add(new CBC_DataMatrixVersion(1, 10, 10, 8, 8, | |
| 101 new ECBlocks(5, new ECB(1, 3)))); | |
| 102 VERSIONS->Add(new CBC_DataMatrixVersion(2, 12, 12, 10, 10, | |
| 103 new ECBlocks(7, new ECB(1, 5)))); | |
| 104 VERSIONS->Add(new CBC_DataMatrixVersion(3, 14, 14, 12, 12, | |
| 105 new ECBlocks(10, new ECB(1, 8)))); | |
| 106 VERSIONS->Add(new CBC_DataMatrixVersion(4, 16, 16, 14, 14, | |
| 107 new ECBlocks(12, new ECB(1, 12)))); | |
| 108 VERSIONS->Add(new CBC_DataMatrixVersion(5, 18, 18, 16, 16, | |
| 109 new ECBlocks(14, new ECB(1, 18)))); | |
| 110 VERSIONS->Add(new CBC_DataMatrixVersion(6, 20, 20, 18, 18, | |
| 111 new ECBlocks(18, new ECB(1, 22)))); | |
| 112 VERSIONS->Add(new CBC_DataMatrixVersion(7, 22, 22, 20, 20, | |
| 113 new ECBlocks(20, new ECB(1, 30)))); | |
| 114 VERSIONS->Add(new CBC_DataMatrixVersion(8, 24, 24, 22, 22, | |
| 115 new ECBlocks(24, new ECB(1, 36)))); | |
| 116 VERSIONS->Add(new CBC_DataMatrixVersion(9, 26, 26, 24, 24, | |
| 117 new ECBlocks(28, new ECB(1, 44)))); | |
| 118 VERSIONS->Add(new CBC_DataMatrixVersion(10, 32, 32, 14, 14, | |
| 119 new ECBlocks(36, new ECB(1, 62)))); | |
| 120 VERSIONS->Add(new CBC_DataMatrixVersion(11, 36, 36, 16, 16, | |
| 121 new ECBlocks(42, new ECB(1, 86)))); | |
| 122 VERSIONS->Add(new CBC_DataMatrixVersion(12, 40, 40, 18, 18, | |
| 123 new ECBlocks(48, new ECB(1, 114)))); | |
| 124 VERSIONS->Add(new CBC_DataMatrixVersion(13, 44, 44, 20, 20, | |
| 125 new ECBlocks(56, new ECB(1, 144)))); | |
| 126 VERSIONS->Add(new CBC_DataMatrixVersion(14, 48, 48, 22, 22, | |
| 127 new ECBlocks(68, new ECB(1, 174)))); | |
| 128 VERSIONS->Add(new CBC_DataMatrixVersion(15, 52, 52, 24, 24, | |
| 129 new ECBlocks(42, new ECB(2, 102)))); | |
| 130 VERSIONS->Add(new CBC_DataMatrixVersion(16, 64, 64, 14, 14, | |
| 131 new ECBlocks(56, new ECB(2, 140)))); | |
| 132 VERSIONS->Add(new CBC_DataMatrixVersion(17, 72, 72, 16, 16, | |
| 133 new ECBlocks(36, new ECB(4, 92)))); | |
| 134 VERSIONS->Add(new CBC_DataMatrixVersion(18, 80, 80, 18, 18, | |
| 135 new ECBlocks(48, new ECB(4, 114)))); | |
| 136 VERSIONS->Add(new CBC_DataMatrixVersion(19, 88, 88, 20, 20, | |
| 137 new ECBlocks(56, new ECB(4, 144)))); | |
| 138 VERSIONS->Add(new CBC_DataMatrixVersion(20, 96, 96, 22, 22, | |
| 139 new ECBlocks(68, new ECB(4, 174)))); | |
| 140 VERSIONS->Add(new CBC_DataMatrixVersion(21, 104, 104, 24, 24, | |
| 141 new ECBlocks(56, new ECB(6, 136)))); | |
| 142 VERSIONS->Add(new CBC_DataMatrixVersion(22, 120, 120, 18, 18, | |
| 143 new ECBlocks(68, new ECB(6, 175)))); | |
| 144 VERSIONS->Add(new CBC_DataMatrixVersion(23, 132, 132, 20, 20, | |
| 145 new ECBlocks(62, new ECB(8, 163)))); | |
| 146 VERSIONS->Add(new CBC_DataMatrixVersion( | |
| 147 24, 144, 144, 22, 22, | |
| 148 new ECBlocks(62, new ECB(8, 156), new ECB(2, 155)))); | |
| 149 VERSIONS->Add(new CBC_DataMatrixVersion(25, 8, 18, 6, 16, | |
| 150 new ECBlocks(7, new ECB(1, 5)))); | |
| 151 VERSIONS->Add(new CBC_DataMatrixVersion(26, 8, 32, 6, 14, | |
| 152 new ECBlocks(11, new ECB(1, 10)))); | |
| 153 VERSIONS->Add(new CBC_DataMatrixVersion(27, 12, 26, 10, 24, | |
| 154 new ECBlocks(14, new ECB(1, 16)))); | |
| 155 VERSIONS->Add(new CBC_DataMatrixVersion(28, 12, 36, 10, 16, | |
| 156 new ECBlocks(18, new ECB(1, 22)))); | |
| 157 VERSIONS->Add(new CBC_DataMatrixVersion(29, 16, 36, 14, 16, | |
| 158 new ECBlocks(24, new ECB(1, 32)))); | |
| 159 VERSIONS->Add(new CBC_DataMatrixVersion(30, 16, 48, 14, 22, | |
| 160 new ECBlocks(28, new ECB(1, 49)))); | |
| 161 } | |
| 162 int32_t numVersions = VERSIONS->GetSize(); | |
| 163 for (int32_t i = 0; i < numVersions; ++i) { | |
| 164 if (((CBC_DataMatrixVersion*)((*VERSIONS)[i]))->m_symbolSizeRows == | |
| 165 numRows && | |
| 166 ((CBC_DataMatrixVersion*)((*VERSIONS)[i]))->m_symbolSizeColumns == | |
| 167 numColumns) { | |
| 168 return (CBC_DataMatrixVersion*)(*VERSIONS)[i]; | |
| 169 } | |
| 170 } | |
| 171 e = BCExceptionNotFound; | |
| 172 return NULL; | |
| 173 } | |
| OLD | NEW |