Skip to main content
Legend
Dec 23, 2025 12:40 AM UTC
Answered

C++SDK About IWaxStrand::GetTextIndexToWaxLineData

IWaxStrand::GetTextIndexToWaxLineData is being used to obtain coordinates.
It seems to work fine, but when tables with two or more rows exist, it doesn't seem to work properly. Is this a bug?

do
{
	// -------------------------------------------------------------
	// Query Index
	// iScript : InsertionPointObjectScriptElement
	ScriptObject scriptObject = iScript->GetScriptObject(iScriptRequestData->GetRequestContext());
	ScriptData scriptData = scriptObject.specifierData;

	int32 int32_TargetIndex;
	scriptData.GetInt32(&int32_TargetIndex);

	// -------------------------------------------------------------
	// Query IWaxStrand
	InterfacePtr<ITextModel> iTextModel((ITextModel*)iScript->QueryParent(
		IID_ITEXTMODEL,
		iScriptRequestData->GetRequestContext()
	));
	if (!iTextModel) break;

	InterfacePtr<IWaxStrand> iWaxStrand(((IWaxStrand*)iTextModel->QueryStrand(kFrameListBoss, IID_IWAXSTRAND)));
	if (!iWaxStrand) break;
	
	// -------------------------------------------------------------
	// Recompose
	InterfacePtr<IFrameList> iFrameList(iWaxStrand, ::UseDefaultIID());
	if (!iFrameList) break;

	const int32 kNoDamage = -1;
	if (iFrameList->GetFirstDamagedFrameIndex() != kNoDamage) {
		// Recompose.
		InterfacePtr<IFrameListComposer> iFrameListComposer(iFrameList, UseDefaultIID());
		if (!iFrameListComposer) break;
		iFrameListComposer->RecomposeThruLastFrame();
	}

	// -------------------------------------------------------------
	// GetTextIndexToWaxLineData
	int32 int32_OffsetWithinLine;
	int32 int32_TextSpan;
	ParcelKey parcelKey;
	UID uID_Frame;
	PMReal pMReal_LineHeight;
	PMLineSeg pMLineSeg_Selection;
	PMPoint pMPoint_WaxPt;
	PMMatrix pMMatrix_WaxToFrameMatrix;
	PMMatrix pMMatrix_WaxToGlyphMatrix;
	bool16 result = iWaxStrand->GetTextIndexToWaxLineData(
		int32_TargetIndex,
		kFalse,
		&int32_OffsetWithinLine,
		&int32_TextSpan,
		&parcelKey,
		&uID_Frame,
		&pMReal_LineHeight,
		&pMLineSeg_Selection,
		&pMPoint_WaxPt,
		&pMMatrix_WaxToFrameMatrix,
		&pMMatrix_WaxToGlyphMatrix
	);

	// -------------------------------------------------------------
	// PointsToUnits
	InterfacePtr<IMeasurementSystem> iMeasurementSystem(::GetExecutionContextSession(), ::UseDefaultIID());
	InterfacePtr<IUnitOfMeasure> iUnitOfMeasure(iMeasurementSystem->QueryUnitOfMeasure(
		iMeasurementSystem->Location(kMillimetersBoss))
	);
	if (!iUnitOfMeasure) break;

	PMReal pMReal_mmValue = iUnitOfMeasure->PointsToUnits(pMPoint_WaxPt.X());

	PMString xCoordinate;
	xCoordinate.AsNumber(pMReal_mmValue);

	CAlert::InformationAlert(xCoordinate);

} while (false);

 

 

Modern AI is quite smart. When I asked it how to get character coordinates, it suggested the IWaxStrand::GetTextIndexToWaxLineData method. If it gives an incorrect answer, uploading the interface header seems to make it return much more accurate results.

琥珀 猫太郎Correct answer
Legend
Dec 24, 2025 6:47 AM UTC

The InsertionPoint's Index and the Story's TextIndex don't match, do they? It seems the text index increases by one each time a row is added to the table.
After adjusting that, it worked fine.

// Query TextCount of InsertionPointIndex
// Use value obtained by subtracting 1 from first argument of GetTextIndexToWaxLineData method.
int32 int32_TextCountForInsertionPointIndex = 0;

int32 int32_InsertionPointIndex = 0;
TextIterator textIterator_Begin(iTextModel, 0);
TextIterator textIterator_End(iTextModel, iTextModel->TotalLength());
for (TextIterator textIterator_iter = textIterator_Begin;
	textIterator_iter != textIterator_End;
	textIterator_iter++)
{
	int32_TextCountForInsertionPointIndex++;
	const UTF32TextChar uTF32TextChar_CharacterCode = *textIterator_iter;
	if (uTF32TextChar_CharacterCode == kTextChar_TableContinued) continue;
	if (int32_InsertionPointIndex == int32_TargetIndex) break;
	int32_InsertionPointIndex++;
}

 

Unable to retrieve the position of characters within the table; currently exploring possible solutions.

1 reply

琥珀 猫太郎AuthorCorrect answer
Legend
Dec 24, 2025 6:47 AM UTC

The InsertionPoint's Index and the Story's TextIndex don't match, do they? It seems the text index increases by one each time a row is added to the table.
After adjusting that, it worked fine.

// Query TextCount of InsertionPointIndex
// Use value obtained by subtracting 1 from first argument of GetTextIndexToWaxLineData method.
int32 int32_TextCountForInsertionPointIndex = 0;

int32 int32_InsertionPointIndex = 0;
TextIterator textIterator_Begin(iTextModel, 0);
TextIterator textIterator_End(iTextModel, iTextModel->TotalLength());
for (TextIterator textIterator_iter = textIterator_Begin;
	textIterator_iter != textIterator_End;
	textIterator_iter++)
{
	int32_TextCountForInsertionPointIndex++;
	const UTF32TextChar uTF32TextChar_CharacterCode = *textIterator_iter;
	if (uTF32TextChar_CharacterCode == kTextChar_TableContinued) continue;
	if (int32_InsertionPointIndex == int32_TargetIndex) break;
	int32_InsertionPointIndex++;
}

 

Unable to retrieve the position of characters within the table; currently exploring possible solutions.

Translate