void CSG_Doc_SVG::Draw_Polygon(CSG_Points &Points, int Fill_Color, int Line_Color, double Line_Width) { if( Points.Get_Count() > 2 ) { int i; CSG_String sPoints; CSG_String sWidth; for (i = 0; i < Points.Get_Count(); i++) { sPoints.Append(SG_Get_String(Points.Get_X(i),2)); sPoints.Append(SG_T(",")); sPoints.Append(SG_Get_String(Points.Get_Y(i),2)); sPoints.Append(SG_T(" ")); } m_sSVGCode.Append(SG_T("<polygon ")); _AddAttribute(SG_T("points"), sPoints); sWidth.Append(SG_Get_String(Line_Width,2)); sWidth.Append(g_Unit); _AddAttribute(SG_T("stroke-width"), sWidth); _AddAttribute(SG_T("stroke"), _Get_SVGColor(Line_Color)); _AddAttribute(SG_T("fill"), _Get_SVGColor(Fill_Color)); m_sSVGCode.Append(SG_T("/>\n")); } }
void CSG_Doc_SVG::Draw_LinkedPolygon(CSG_Points &Points, const SG_Char* Link, int Fill_Color, int Line_Color, double Line_Width) { if( Points.Get_Count() > 2 ) { int i; CSG_String sPoints; CSG_String sWidth; CSG_String sLink; for (i = 0; i < Points.Get_Count(); i++) { sPoints.Append(SG_Get_String(Points.Get_X(i),2)); sPoints.Append(SG_T(",")); sPoints.Append(SG_Get_String(Points.Get_Y(i),2)); sPoints.Append(SG_T(" ")); } m_sSVGCode.Append(SG_T("<polygon ")); _AddAttribute(SG_T("points"), sPoints); sWidth.Append(SG_Get_String(Line_Width,2)); sWidth.Append(g_Unit); _AddAttribute(SG_T("stroke-width"), sWidth); _AddAttribute(SG_T("stroke"), _Get_SVGColor(Line_Color)); _AddAttribute(SG_T("fill"), _Get_SVGColor(Fill_Color)); sLink = SG_T("window.open('"); sLink.Append(Link); sLink.Append(SG_T("')")); _AddAttribute(SG_T("onclick"), sLink); m_sSVGCode.Append(SG_T("/>\n")); } }
void CSG_Doc_SVG::Draw_Line(CSG_Points &Points, double Width, int Color) { int i; CSG_String sPoints; CSG_String sWidth; for (i = 0; i < Points.Get_Count(); i++) { sPoints.Append(SG_Get_String(Points.Get_X(i),2)); sPoints.Append(SG_T(",")); sPoints.Append(SG_Get_String(Points.Get_Y(i),2)); sPoints.Append(SG_T(" ")); } m_sSVGCode.Append(SG_T("<polyline ")); _AddAttribute(SG_T("points"), sPoints); sWidth.Append(SG_Get_String(Width,2)); sWidth.Append(g_Unit); _AddAttribute(SG_T("stroke-width"), sWidth); _AddAttribute(SG_T("stroke"), _Get_SVGColor(Color)); _AddAttribute(SG_T("fill"), SG_T("none")); m_sSVGCode.Append(SG_T("/>\n")); }
status_t PackageWriter::_AddData(DataReader& dataReader, off_t size) { // add short data inline if (size <= B_HPKG_MAX_INLINE_DATA_SIZE) { uint8 buffer[B_HPKG_MAX_INLINE_DATA_SIZE]; status_t error = dataReader.ReadData(0, buffer, size); if (error != B_OK) { fprintf(stderr, "Error: Failed to read data: %s\n", strerror(error)); return error; } _AddDataAttribute(B_HPKG_ATTRIBUTE_NAME_DATA, size, buffer); return B_OK; } // longer data -- try to compress uint64 dataOffset = fHeapEnd; uint64 compression = B_HPKG_COMPRESSION_NONE; uint64 compressedSize; status_t error = _WriteZlibCompressedData(dataReader, size, dataOffset, compressedSize); if (error == B_OK) { compression = B_HPKG_COMPRESSION_ZLIB; } else { error = _WriteUncompressedData(dataReader, size, dataOffset); compressedSize = size; } if (error != B_OK) return error; fHeapEnd = dataOffset + compressedSize; // add data attribute Attribute* dataAttribute = _AddDataAttribute(B_HPKG_ATTRIBUTE_NAME_DATA, compressedSize, dataOffset - fHeapOffset); Stacker<Attribute> attributeAttributeStacker(fTopAttribute, dataAttribute); // if compressed, add compression attributes if (compression != B_HPKG_COMPRESSION_NONE) { _AddAttribute(B_HPKG_ATTRIBUTE_NAME_DATA_COMPRESSION, compression); _AddAttribute(B_HPKG_ATTRIBUTE_NAME_DATA_SIZE, (uint64)size); // uncompressed size } return B_OK; }
void CSG_Doc_SVG::_AddAttribute(const SG_Char *Attribute, double dValue) { _AddAttribute(Attribute, SG_Get_String(dValue, 2)); }
inline PackageWriter::Attribute* PackageWriter::_AddAttribute(const char* attributeName, Type value) { AttributeValue attributeValue; attributeValue.SetTo(value); return _AddAttribute(attributeName, attributeValue); }
PackageWriter::Attribute* PackageWriter::_AddStringAttribute(const char* attributeName, const char* value) { AttributeValue attributeValue; attributeValue.SetTo(_GetCachedString(value)); return _AddAttribute(attributeName, attributeValue); }
PackageWriter::Attribute* PackageWriter::_AddDataAttribute(const char* attributeName, uint64 dataSize, const uint8* data) { AttributeValue attributeValue; attributeValue.SetToData(dataSize, data); return _AddAttribute(attributeName, attributeValue); }
void CSG_Doc_SVG::Draw_LinkedCircle(double x, double y, double Radius, const SG_Char *Link, int Fill_Color, int Line_Color, double Line_Width) { CSG_String sWidth; CSG_String sLink; m_sSVGCode.Append(SG_T("<circle ")); _AddAttribute(SG_T("cx"), x); _AddAttribute(SG_T("cy"), y); _AddAttribute(SG_T("r"), Radius); sWidth.Append(SG_Get_String(Line_Width,2)); sWidth.Append(g_Unit); _AddAttribute(SG_T("stroke-width"), sWidth); _AddAttribute(SG_T("stroke"), _Get_SVGColor(Line_Color)); _AddAttribute(SG_T("fill"), _Get_SVGColor(Fill_Color)); sLink = SG_T("window.open('"); sLink.Append(Link); sLink.Append(SG_T("')")); _AddAttribute(SG_T("onclick"), sLink); m_sSVGCode.Append(SG_T("/>\n")); }
void CSG_Doc_SVG::Draw_Text(double x, double y, const SG_Char *Text, int Color, const SG_Char* Font, double dSize, TSG_SVG_Alignment iAlignment) { CSG_String sAlignments[] = {SG_T(""), SG_T("middle"), SG_T("end")}; CSG_String sSize; sSize.Append(SG_Get_String(dSize,2)); sSize.Append(g_Unit); m_sSVGCode.Append(SG_T("<text ")); _AddAttribute(SG_T("x"), x); _AddAttribute(SG_T("y"), y); _AddAttribute(SG_T("font-family"), Font); _AddAttribute(SG_T("fill"), _Get_SVGColor(Color)); _AddAttribute(SG_T("font-size"), sSize); _AddAttribute(SG_T("text-anchor"), sAlignments[iAlignment]); m_sSVGCode.Append(SG_T(">\n")); m_sSVGCode.Append(Text); m_sSVGCode.Append(SG_T("</text>")); }
void CSG_Doc_SVG::Draw_Line(double xa, double ya, double xb, double yb, double Width, int Color) { CSG_String sWidth; m_sSVGCode.Append(SG_T("<line ")); _AddAttribute(SG_T("x1"), xa); _AddAttribute(SG_T("x2"), xb); _AddAttribute(SG_T("y1"), ya); _AddAttribute(SG_T("y2"), yb); sWidth.Append(SG_Get_String(Width,2)); sWidth.Append(g_Unit); _AddAttribute(SG_T("stroke-width"), sWidth); _AddAttribute(SG_T("stroke"), _Get_SVGColor(Color)); m_sSVGCode.Append(SG_T("/>\n")); }
void CSG_Doc_SVG::Draw_Circle(double x, double y, double Radius, int Fill_Color, int Line_Color, double Line_Width) { CSG_String sWidth; m_sSVGCode.Append(SG_T("<circle ")); _AddAttribute(SG_T("cx"), x); _AddAttribute(SG_T("cy"), y); _AddAttribute(SG_T("r"), Radius); sWidth.Append(SG_Get_String(Line_Width,2)); sWidth.Append(g_Unit); _AddAttribute(SG_T("stroke-width"), sWidth); _AddAttribute(SG_T("stroke"), _Get_SVGColor(Line_Color)); _AddAttribute(SG_T("fill"), _Get_SVGColor(Fill_Color)); m_sSVGCode.Append(SG_T("/>\n")); }
void CSG_Doc_SVG::_AddAttribute(const SG_Char *Attribute, int iValue) { _AddAttribute(Attribute, SG_Get_String(iValue, 0)); }
void PackageWriter::_AddEntry(int dirFD, Entry* entry, const char* fileName) { printf("PackageWriter::_AddEntry(%d, %p, \"%s\")\n", dirFD, entry, fileName); bool isImplicitEntry = entry != NULL && entry->IsImplicit(); // open the node int fd = openat(dirFD, fileName, O_RDONLY | (isImplicitEntry ? 0 : O_NOTRAVERSE)); if (fd < 0) { fprintf(stderr, "Error: Failed to open entry \"%s\": %s\n", fileName, strerror(errno)); throw status_t(errno); } FDCloser fdCloser(fd); // stat the node struct stat st; if (fstat(fd, &st) < 0) { fprintf(stderr, "Error: Failed to fstat() file \"%s\": %s\n", fileName, strerror(errno)); throw status_t(errno); } // implicit entries must be directories if (isImplicitEntry && !S_ISDIR(st.st_mode)) { fprintf(stderr, "Error: Non-leaf path component \"%s\" is not a " "directory\n", fileName); throw status_t(B_BAD_VALUE); } // check/translate the node type uint8 fileType; uint32 defaultPermissions; if (S_ISREG(st.st_mode)) { fileType = B_HPKG_FILE_TYPE_FILE; defaultPermissions = B_HPKG_DEFAULT_FILE_PERMISSIONS; } else if (S_ISLNK(st.st_mode)) { fileType = B_HPKG_FILE_TYPE_SYMLINK; defaultPermissions = B_HPKG_DEFAULT_SYMLINK_PERMISSIONS; } else if (S_ISDIR(st.st_mode)) { fileType = B_HPKG_FILE_TYPE_DIRECTORY; defaultPermissions = B_HPKG_DEFAULT_DIRECTORY_PERMISSIONS; } else { // unsupported node type fprintf(stderr, "Error: Unsupported node type, entry: \"%s\"\n", fileName); throw status_t(B_UNSUPPORTED); } // add attribute entry Attribute* entryAttribute = _AddStringAttribute( B_HPKG_ATTRIBUTE_NAME_DIRECTORY_ENTRY, fileName); Stacker<Attribute> entryAttributeStacker(fTopAttribute, entryAttribute); // add stat data if (fileType != B_HPKG_DEFAULT_FILE_TYPE) _AddAttribute(B_HPKG_ATTRIBUTE_NAME_FILE_TYPE, fileType); if (defaultPermissions != uint32(st.st_mode & ALLPERMS)) { _AddAttribute(B_HPKG_ATTRIBUTE_NAME_FILE_PERMISSIONS, uint32(st.st_mode & ALLPERMS)); } _AddAttribute(B_HPKG_ATTRIBUTE_NAME_FILE_ATIME, uint32(st.st_atime)); _AddAttribute(B_HPKG_ATTRIBUTE_NAME_FILE_MTIME, uint32(st.st_mtime)); _AddAttribute(B_HPKG_ATTRIBUTE_NAME_FILE_CRTIME, uint32(st.st_crtime)); // TODO: File user/group! // add file data/symlink path if (S_ISREG(st.st_mode)) { // regular file -- add data if (st.st_size > 0) { FDDataReader dataReader(fd); status_t error = _AddData(dataReader, st.st_size); if (error != B_OK) throw status_t(error); } } else if (S_ISLNK(st.st_mode)) { // symlink -- add link address char path[B_PATH_NAME_LENGTH + 1]; ssize_t bytesRead = readlinkat(dirFD, fileName, path, B_PATH_NAME_LENGTH); if (bytesRead < 0) { fprintf(stderr, "Error: Failed to read symlink \"%s\": %s\n", fileName, strerror(errno)); throw status_t(errno); } path[bytesRead] = '\0'; _AddStringAttribute(B_HPKG_ATTRIBUTE_NAME_SYMLINK_PATH, path); } // add attributes if (DIR* attrDir = fs_fopen_attr_dir(fd)) { CObjectDeleter<DIR, int> attrDirCloser(attrDir, fs_close_attr_dir); while (dirent* entry = readdir(attrDir)) { attr_info attrInfo; if (fs_stat_attr(fd, entry->d_name, &attrInfo) < 0) { fprintf(stderr, "Error: Failed to stat attribute \"%s\" of " "file \"%s\": %s\n", entry->d_name, fileName, strerror(errno)); throw status_t(errno); } // create attribute entry Attribute* attributeAttribute = _AddStringAttribute( B_HPKG_ATTRIBUTE_NAME_FILE_ATTRIBUTE, entry->d_name); Stacker<Attribute> attributeAttributeStacker(fTopAttribute, attributeAttribute); // add type _AddAttribute(B_HPKG_ATTRIBUTE_NAME_FILE_ATTRIBUTE_TYPE, (uint32)attrInfo.type); // add data AttributeDataReader dataReader(fd, entry->d_name, attrInfo.type); status_t error = _AddData(dataReader, attrInfo.size); if (error != B_OK) throw status_t(error); } } if (S_ISDIR(st.st_mode)) { // directory -- recursively add children if (isImplicitEntry) { // this is an implicit entry -- just add it's children for (EntryList::ConstIterator it = entry->ChildIterator(); Entry* child = it.Next();) { _AddEntry(fd, child, child->Name()); } } else { // we need to clone the directory FD for fdopendir() int clonedFD = dup(fd); if (clonedFD < 0) { fprintf(stderr, "Error: Failed to dup() directory FD: %s\n", strerror(errno)); throw status_t(errno); } DIR* dir = fdopendir(clonedFD); if (dir == NULL) { fprintf(stderr, "Error: Failed to open directory \"%s\": %s\n", fileName, strerror(errno)); close(clonedFD); throw status_t(errno); } CObjectDeleter<DIR, int> dirCloser(dir, closedir); while (dirent* entry = readdir(dir)) { // skip "." and ".." if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) { continue; } _AddEntry(fd, NULL, entry->d_name); } } } }