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 7 #ifndef FXBARCODE_ONED_BC_ONEDIMWRITER_H_ 8 #define FXBARCODE_ONED_BC_ONEDIMWRITER_H_ 9 10 #include <vector> 11 12 #include "core/fxcrt/fx_string.h" 13 #include "core/fxcrt/unowned_ptr.h" 14 #include "fxbarcode/BC_Library.h" 15 #include "fxbarcode/BC_Writer.h" 16 #include "fxbarcode/utils.h" 17 18 class CFX_Font; 19 class CFX_PathData; 20 class CFX_RenderDevice; 21 class TextCharPos; 22 23 class CBC_OneDimWriter : public CBC_Writer { 24 public: 25 CBC_OneDimWriter(); 26 ~CBC_OneDimWriter() override; 27 28 virtual bool RenderResult(WideStringView contents, 29 uint8_t* code, 30 int32_t codeLength); 31 virtual bool CheckContentValidity(WideStringView contents) = 0; 32 virtual WideString FilterContents(WideStringView contents) = 0; 33 virtual void SetPrintChecksum(bool checksum); 34 virtual void SetDataLength(int32_t length); 35 virtual void SetCalcChecksum(bool state); 36 virtual void SetFontSize(float size); 37 virtual void SetFontStyle(int32_t style); 38 virtual void SetFontColor(FX_ARGB color); 39 40 uint8_t* Encode(const ByteString& contents, 41 BCFORMAT format, 42 int32_t& outWidth, 43 int32_t& outHeight); 44 bool RenderDeviceResult(CFX_RenderDevice* device, 45 const CFX_Matrix* matrix, 46 WideStringView contents); 47 bool SetFont(CFX_Font* cFont); 48 49 protected: 50 virtual uint8_t* EncodeWithHint(const ByteString& contents, 51 BCFORMAT format, 52 int32_t& outWidth, 53 int32_t& outHeight, 54 int32_t hints); 55 virtual uint8_t* EncodeImpl(const ByteString& contents, 56 int32_t& outLength) = 0; 57 virtual bool ShowChars(WideStringView contents, 58 CFX_RenderDevice* device, 59 const CFX_Matrix* matrix, 60 int32_t barWidth, 61 int32_t multiple); 62 void ShowDeviceChars(CFX_RenderDevice* device, 63 const CFX_Matrix* matrix, 64 const ByteString str, 65 float geWidth, 66 TextCharPos* pCharPos, 67 float locX, 68 float locY, 69 int32_t barWidth); 70 void CalcTextInfo(const ByteString& text, 71 TextCharPos* charPos, 72 CFX_Font* cFont, 73 float geWidth, 74 int32_t fontSize, 75 float& charsLen); 76 int32_t AppendPattern(uint8_t* target, 77 int32_t pos, 78 const int8_t* pattern, 79 int32_t patternLength, 80 bool startColor); 81 82 void RenderVerticalBars(int32_t outputX, int32_t width); 83 84 bool m_bPrintChecksum = true; 85 bool m_bCalcChecksum = false; 86 bool m_bLeftPadding = false; 87 bool m_bRightPadding = false; 88 89 UnownedPtr<CFX_Font> m_pFont; 90 float m_fFontSize = 10.0f; 91 int32_t m_iFontStyle = 0; 92 uint32_t m_fontColor = 0xff000000; 93 BC_TEXT_LOC m_locTextLoc = BC_TEXT_LOC_BELOWEMBED; 94 95 int32_t m_iDataLenth = 0; 96 size_t m_iContentLen = 0; 97 98 std::vector<CFX_PathData> m_output; 99 int32_t m_barWidth; 100 int32_t m_multiple; 101 float m_outputHScale; 102 }; 103 104 #endif // FXBARCODE_ONED_BC_ONEDIMWRITER_H_ 105