Ejemplo n.º 1
0
int32_t CBC_OnedCode128Writer::Encode128C(const CFX_ByteString& contents,
                                          CFX_PtrArray& patterns) {
  int32_t checkSum = 0;
  int32_t checkWeight = 1;
  int32_t position = 0;
  patterns.Add((int32_t*)CBC_OnedCode128Reader::CODE_PATTERNS[CODE_START_C]);
  checkSum += CODE_START_C * checkWeight;
  while (position < contents.GetLength()) {
    int32_t patternIndex = 0;
    FX_CHAR ch = contents.GetAt(position);
    if (ch < '0' || ch > '9') {
      patternIndex = (int32_t)ch;
      position++;
    } else {
      patternIndex = FXSYS_atoi(contents.Mid(position, 2));
      if (contents.GetAt(position + 1) < '0' ||
          contents.GetAt(position + 1) > '9') {
        position += 1;
      } else {
        position += 2;
      }
    }
    patterns.Add((int32_t*)CBC_OnedCode128Reader::CODE_PATTERNS[patternIndex]);
    checkSum += patternIndex * checkWeight;
    if (position != 0) {
      checkWeight++;
    }
  }
  return checkSum;
}
Ejemplo n.º 2
0
CFX_ByteArray& CBC_HighLevelEncoder::getBytesForMessage(CFX_WideString msg) {
  CFX_ByteString bytestr;
  CBC_UtilCodingConvert::UnicodeToUTF8(msg, bytestr);
  for (int32_t i = 0; i < bytestr.GetLength(); i++) {
    m_bytearray.Add(bytestr.GetAt(i));
  }
  return m_bytearray;
}
Ejemplo n.º 3
0
CBC_EncoderContext::CBC_EncoderContext(const CFX_WideString msg,
                                       CFX_WideString ecLevel,
                                       int32_t& e) {
  CFX_ByteString dststr;
  CBC_UtilCodingConvert::UnicodeToUTF8(msg, dststr);
  CFX_WideString sb;
  int32_t c = dststr.GetLength();
  for (int32_t i = 0; i < c; i++) {
    FX_WCHAR ch = (FX_WCHAR)(dststr.GetAt(i) & 0xff);
    if (ch == '?' && dststr.GetAt(i) != '?') {
      e = BCExceptionCharactersOutsideISO88591Encoding;
    }
    sb += ch;
  }
  m_msg = sb;
  m_shape = FORCE_NONE;
  m_newEncoding = -1;
  m_pos = 0;
  m_symbolInfo = NULL;
  m_skipAtEnd = 0;
  m_maxSize = NULL;
  m_minSize = NULL;
}
CFX_WideString CBC_PDF417HighLevelEncoder::encodeHighLevel(
    CFX_WideString wideMsg,
    Compaction compaction,
    int32_t& e) {
  CFX_ByteString bytes;
  CBC_UtilCodingConvert::UnicodeToUTF8(wideMsg, bytes);
  CFX_WideString msg;
  int32_t len = bytes.GetLength();
  for (int32_t i = 0; i < len; i++) {
    FX_WCHAR ch = (FX_WCHAR)(bytes.GetAt(i) & 0xff);
    if (ch == '?' && bytes.GetAt(i) != '?') {
      e = BCExceptionCharactersOutsideISO88591Encoding;
      return CFX_WideString();
    }
    msg += ch;
  }
  CFX_ByteArray byteArr;
  for (int32_t k = 0; k < bytes.GetLength(); k++) {
    byteArr.Add(bytes.GetAt(k));
  }
  CFX_WideString sb;
  len = msg.GetLength();
  int32_t p = 0;
  int32_t textSubMode = SUBMODE_ALPHA;
  if (compaction == TEXT) {
    encodeText(msg, p, len, sb, textSubMode);
  } else if (compaction == BYTES) {
    encodeBinary(&byteArr, p, byteArr.GetSize(), BYTE_COMPACTION, sb);
  } else if (compaction == NUMERIC) {
    sb += (FX_WCHAR)LATCH_TO_NUMERIC;
    encodeNumeric(msg, p, len, sb);
  } else {
    int32_t encodingMode = LATCH_TO_TEXT;
    while (p < len) {
      int32_t n = determineConsecutiveDigitCount(msg, p);
      if (n >= 13) {
        sb += (FX_WCHAR)LATCH_TO_NUMERIC;
        encodingMode = NUMERIC_COMPACTION;
        textSubMode = SUBMODE_ALPHA;
        encodeNumeric(msg, p, n, sb);
        p += n;
      } else {
        int32_t t = determineConsecutiveTextCount(msg, p);
        if (t >= 5 || n == len) {
          if (encodingMode != TEXT_COMPACTION) {
            sb += (FX_WCHAR)LATCH_TO_TEXT;
            encodingMode = TEXT_COMPACTION;
            textSubMode = SUBMODE_ALPHA;
          }
          textSubMode = encodeText(msg, p, t, sb, textSubMode);
          p += t;
        } else {
          int32_t b = determineConsecutiveBinaryCount(msg, &byteArr, p, e);
          BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR)' ');
          if (b == 0) {
            b = 1;
          }
          if (b == 1 && encodingMode == TEXT_COMPACTION) {
            encodeBinary(&byteArr, p, 1, TEXT_COMPACTION, sb);
          } else {
            encodeBinary(&byteArr, p, b, encodingMode, sb);
            encodingMode = BYTE_COMPACTION;
            textSubMode = SUBMODE_ALPHA;
          }
          p += b;
        }
      }
    }
  }
  return sb;
}