CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& buf, const CPDF_Object* pObj) {
  if (!pObj) {
    buf << " null";
    return buf;
  }
  switch (pObj->GetType()) {
    case PDFOBJ_NULL:
      buf << " null";
      break;
    case PDFOBJ_BOOLEAN:
    case PDFOBJ_NUMBER:
      buf << " " << pObj->GetString();
      break;
    case PDFOBJ_STRING:
      buf << PDF_EncodeString(pObj->GetString(), pObj->AsString()->IsHex());
      break;
    case PDFOBJ_NAME: {
      CFX_ByteString str = pObj->GetString();
      buf << "/" << PDF_NameEncode(str);
      break;
    }
    case PDFOBJ_REFERENCE: {
      buf << " " << pObj->AsReference()->GetRefObjNum() << " 0 R ";
      break;
    }
    case PDFOBJ_ARRAY: {
      const CPDF_Array* p = pObj->AsArray();
      buf << "[";
      for (FX_DWORD i = 0; i < p->GetCount(); i++) {
        CPDF_Object* pElement = p->GetElement(i);
        if (pElement->GetObjNum()) {
          buf << " " << pElement->GetObjNum() << " 0 R";
        } else {
          buf << pElement;
        }
      }
      buf << "]";
      break;
    }
    case PDFOBJ_DICTIONARY: {
      const CPDF_Dictionary* p = pObj->AsDictionary();
      buf << "<<";
      for (const auto& it : *p) {
        const CFX_ByteString& key = it.first;
        CPDF_Object* pValue = it.second;
        buf << "/" << PDF_NameEncode(key);
        if (pValue && pValue->GetObjNum()) {
          buf << " " << pValue->GetObjNum() << " 0 R ";
        } else {
          buf << pValue;
        }
      }
      buf << ">>";
      break;
    }
    case PDFOBJ_STREAM: {
      const CPDF_Stream* p = pObj->AsStream();
      buf << p->GetDict() << "stream\r\n";
      CPDF_StreamAcc acc;
      acc.LoadAllData(p, TRUE);
      buf.AppendBlock(acc.GetData(), acc.GetSize());
      buf << "\r\nendstream";
      break;
    }
    default:
      ASSERT(FALSE);
      break;
  }
  return buf;
}
示例#2
0
static CFX_ByteString GetWordRenderString(const CFX_ByteString& strWords) {
  if (strWords.GetLength() > 0)
    return PDF_EncodeString(strWords) + " Tj\n";

  return "";
}
示例#3
0
CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& buf, const CPDF_Object* pObj) {
  if (pObj == NULL) {
    buf << FX_BSTRC(" null");
    return buf;
  }
  switch (pObj->GetType()) {
    case PDFOBJ_NULL:
      buf << FX_BSTRC(" null");
      break;
    case PDFOBJ_BOOLEAN:
    case PDFOBJ_NUMBER:
      buf << " " << pObj->GetString();
      break;
    case PDFOBJ_STRING:
      buf << PDF_EncodeString(pObj->GetString(), pObj->AsString()->IsHex());
      break;
    case PDFOBJ_NAME: {
      CFX_ByteString str = pObj->GetString();
      buf << FX_BSTRC("/") << PDF_NameEncode(str);
      break;
    }
    case PDFOBJ_REFERENCE: {
      buf << " " << pObj->AsReference()->GetRefObjNum() << FX_BSTRC(" 0 R ");
      break;
    }
    case PDFOBJ_ARRAY: {
      const CPDF_Array* p = pObj->AsArray();
      buf << FX_BSTRC("[");
      for (FX_DWORD i = 0; i < p->GetCount(); i++) {
        CPDF_Object* pElement = p->GetElement(i);
        if (pElement->GetObjNum()) {
          buf << " " << pElement->GetObjNum() << FX_BSTRC(" 0 R");
        } else {
          buf << pElement;
        }
      }
      buf << FX_BSTRC("]");
      break;
    }
    case PDFOBJ_DICTIONARY: {
      const CPDF_Dictionary* p = pObj->AsDictionary();
      buf << FX_BSTRC("<<");
      FX_POSITION pos = p->GetStartPos();
      while (pos) {
        CFX_ByteString key;
        CPDF_Object* pValue = p->GetNextElement(pos, key);
        buf << FX_BSTRC("/") << PDF_NameEncode(key);
        if (pValue && pValue->GetObjNum()) {
          buf << " " << pValue->GetObjNum() << FX_BSTRC(" 0 R ");
        } else {
          buf << pValue;
        }
      }
      buf << FX_BSTRC(">>");
      break;
    }
    case PDFOBJ_STREAM: {
      const CPDF_Stream* p = pObj->AsStream();
      buf << p->GetDict() << FX_BSTRC("stream\r\n");
      CPDF_StreamAcc acc;
      acc.LoadAllData(p, TRUE);
      buf.AppendBlock(acc.GetData(), acc.GetSize());
      buf << FX_BSTRC("\r\nendstream");
      break;
    }
    default:
      ASSERT(FALSE);
      break;
  }
  return buf;
}