操作系统:windows 10
使用版本:aspose-slides-cpp-windows-22.8
JsonObjectPtr GetTextFrame(System::SharedPtr<Aspose::Slides::ITextFrame> textFrame)
{
JsonObjectPtr jTextFrame = MakeJsonObject();
System::String text = textFrame->get_Text();
jTextFrame->put("text", GetSystemString(text).c_str());
auto jParagraphs = MakeJsonArray();
System::SharedPtr<Aspose::Slides::IParagraphCollection> paragraphCollection = textFrame->get_Paragraphs();
for (int paragraphIndex = 0, paragraphCount = paragraphCollection->get_Count(); paragraphIndex < paragraphCount; paragraphIndex++)
{
auto jParagraph = MakeJsonObject();
System::SharedPtr<Aspose::Slides::IParagraph> paragraph = paragraphCollection->idx_get(paragraphIndex);
System::String paragraphText = paragraph->get_Text();
jParagraph->put("text", GetSystemString(paragraphText).c_str());
System::Drawing::RectangleF paragraphRect = paragraph->GetRect();
auto jsonParagraphRect = MakeJsonObject();
jsonParagraphRect->put("x", paragraphRect.get_X());
jsonParagraphRect->put("y", paragraphRect.get_Y());
jsonParagraphRect->put("width", paragraphRect.get_Width());
jsonParagraphRect->put("height", paragraphRect.get_Height());
jParagraph->put("rect", jsonParagraphRect);
auto jTextPortionArray = MakeJsonArray();
System::SharedPtr<Aspose::Slides::IPortionCollection> portionCollection = paragraph->get_Portions();
for (int portionIndex = 0, portionCount = portionCollection->get_Count(); portionIndex < portionCount; portionIndex++)
{
System::SharedPtr<IPortion> portion = portionCollection->idx_get(portionIndex);
auto jPortion = MakeJsonObject();
System::Drawing::RectangleF portionRect = portion->GetRect();
auto jsonPortionRect = MakeJsonObject();
jsonPortionRect->put("x", portionRect.get_X());
jsonPortionRect->put("y", portionRect.get_Y());
jsonPortionRect->put("width", portionRect.get_Width());
jsonPortionRect->put("height", portionRect.get_Height());
jPortion->put("rect", jsonPortionRect);
System::Drawing::PointF coordinates = portion->GetCoordinates();
auto jsonCoordinates = MakeJsonObject();
jsonCoordinates->put("x", coordinates.get_X());
jsonCoordinates->put("y", coordinates.get_Y());
jPortion->put("coordinates", jsonCoordinates);
System::String portionsText = portion->get_Text();
jPortion->put("text", GetSystemString(portionsText).c_str());
jTextPortionArray->put(jPortion);
}
jParagraph->put("portions", jTextPortionArray);
jParagraphs->put(jParagraph);
}
jTextFrame->put("paragraphs", jParagraphs);
return jTextFrame;
}
使用上面的方式获取文本段落的RectangleF区域大小,在文本内容为:为什么说一队“红领巾”呢?与内容为:为什么说一队“红领巾”呢,2个内容差一个句末的问号(“?”)测量出来的文本宽度是一样的,这是bug吗?
test.zip (36.7 KB)