From c6bca1ff756c24deb56de264353affa428d7e1d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9A=E6=98=8E?= Date: Sat, 6 Jul 2024 14:16:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DRichEditor=E7=9A=84GetLineMet?= =?UTF-8?q?rics=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 姚明 --- .../jsview/js_layout_manager.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_layout_manager.cpp b/frameworks/bridge/declarative_frontend/jsview/js_layout_manager.cpp index ef065e32bc1..1e962af74b1 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_layout_manager.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_layout_manager.cpp @@ -36,9 +36,19 @@ void JSLayoutManager::GetLineMetrics(const JSCallbackInfo& args) { auto layoutInfoInterface = layoutInfoInterface_.Upgrade(); CHECK_NULL_VOID(layoutInfoInterface); - int32_t lineNumber = 0; - JSViewAbstract::ParseJsInteger(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(static_cast(lineIndex))) { + return; + } + int32_t lineIndex = 0; + JSViewAbstract::ParseJsInteger(args[0], lineIndex); + if (lineIndex < 0 || lineIndex >= layoutInfoInterface->GetLineCount()) { + return; + } + auto lineMetrics = layoutInfoInterface->GetLineMetrics(lineIndex); JSRef lineMetricsObj = JSRef::New(); CreateJSLineMetrics(lineMetricsObj, lineMetrics); args.SetReturnValue(JSRef::Cast(lineMetricsObj));