Help with the code examples, I have not found any normal documentation and examples for the library. I managed to get the plain text, but I do not know how to get it from the blocks. I also tried to find other libraries, but they don’t compile for visual studio 2022. Here is my code that reads the text:
int DWGTextLoader::loadFile(const std::string& filename)
{
text.clear();
this->filename = utf8_decode(filename);
Dwg_Data dwg;
memset(&dwg, 0, sizeof(Dwg_Data));
int success = dwg_read_file(filename.c_str(), &dwg);
if (!(success < DWG_ERR_CRITICAL)) {
printer->printError(L"Wrong file!");
return success;
}
char* text_value{ nullptr };
int found{ 0 };
int isnew{ 0 };
std::wstring text2;
for (BITCODE_BL i = 0; i < dwg.num_objects; i++)
{
if (dwg.object[i].type == DWG_TYPE_TEXT)
{
Dwg_Entity_TEXT* _obj = dwg.object[i].tio.entity->tio.TEXT;
found++;
dwg_dynapi_entity_utf8text(_obj, "TEXT", "text_value", &text_value, &isnew, NULL);
text.append(separator + utf8_decode(text_value));
}
}
if (!found) {
printer->printError(L"Text not found!");
return 0;
}
dwg_free(&dwg);
return success;
}
std::wstring utf8_decode(const std::string& text)
{
if (text[0] == 0)
return std::wstring();
int size_needed = ::MultiByteToWideChar(CP_UTF8, 0, text.c_str(),
static_cast<int>(text.size()), NULL, 0);
assert(size_needed > 0);
const size_t cnt = static_cast<size_t>(size_needed);
std::wstring wstrTo(cnt, 0);
MultiByteToWideChar(CP_UTF8, 0, text.c_str(),
static_cast<int>(text.size()), &wstrTo[0], size_needed);
return wstrTo;
}