!37112 修复RichEditor的GetLineMetrics异常

Merge pull request !37112 from 姚明/REInterfaceBug
This commit is contained in:
openharmony_ci 2024-07-07 04:48:47 +00:00 committed by Gitee
commit 058035cdae
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -36,9 +36,19 @@ void JSLayoutManager::GetLineMetrics(const JSCallbackInfo& args)
{
auto layoutInfoInterface = layoutInfoInterface_.Upgrade();
CHECK_NULL_VOID(layoutInfoInterface);
int32_t lineNumber = 0;
JSViewAbstract::ParseJsInteger<int32_t>(args[0], lineNumber);
auto lineMetrics = layoutInfoInterface->GetLineMetrics(lineNumber);
if (args.Length() < 1 || args[0]->IsUndefined() || args[0]->IsNull() || !args[0]->IsNumber()) {
return;
}
if (double lineIndex = 0.0; !JSContainerBase::ParseJsDouble(args[0], lineIndex)
|| lineIndex != static_cast<double>(static_cast<int>(lineIndex))) {
return;
}
int32_t lineIndex = 0;
JSViewAbstract::ParseJsInteger<int32_t>(args[0], lineIndex);
if (lineIndex < 0 || lineIndex >= layoutInfoInterface->GetLineCount()) {
return;
}
auto lineMetrics = layoutInfoInterface->GetLineMetrics(lineIndex);
JSRef<JSObject> lineMetricsObj = JSRef<JSObject>::New();
CreateJSLineMetrics(lineMetricsObj, lineMetrics);
args.SetReturnValue(JSRef<JSVal>::Cast(lineMetricsObj));