/*****************************************************************************/ // stxtinfo // Written by Michael Wilber, Haiku Translation Kit Team // // Version: // // stxtinfo is a command line program for displaying text information about // Be styled text (the format that StyledEdit uses). StyledEdit stores the // styled text information as an attribute of the file and it is this // information that this program is concerned with. This format is outlined // in TranslatorFormats.h. // // This program prints out information from the "styles" attribute that // StyledEdit uses. If that information is not available, it attempts // to read the styles information from the contents of the file, assuming // that it is the format that BTranslationUtils::PutStyledText() writes // out. // // The intention of this program is to aid with the development and // debugging of the STXTTranslator. It may also be useful for debugging / // testing StyledEdit. // // This application and all source files used in its construction, except // where noted, are licensed under the MIT License, and have been written // and are: // // Copyright (c) 2003 Haiku Project // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. /*****************************************************************************/ #include #include #include #include #include #include #include // for B_UNICODE_UTF8 #include // for attr_info #define max(x,y) ((x > y) ? x : y) #define DATA_BUFFER_SIZE 64 struct StylesHeader { uint32 magic; // 41 6c 69 21 uint32 version; // 0 int32 count; }; struct Style { int32 offset; char family[64]; char style[64]; float size; float shear; // typically 90.0 uint16 face; // typically 0 uint8 red; uint8 green; uint8 blue; uint8 alpha; // 255 == opaque uint16 reserved; // 0 }; void PrintStyle(Style &style, int32 i) { style.offset = B_BENDIAN_TO_HOST_INT32(style.offset); style.size = B_BENDIAN_TO_HOST_FLOAT(style.size); style.shear = B_BENDIAN_TO_HOST_FLOAT(style.shear); style.face = B_BENDIAN_TO_HOST_INT16(style.face); style.reserved = B_BENDIAN_TO_HOST_INT16(style.reserved); printf("\nStyle %d:\n", static_cast(i + 1)); printf("offset: %d\n", static_cast(style.offset)); printf("family: %s\n", style.family); printf("style: %s\n", style.style); printf("size: %f\n", style.size); printf("shear: %f (typically 90.0)\n", style.shear); printf("face: %u (typically 0)\n", static_cast(style.face)); printf("RGBA: (%u, %u, %u, %u)\n", static_cast(style.red), static_cast(style.blue), static_cast(style.green), static_cast(style.alpha)); printf("reserved: %u (should be 0)\n", static_cast(style.reserved)); } bool PrintStylesAttribute(BFile &file) { const char *kAttrName = "styles"; attr_info info; if (file.GetAttrInfo(kAttrName, &info) != B_OK) return false; if (info.type != B_RAW_TYPE) { printf("Error: styles attribute is of the wrong type\n"); return false; } if (info.size < 160) { printf("Error: styles attribute is missing information\n"); return false; } uint8 *pflatRunArray = new uint8[info.size]; if (!pflatRunArray) { printf("Error: Not enough memory available to read styles attribute\n"); return false; } ssize_t amtread = file.ReadAttr(kAttrName, B_RAW_TYPE, 0, pflatRunArray, info.size); if (amtread != info.size) { printf("Error: Unable to read styles attribute\n"); return false; } // Check Styles StylesHeader stylesheader; memcpy(&stylesheader, pflatRunArray, sizeof(StylesHeader)); if (swap_data(B_UINT32_TYPE, &stylesheader, sizeof(StylesHeader), B_SWAP_BENDIAN_TO_HOST) != B_OK) { printf("Error: Unable to swap byte order of styles header\n"); return false; } // Print StylesHeader info printf("\"styles\" attribute data:\n\n"); printf("magic number: 0x%.8lx ", static_cast(stylesheader.magic)); if (stylesheader.magic == 'Ali!') printf("(valid)\n"); else printf("(INVALID, should be 0x%.8lx)\n", static_cast('Ali!')); printf("version: 0x%.8lx ", static_cast(stylesheader.version)); if (stylesheader.version == 0) printf("(valid)\n"); else printf("(INVALID, should be 0x%.8lx)\n", 0UL); printf("number of styles: %d\n", static_cast(stylesheader.count)); // Check and Print out each style Style *pstyle = reinterpret_cast