Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cbc_eancode.cpp
Go to the documentation of this file.
1// Copyright 2018 The PDFium Authors
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
7#include "fxbarcode/cbc_eancode.h"
8
9#include <utility>
10
11#include "fxbarcode/BC_Library.h"
12#include "fxbarcode/oned/BC_OnedEANWriter.h"
13
14CBC_EANCode::CBC_EANCode(std::unique_ptr<CBC_OneDimEANWriter> pWriter)
15 : CBC_OneCode(std::move(pWriter)) {}
16
17CBC_EANCode::~CBC_EANCode() = default;
18
20 return static_cast<CBC_OneDimEANWriter*>(m_pBCWriter.get());
21}
22
23bool CBC_EANCode::Encode(WideStringView contents) {
24 auto* pWriter = GetOneDimEANWriter();
25 if (!pWriter->CheckContentValidity(contents))
26 return false;
27
28 m_renderContents = Preprocess(contents);
29 ByteString str = m_renderContents.ToUTF8();
30 pWriter->InitEANWriter();
31 return pWriter->RenderResult(m_renderContents.AsStringView(),
32 pWriter->Encode(str));
33}
34
36 const CFX_Matrix& matrix) {
37 return GetOneDimEANWriter()->RenderDeviceResult(
38 device, matrix, m_renderContents.AsStringView());
39}
40
41WideString CBC_EANCode::Preprocess(WideStringView contents) {
42 auto* pWriter = GetOneDimEANWriter();
43 WideString encoded_contents = pWriter->FilterContents(contents);
44 size_t length = encoded_contents.GetLength();
45 size_t max_length = GetMaxLength();
46 if (length <= max_length) {
47 for (size_t i = 0; i < max_length - length; i++)
48 encoded_contents.InsertAtFront(L'0');
49
50 ByteString str = encoded_contents.ToUTF8();
51 int32_t checksum = pWriter->CalcChecksum(str);
52 str += '0' + checksum;
53 encoded_contents = WideString::FromUTF8(str.AsStringView());
54 } else {
55 encoded_contents = encoded_contents.First(max_length + 1);
56 }
57
58 return encoded_contents;
59}
CBC_EANCode(std::unique_ptr< CBC_OneDimEANWriter > pWriter)
WideString Preprocess(WideStringView contents)
bool RenderDevice(CFX_RenderDevice *device, const CFX_Matrix &matrix) override
bool Encode(WideStringView contents) override
~CBC_EANCode() override
CBC_OneDimEANWriter * GetOneDimEANWriter()
virtual int32_t CalcChecksum(const ByteString &contents)=0
virtual void InitEANWriter()
virtual WideString FilterContents(WideStringView contents)=0
virtual bool CheckContentValidity(WideStringView contents)=0
ByteString & operator+=(char ch)
ByteString ToUTF8() const
static WideString FromUTF8(ByteStringView str)