文本内容区域

操作系统: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)

@101ppt,
感谢您联系支持。

这似乎不是有问题的演示文稿。请检查附件。如果您可以隔离问题并分享最简单的可编译代码示例而不是上面的示例,那就太好了。

可运行visual studio工程:
[removed by moderator] (4.5 MB)
由于库文件较大,麻烦把aspose-slides-cpp-windows-22.8解压到AsposeParserDemo/aspose目录下。
谢谢!

@101ppt,
不幸的是,我无法运行该项目。 请尽可能简化代码并更详细地描述问题。 也请不要在论坛上分享您的许可证数据。 我已经删除了你的附件。

允许标点溢出边界.zip (57.5 KB)

void PrintText(System::String pptFilePath)
{
   System::SharedPtr<System::IO::FileStream> stream = System::MakeObject<System::IO::FileStream>(pptFilePath, System::IO::FileMode::Open, System::IO::FileAccess::Read, System::IO::FileShare::ReadWrite);
   System::SharedPtr<Aspose::Slides::Presentation> presentation = System::MakeObject<Aspose::Slides::Presentation>(stream);

   System::SharedPtr<IShapeCollection> shapes = presentation->get_Slides()->idx_get(0)->get_Shapes();
   for (int i = 0, n = shapes->get_Count(); i < n; i++)
   {
   	System::SharedPtr<IShape> shape = shapes->idx_get(i);
   	if (!System::ObjectExt::Is<IAutoShape>(shape))
   	{
   		continue;
   	}
   	auto autoShape = System::DynamicCast_noexcept<IAutoShape>(shape);

   	System::SharedPtr<Aspose::Slides::ITextFrame> textFrame = autoShape->get_TextFrame();
   	System::SharedPtr<Aspose::Slides::IParagraphCollection> paragraphCollection = textFrame->get_Paragraphs();
   	for (int paragraphIndex = 0, paragraphCount = paragraphCollection->get_Count(); paragraphIndex < paragraphCount; paragraphIndex++)
   	{
   		System::SharedPtr<Aspose::Slides::IParagraph> paragraph = paragraphCollection->idx_get(paragraphIndex);
   		System::String paragraphText = paragraph->get_Text();
   		System::Drawing::RectangleF paragraphRect = paragraph->GetRect();

   		System::Console::WriteLine(u"rect:({0},{1},{2},{3}), text:{4}", paragraphRect.get_X(), paragraphRect.get_Y(), paragraphRect.get_Width(), paragraphRect.get_Height(), paragraphText);
   	}
   }
}

Power Point的"段落"->“允许标点溢出边界”打√后,标点在行末溢出了,此时文本内容是在同一行的,而通过下面的代码输出:
rect:(7.200012,3.600006,462,158.4), text:ABCDEFGHIJKLMN?
rect:(7.200012,3.600006,462,79.2), text:ABCDEFGHIJKLMN
这里可看出上面的一个文本框是2行显示了,而与Power Point的显示有差异

@101ppt,
感谢您提供代码示例和演示文件。我已经重现了段落高度的问题,并在我们的问题跟踪系统中添加了 ID 为 SLIDESCPP-3557 的票证。 很抱歉给您带来不便。 我们的开发团队将调查此案。 问题解决后会通知您。

A post was split to a new topic: get_Text耗时超过20秒甚至更长的时间

The issues you found earlier (filed as SLIDESCPP-3557) have been fixed in Aspose.Slides for C++ 22.12 (Windows, Linux, macOS).
You can check all fixes on the Release Notes page.
You can also find the latest version of our library on the Product Download page.