Пример #1
0
FXFT_Face CFGAS_FontMgr::LoadFace(IFX_SeekableReadStream* pFontStream,
                                  int32_t iFaceIndex) {
  if (!pFontStream)
    return nullptr;

  CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr();
  pFontMgr->InitFTLibrary();
  FXFT_Library library = pFontMgr->GetFTLibrary();
  if (!library)
    return nullptr;

  FXFT_Stream ftStream = FX_Alloc(FXFT_StreamRec, 1);
  FXSYS_memset(ftStream, 0, sizeof(FXFT_StreamRec));
  ftStream->base = nullptr;
  ftStream->descriptor.pointer = pFontStream;
  ftStream->pos = 0;
  ftStream->size = static_cast<unsigned long>(pFontStream->GetSize());
  ftStream->read = _ftStreamRead;
  ftStream->close = _ftStreamClose;

  FXFT_Open_Args ftArgs;
  FXSYS_memset(&ftArgs, 0, sizeof(FXFT_Open_Args));
  ftArgs.flags |= FT_OPEN_STREAM;
  ftArgs.stream = ftStream;

  FXFT_Face pFace = nullptr;
  if (FXFT_Open_Face(library, &ftArgs, iFaceIndex, &pFace)) {
    FX_Free(ftStream);
    return nullptr;
  }

  FXFT_Set_Pixel_Sizes(pFace, 0, 64);
  return pFace;
}
Пример #2
0
CCodec_JpegDecoder::CCodec_JpegDecoder() {
  m_pScanlineBuf = nullptr;
  m_bStarted = FALSE;
  m_bInited = FALSE;
  FXSYS_memset(&cinfo, 0, sizeof(cinfo));
  FXSYS_memset(&jerr, 0, sizeof(jerr));
  FXSYS_memset(&src, 0, sizeof(src));
  m_nDefaultScaleDenom = 1;
}
Пример #3
0
CCodec_JpegDecoder::CCodec_JpegDecoder() {
  m_pScanlineBuf = NULL;
  m_DownScale = 1;
  m_bStarted = FALSE;
  m_bInited = FALSE;
  m_pExtProvider = NULL;
  m_pExtContext = NULL;
  FXSYS_memset(&cinfo, 0, sizeof(cinfo));
  FXSYS_memset(&jerr, 0, sizeof(jerr));
  FXSYS_memset(&src, 0, sizeof(src));
  m_nDefaultScaleDenom = 1;
}
Пример #4
0
void CBC_CommonByteArray::Reserve(int32_t capacity) {
  if (!m_bytes || m_size < capacity) {
    uint8_t* newArray = FX_Alloc(uint8_t, capacity);
    if (m_bytes) {
      FXSYS_memcpy(newArray, m_bytes, m_size);
      FXSYS_memset(newArray + m_size, 0, capacity - m_size);
    } else {
      FXSYS_memset(newArray, 0, capacity);
    }
    FX_Free(m_bytes);
    m_bytes = newArray;
    m_size = capacity;
  }
}
Пример #5
0
CFX_ByteString CPDF_StandardSecurityHandler::GetUserPassword(
    const uint8_t* owner_pass,
    FX_DWORD pass_size,
    int32_t key_len) {
  CFX_ByteString okey = m_pEncryptDict->GetString(FX_BSTRC("O"));
  uint8_t passcode[32];
  FX_DWORD i;
  for (i = 0; i < 32; i++) {
    passcode[i] = i < pass_size ? owner_pass[i] : defpasscode[i - pass_size];
  }
  uint8_t digest[16];
  CRYPT_MD5Generate(passcode, 32, digest);
  if (m_Revision >= 3) {
    for (int i = 0; i < 50; i++) {
      CRYPT_MD5Generate(digest, 16, digest);
    }
  }
  uint8_t enckey[32];
  FXSYS_memset(enckey, 0, sizeof(enckey));
  FX_DWORD copy_len = key_len;
  if (copy_len > sizeof(digest)) {
    copy_len = sizeof(digest);
  }
  FXSYS_memcpy(enckey, digest, copy_len);
  int okeylen = okey.GetLength();
  if (okeylen > 32) {
    okeylen = 32;
  }
  uint8_t okeybuf[64];
  FXSYS_memset(okeybuf, 0, sizeof(okeybuf));
  FXSYS_memcpy(okeybuf, okey.c_str(), okeylen);
  if (m_Revision == 2) {
    CRYPT_ArcFourCryptBlock(okeybuf, okeylen, enckey, key_len);
  } else {
    for (int i = 19; i >= 0; i--) {
      uint8_t tempkey[32];
      FXSYS_memset(tempkey, 0, sizeof(tempkey));
      for (int j = 0; j < m_KeyLen; j++) {
        tempkey[j] = enckey[j] ^ i;
      }
      CRYPT_ArcFourCryptBlock(okeybuf, okeylen, tempkey, key_len);
    }
  }
  int len = 32;
  while (len && defpasscode[len - 1] == okeybuf[len - 1]) {
    len--;
  }
  return CFX_ByteString(okeybuf, len);
}
Пример #6
0
FX_BOOL CPDF_StandardSecurityHandler::CheckUserPassword(
    const uint8_t* password,
    FX_DWORD pass_size,
    FX_BOOL bIgnoreEncryptMeta,
    uint8_t* key,
    int32_t key_len) {
  CalcEncryptKey(m_pEncryptDict, password, pass_size, key, key_len,
                 bIgnoreEncryptMeta, m_pParser->GetIDArray());
  CFX_ByteString ukey = m_pEncryptDict
                            ? m_pEncryptDict->GetString(FX_BSTRC("U"))
                            : CFX_ByteString();
  if (ukey.GetLength() < 16) {
    return FALSE;
  }
  uint8_t ukeybuf[32];
  if (m_Revision == 2) {
    FXSYS_memcpy(ukeybuf, defpasscode, 32);
    CRYPT_ArcFourCryptBlock(ukeybuf, 32, key, key_len);
  } else {
    uint8_t test[32], tmpkey[32];
    FX_DWORD copy_len = sizeof(test);
    if (copy_len > (FX_DWORD)ukey.GetLength()) {
      copy_len = ukey.GetLength();
    }
    FXSYS_memset(test, 0, sizeof(test));
    FXSYS_memset(tmpkey, 0, sizeof(tmpkey));
    FXSYS_memcpy(test, ukey.c_str(), copy_len);
    for (int i = 19; i >= 0; i--) {
      for (int j = 0; j < key_len; j++) {
        tmpkey[j] = key[j] ^ i;
      }
      CRYPT_ArcFourCryptBlock(test, 32, tmpkey, key_len);
    }
    uint8_t md5[100];
    CRYPT_MD5Start(md5);
    CRYPT_MD5Update(md5, defpasscode, 32);
    CPDF_Array* pIdArray = m_pParser->GetIDArray();
    if (pIdArray) {
      CFX_ByteString id = pIdArray->GetString(0);
      CRYPT_MD5Update(md5, (uint8_t*)id.c_str(), id.GetLength());
    }
    CRYPT_MD5Finish(md5, ukeybuf);
    return FXSYS_memcmp(test, ukeybuf, 16) == 0;
  }
  if (FXSYS_memcmp((void*)ukey.c_str(), ukeybuf, 16) == 0) {
    return TRUE;
  }
  return FALSE;
}
Пример #7
0
CFDE_TxtEdtPage::CFDE_TxtEdtPage(CFDE_TxtEdtEngine* pEngine, int32_t nPageIndex)
    : m_pEditEngine(pEngine),
      m_PieceMassArr(100),
      m_pBgnParag(nullptr),
      m_pEndParag(nullptr),
      m_nRefCount(0),
      m_nPageStart(-1),
      m_nCharCount(0),
      m_nPageIndex(nPageIndex),
      m_bLoaded(FALSE) {
  FXSYS_memset(&m_rtPage, 0, sizeof(CFX_RectF));
  FXSYS_memset(&m_rtPageMargin, 0, sizeof(CFX_RectF));
  FXSYS_memset(&m_rtPageContents, 0, sizeof(CFX_RectF));
  FXSYS_memset(&m_rtPageCanvas, 0, sizeof(CFX_RectF));
}
Пример #8
0
bool CCodec_RLScanlineDecoder::v_Rewind() {
  FXSYS_memset(m_pScanline, 0, m_Pitch);
  m_SrcOffset = 0;
  m_bEOD = false;
  m_Operator = 0;
  return true;
}
Пример #9
0
void CPWL_Wnd::Destroy() {
  KillFocus();

  OnDestroy();

  if (m_bCreated) {
    for (int32_t i = m_aChildren.GetSize() - 1; i >= 0; i--) {
      if (CPWL_Wnd* pChild = m_aChildren[i]) {
        pChild->Destroy();
        delete pChild;
        pChild = nullptr;
      }
    }

    if (m_sPrivateParam.pParentWnd)
      m_sPrivateParam.pParentWnd->OnNotify(this, PNM_REMOVECHILD);
    m_bCreated = FALSE;
  }

  DestroyMsgControl();

  FXSYS_memset(&m_sPrivateParam, 0, sizeof(PWL_CREATEPARAM));
  m_aChildren.RemoveAll();
  m_pVScrollBar = nullptr;
}
Пример #10
0
void CPDF_SecurityHandler::AES256_SetPerms(CPDF_Dictionary* pEncryptDict,
                                           uint32_t permissions,
                                           FX_BOOL bEncryptMetadata,
                                           const uint8_t* key) {
  uint8_t buf[16];
  buf[0] = (uint8_t)permissions;
  buf[1] = (uint8_t)(permissions >> 8);
  buf[2] = (uint8_t)(permissions >> 16);
  buf[3] = (uint8_t)(permissions >> 24);
  buf[4] = 0xff;
  buf[5] = 0xff;
  buf[6] = 0xff;
  buf[7] = 0xff;
  buf[8] = bEncryptMetadata ? 'T' : 'F';
  buf[9] = 'a';
  buf[10] = 'd';
  buf[11] = 'b';
  uint8_t* aes = FX_Alloc(uint8_t, 2048);
  CRYPT_AESSetKey(aes, 16, key, 32, TRUE);
  uint8_t iv[16], buf1[16];
  FXSYS_memset(iv, 0, 16);
  CRYPT_AESSetIV(aes, iv);
  CRYPT_AESEncrypt(aes, buf1, buf, 16);
  FX_Free(aes);
  pEncryptDict->SetAtString("Perms", CFX_ByteString(buf1, 16));
}
Пример #11
0
void CBC_QRDecodedBitStreamParser::DecodeByteSegment(
    CBC_CommonBitSource* bits,
    CFX_ByteString& result,
    int32_t count,
    CBC_CommonCharacterSetECI* currentCharacterSetECI,
    CFX_Int32Array* byteSegments,
    int32_t byteModeDecode,
    int32_t& e) {
  if (count < 0) {
    e = BCExceptionNotFound;
    BC_EXCEPTION_CHECK_ReturnVoid(e);
  }
  if ((count << 3) > bits->Available()) {
    e = BCExceptionRead;
    BC_EXCEPTION_CHECK_ReturnVoid(e);
  }
  uint8_t* readBytes = FX_Alloc(uint8_t, count);
  FXSYS_memset(readBytes, 0x00, count);
  for (int32_t i = 0; i < count; i++) {
    readBytes[i] = (uint8_t)bits->ReadBits(8, e);
    BC_EXCEPTION_CHECK_ReturnVoid(e);
  }
  CFX_ByteString bs(readBytes, count);
  result += bs;
  FX_Free(readBytes);
}
Пример #12
0
FX_BOOL CCodec_RLScanlineDecoder::v_Rewind() {
  FXSYS_memset(m_pScanline, 0, m_Pitch);
  m_SrcOffset = 0;
  m_bEOD = FALSE;
  m_Operator = 0;
  return TRUE;
}
Пример #13
0
FX_BOOL CFDE_TxtEdtEngine::IsFitArea(CFX_WideString& wsText) {
  std::unique_ptr<CFDE_TextOut> pTextOut(new CFDE_TextOut);
  pTextOut->SetLineSpace(m_Param.fLineSpace);
  pTextOut->SetFont(m_Param.pFont);
  pTextOut->SetFontSize(m_Param.fFontSize);
  CFX_RectF rcText;
  FXSYS_memset(&rcText, 0, sizeof(rcText));
  uint32_t dwStyle = 0;
  if (!(m_Param.dwMode & FDE_TEXTEDITMODE_MultiLines))
    dwStyle |= FDE_TTOSTYLE_SingleLine;

  if (m_Param.dwMode & FDE_TEXTEDITMODE_AutoLineWrap) {
    dwStyle |= FDE_TTOSTYLE_LineWrap;
    rcText.width = m_Param.fPlateWidth;
  } else {
    rcText.width = 65535;
  }
  pTextOut->SetStyles(dwStyle);
  wsText += L"\n";
  pTextOut->CalcLogicSize(wsText.c_str(), wsText.GetLength(), rcText);
  wsText.Delete(wsText.GetLength() - 1);
  if ((m_Param.dwMode & FDE_TEXTEDITMODE_LimitArea_Horz) &&
      (rcText.width > m_Param.fPlateWidth)) {
    return FALSE;
  }
  if ((m_Param.dwMode & FDE_TEXTEDITMODE_LimitArea_Vert) &&
      (rcText.height > m_Param.fLineSpace * m_Param.nLineCount)) {
    return FALSE;
  }
  return TRUE;
}
Пример #14
0
int CPDF_Object::GetInteger() const
{
    CFX_AutoRestorer<int> restorer(&s_nCurRefDepth);
    if (++s_nCurRefDepth > OBJECT_REF_MAX_DEPTH) {
        return 0;
    }
    switch (m_Type) {
        case PDFOBJ_BOOLEAN:
            return ((CPDF_Boolean*)this)->m_bValue;
        case PDFOBJ_NUMBER:
            return ((CPDF_Number*)this)->GetInteger();
        case PDFOBJ_REFERENCE: {
                CPDF_Reference* pRef = (CPDF_Reference*)(void*)this;
                PARSE_CONTEXT context;
                FXSYS_memset(&context, 0, sizeof(PARSE_CONTEXT));
                if (pRef->m_pObjList == NULL) {
                    return 0;
                }
                CPDF_Object* pObj = pRef->m_pObjList->GetIndirectObject(pRef->m_RefObjNum, &context);
                if (pObj == NULL) {
                    return 0;
                }
                return pObj->GetInteger();
            }
    }
    return 0;
}
Пример #15
0
static void DrawFreeGouraudShading(CFX_DIBitmap* pBitmap,
                                   CFX_Matrix* pObject2Bitmap,
                                   CPDF_Stream* pShadingStream,
                                   CPDF_Function** pFuncs,
                                   int nFuncs,
                                   CPDF_ColorSpace* pCS,
                                   int alpha) {
  ASSERT(pBitmap->GetFormat() == FXDIB_Argb);

  CPDF_MeshStream stream;
  if (!stream.Load(pShadingStream, pFuncs, nFuncs, pCS))
    return;

  CPDF_MeshVertex triangle[3];
  FXSYS_memset(triangle, 0, sizeof(triangle));

  while (!stream.m_BitStream.IsEOF()) {
    CPDF_MeshVertex vertex;
    FX_DWORD flag = stream.GetVertex(vertex, pObject2Bitmap);
    if (flag == 0) {
      triangle[0] = vertex;
      for (int j = 1; j < 3; j++) {
        stream.GetVertex(triangle[j], pObject2Bitmap);
      }
    } else {
      if (flag == 1) {
        triangle[0] = triangle[1];
      }
      triangle[1] = triangle[2];
      triangle[2] = vertex;
    }
    DrawGouraud(pBitmap, alpha, triangle);
  }
}
CFX_WideString CBC_PDF417ErrorCorrection::generateErrorCorrection(
    CFX_WideString dataCodewords,
    int32_t errorCorrectionLevel,
    int32_t& e) {
  int32_t k = getErrorCorrectionCodewordCount(errorCorrectionLevel, e);
  if (e != BCExceptionNO)
    return L" ";
  FX_WCHAR* ech = FX_Alloc(FX_WCHAR, k);
  FXSYS_memset(ech, 0, k * sizeof(FX_WCHAR));
  int32_t sld = dataCodewords.GetLength();
  for (int32_t i = 0; i < sld; i++) {
    int32_t t1 = (dataCodewords.GetAt(i) + ech[k - 1]) % 929;
    int32_t t2;
    int32_t t3;
    for (int32_t j = k - 1; j >= 1; j--) {
      t2 = (t1 * EC_COEFFICIENTS[errorCorrectionLevel][j]) % 929;
      t3 = 929 - t2;
      ech[j] = (FX_WCHAR)((ech[j - 1] + t3) % 929);
    }
    t2 = (t1 * EC_COEFFICIENTS[errorCorrectionLevel][0]) % 929;
    t3 = 929 - t2;
    ech[0] = (FX_WCHAR)(t3 % 929);
  }
  CFX_WideString sb;
  for (int32_t j = k - 1; j >= 0; j--) {
    if (ech[j] != 0) {
      ech[j] = (FX_WCHAR)(929 - ech[j]);
    }
    sb += (FX_WCHAR)ech[j];
  }
  FX_Free(ech);
  return sb;
}
Пример #17
0
FXFT_Face CFPF_SkiaFontMgr::GetFontFace(IFX_FileRead* pFileRead,
                                        int32_t iFaceIndex) {
  if (!pFileRead) {
    return nullptr;
  }
  if (pFileRead->GetSize() == 0) {
    return nullptr;
  }
  if (iFaceIndex < 0) {
    return nullptr;
  }
  FXFT_StreamRec streamRec;
  FXSYS_memset(&streamRec, 0, sizeof(FXFT_StreamRec));
  streamRec.size = pFileRead->GetSize();
  streamRec.descriptor.pointer = pFileRead;
  streamRec.read = FPF_SkiaStream_Read;
  streamRec.close = FPF_SkiaStream_Close;
  FXFT_Open_Args args;
  args.flags = FT_OPEN_STREAM;
  args.stream = &streamRec;
  FXFT_Face face;
  if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) {
    return nullptr;
  }
  FXFT_Set_Pixel_Sizes(face, 0, 64);
  return face;
}
Пример #18
0
CFDE_TxtEdtPage::CFDE_TxtEdtPage(CFDE_TxtEdtEngine* pEngine, int32_t nPageIndex)
    : m_pTextSet(nullptr),
      m_pBgnParag(nullptr),
      m_pEndParag(nullptr),
      m_nRefCount(0),
      m_nPageStart(-1),
      m_nCharCount(0),
      m_nPageIndex(nPageIndex),
      m_bLoaded(FALSE),
      m_pCharWidth(nullptr) {
    FXSYS_memset(&m_rtPage, 0, sizeof(CFX_RectF));
    FXSYS_memset(&m_rtPageMargin, 0, sizeof(CFX_RectF));
    FXSYS_memset(&m_rtPageContents, 0, sizeof(CFX_RectF));
    FXSYS_memset(&m_rtPageCanvas, 0, sizeof(CFX_RectF));
    m_pEditEngine = static_cast<CFDE_TxtEdtEngine*>(pEngine);
}
Пример #19
0
void CPDF_CryptoHandler::CryptBlock(bool bEncrypt,
                                    uint32_t objnum,
                                    uint32_t gennum,
                                    const uint8_t* src_buf,
                                    uint32_t src_size,
                                    uint8_t* dest_buf,
                                    uint32_t& dest_size) {
  if (m_Cipher == FXCIPHER_NONE) {
    FXSYS_memcpy(dest_buf, src_buf, src_size);
    return;
  }
  uint8_t realkey[16];
  int realkeylen = 16;
  if (m_Cipher != FXCIPHER_AES || m_KeyLen != 32) {
    uint8_t key1[32];
    PopulateKey(objnum, gennum, key1);

    if (m_Cipher == FXCIPHER_AES) {
      FXSYS_memcpy(key1 + m_KeyLen + 5, "sAlT", 4);
    }
    CRYPT_MD5Generate(
        key1, m_Cipher == FXCIPHER_AES ? m_KeyLen + 9 : m_KeyLen + 5, realkey);
    realkeylen = m_KeyLen + 5;
    if (realkeylen > 16) {
      realkeylen = 16;
    }
  }
  if (m_Cipher == FXCIPHER_AES) {
    CRYPT_AESSetKey(m_pAESContext, 16, m_KeyLen == 32 ? m_EncryptKey : realkey,
                    m_KeyLen, bEncrypt);
    if (bEncrypt) {
      uint8_t iv[16];
      for (int i = 0; i < 16; i++) {
        iv[i] = (uint8_t)rand();
      }
      CRYPT_AESSetIV(m_pAESContext, iv);
      FXSYS_memcpy(dest_buf, iv, 16);
      int nblocks = src_size / 16;
      CRYPT_AESEncrypt(m_pAESContext, dest_buf + 16, src_buf, nblocks * 16);
      uint8_t padding[16];
      FXSYS_memcpy(padding, src_buf + nblocks * 16, src_size % 16);
      FXSYS_memset(padding + src_size % 16, 16 - src_size % 16,
                   16 - src_size % 16);
      CRYPT_AESEncrypt(m_pAESContext, dest_buf + nblocks * 16 + 16, padding,
                       16);
      dest_size = 32 + nblocks * 16;
    } else {
      CRYPT_AESSetIV(m_pAESContext, src_buf);
      CRYPT_AESDecrypt(m_pAESContext, dest_buf, src_buf + 16, src_size - 16);
      dest_size = src_size - 16;
      dest_size -= dest_buf[dest_size - 1];
    }
  } else {
    ASSERT(dest_size == src_size);
    if (dest_buf != src_buf) {
      FXSYS_memcpy(dest_buf, src_buf, src_size);
    }
    CRYPT_ArcFourCryptBlock(dest_buf, dest_size, realkey, realkeylen);
  }
}
Пример #20
0
FX_FONTDESCRIPTOR const* CFGAS_FontMgr::FindFont(const FX_WCHAR* pszFontFamily,
                                                 uint32_t dwFontStyles,
                                                 uint32_t dwMatchFlags,
                                                 uint16_t wCodePage,
                                                 uint32_t dwUSB,
                                                 FX_WCHAR wUnicode) {
  FX_FONTMATCHPARAMS params;
  FXSYS_memset(&params, 0, sizeof(params));
  params.dwUSB = dwUSB;
  params.wUnicode = wUnicode;
  params.wCodePage = wCodePage;
  params.pwsFamily = pszFontFamily;
  params.dwFontStyles = dwFontStyles;
  params.dwMatchFlags = dwMatchFlags;
  FX_FONTDESCRIPTOR const* pDesc = MatchDefaultFont(&params, m_FontFaces);
  if (pDesc)
    return pDesc;
  if (!pszFontFamily || !m_pEnumerator)
    return nullptr;

  CFX_FontDescriptors namedFonts(100);
  m_pEnumerator(namedFonts, pszFontFamily, wUnicode);
  params.pwsFamily = nullptr;
  pDesc = MatchDefaultFont(&params, namedFonts);
  if (!pDesc)
    return nullptr;
  for (int32_t i = m_FontFaces.GetSize() - 1; i >= 0; i--) {
    FX_FONTDESCRIPTOR const* pMatch = m_FontFaces.GetPtrAt(i);
    if (*pMatch == *pDesc)
      return pMatch;
  }
  int index = m_FontFaces.Add(*pDesc);
  return m_FontFaces.GetPtrAt(index);
}
Пример #21
0
CFX_FontMapper::CFX_FontMapper()
{
    FXSYS_memset(m_FoxitFaces, 0, sizeof m_FoxitFaces);
    m_MMFaces[0] = m_MMFaces[1] = NULL;
    m_pFontInfo = NULL;
    m_bListLoaded = FALSE;
    m_pFontEnumerator = NULL;
}
CPDF_GeneralStateData::CPDF_GeneralStateData() {
  FXSYS_memset(this, 0, sizeof(CPDF_GeneralStateData));
  FXSYS_strcpy((FX_CHAR*)m_BlendMode, "Normal");
  m_StrokeAlpha = 1.0f;
  m_FillAlpha = 1.0f;
  m_Flatness = 1.0f;
  m_Matrix.SetIdentity();
}
Пример #23
0
CFX_FontMgr::CFX_FontMgr()
{
    m_pBuiltinMapper = new CFX_FontMapper;
    m_pBuiltinMapper->m_pFontMgr = this;
    m_pExtMapper = NULL;
    m_FTLibrary = NULL;
    FXSYS_memset(m_ExternalFonts, 0, sizeof m_ExternalFonts);
}
Пример #24
0
uint8_t* CCodec_RLScanlineDecoder::v_GetNextLine()
{
    if (m_SrcOffset == 0) {
        GetNextOperator();
    } else {
        if (m_bEOD) {
            return NULL;
        }
    }
    FXSYS_memset(m_pScanline, 0, m_Pitch);
    FX_DWORD col_pos = 0;
    FX_BOOL	eol = FALSE;
    while (m_SrcOffset < m_SrcSize && !eol) {
        if (m_Operator < 128) {
            FX_DWORD copy_len = m_Operator + 1;
            if (col_pos + copy_len >= m_dwLineBytes) {
                copy_len = m_dwLineBytes - col_pos;
                eol = TRUE;
            }
            if (copy_len >= m_SrcSize - m_SrcOffset) {
                copy_len = m_SrcSize - m_SrcOffset;
                m_bEOD = TRUE;
            }
            FXSYS_memcpy(m_pScanline + col_pos, m_pSrcBuf + m_SrcOffset, copy_len);
            col_pos += copy_len;
            UpdateOperator((uint8_t)copy_len);
        } else if (m_Operator > 128) {
            int fill = 0;
            if (m_SrcOffset - 1 < m_SrcSize - 1) {
                fill = m_pSrcBuf[m_SrcOffset];
            }
            FX_DWORD duplicate_len = 257 - m_Operator;
            if (col_pos + duplicate_len >= m_dwLineBytes) {
                duplicate_len = m_dwLineBytes - col_pos;
                eol = TRUE;
            }
            FXSYS_memset(m_pScanline + col_pos, fill, duplicate_len);
            col_pos += duplicate_len;
            UpdateOperator((uint8_t)duplicate_len);
        } else {
            m_bEOD = TRUE;
            break;
        }
    }
    return m_pScanline;
}
Пример #25
0
void CFX_BinaryBuf::AppendFill(uint8_t byte, FX_STRSIZE count) {
  ExpandBuf(count);
  if (!m_pBuffer) {
    return;
  }
  FXSYS_memset(m_pBuffer + m_DataSize, byte, count);
  m_DataSize += count;
}
Пример #26
0
void CBC_CommonBitMatrix::Init(int32_t width, int32_t height) {
  m_width = width;
  m_height = height;
  int32_t rowSize = (width + 31) >> 5;
  m_rowSize = rowSize;
  m_bits = FX_Alloc2D(int32_t, m_rowSize, m_height);
  FXSYS_memset(m_bits, 0, m_rowSize * m_height * sizeof(int32_t));
}
Пример #27
0
void CBC_CommonBitMatrix::Init(int32_t dimension) {
  m_width = dimension;
  m_height = dimension;
  int32_t rowSize = (m_height + 31) >> 5;
  m_rowSize = rowSize;
  m_bits = FX_Alloc2D(int32_t, m_rowSize, m_height);
  FXSYS_memset(m_bits, 0, m_rowSize * m_height * sizeof(int32_t));
}
Пример #28
0
uint8_t* CCodec_RLScanlineDecoder::v_GetNextLine() {
  if (m_SrcOffset == 0) {
    GetNextOperator();
  } else {
    if (m_bEOD) {
      return nullptr;
    }
  }
  FXSYS_memset(m_pScanline, 0, m_Pitch);
  uint32_t col_pos = 0;
  bool eol = false;
  while (m_SrcOffset < m_SrcSize && !eol) {
    if (m_Operator < 128) {
      uint32_t copy_len = m_Operator + 1;
      if (col_pos + copy_len >= m_dwLineBytes) {
        copy_len = m_dwLineBytes - col_pos;
        eol = true;
      }
      if (copy_len >= m_SrcSize - m_SrcOffset) {
        copy_len = m_SrcSize - m_SrcOffset;
        m_bEOD = true;
      }
      FXSYS_memcpy(m_pScanline + col_pos, m_pSrcBuf + m_SrcOffset, copy_len);
      col_pos += copy_len;
      UpdateOperator((uint8_t)copy_len);
    } else if (m_Operator > 128) {
      int fill = 0;
      if (m_SrcOffset - 1 < m_SrcSize - 1) {
        fill = m_pSrcBuf[m_SrcOffset];
      }
      uint32_t duplicate_len = 257 - m_Operator;
      if (col_pos + duplicate_len >= m_dwLineBytes) {
        duplicate_len = m_dwLineBytes - col_pos;
        eol = true;
      }
      FXSYS_memset(m_pScanline + col_pos, fill, duplicate_len);
      col_pos += duplicate_len;
      UpdateOperator((uint8_t)duplicate_len);
    } else {
      m_bEOD = true;
      break;
    }
  }
  return m_pScanline;
}
Пример #29
0
FX_FILESIZE CFXCRT_FileAccess_Posix::GetSize() const {
  if (m_nFD < 0) {
    return 0;
  }
  struct stat s;
  FXSYS_memset(&s, 0, sizeof(s));
  fstat(m_nFD, &s);
  return s.st_size;
}
Пример #30
0
bool CFX_BasicArray::SetSize(int nNewSize) {
  if (nNewSize <= 0) {
    FX_Free(m_pData);
    m_pData = nullptr;
    m_nSize = m_nMaxSize = 0;
    return 0 == nNewSize;
  }

  if (!m_pData) {
    pdfium::base::CheckedNumeric<int> totalSize = nNewSize;
    totalSize *= m_nUnitSize;
    if (!totalSize.IsValid()) {
      m_nSize = m_nMaxSize = 0;
      return false;
    }
    m_pData =
        FX_Alloc(uint8_t, pdfium::base::ValueOrDieForType<size_t>(totalSize));
    m_nSize = m_nMaxSize = nNewSize;
  } else if (nNewSize <= m_nMaxSize) {
    if (nNewSize > m_nSize) {
      FXSYS_memset(m_pData + m_nSize * m_nUnitSize, 0,
                   (nNewSize - m_nSize) * m_nUnitSize);
    }
    m_nSize = nNewSize;
  } else {
    int nNewMax = nNewSize < m_nMaxSize ? m_nMaxSize : nNewSize;
    pdfium::base::CheckedNumeric<int> totalSize = nNewMax;
    totalSize *= m_nUnitSize;
    if (!totalSize.IsValid() || nNewMax < m_nSize) {
      return false;
    }
    uint8_t* pNewData = FX_Realloc(
        uint8_t, m_pData, pdfium::base::ValueOrDieForType<size_t>(totalSize));
    if (!pNewData) {
      return false;
    }
    FXSYS_memset(pNewData + m_nSize * m_nUnitSize, 0,
                 (nNewMax - m_nSize) * m_nUnitSize);
    m_pData = pNewData;
    m_nSize = nNewSize;
    m_nMaxSize = nNewMax;
  }
  return true;
}