From patchwork Mon Sep 11 14:48:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Francesco Carusi X-Patchwork-Id: 43694 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4e27:b0:149:dfde:5c0a with SMTP id gk39csp2188796pzb; Mon, 11 Sep 2023 07:48:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE7hrbSJ4bt6kXa1R7S+t5gmi0Xr/DCJpWeLS0UELkpS4UNn1UbaTB0Ht6U7NHLmliAC5Jy X-Received: by 2002:aa7:d44b:0:b0:525:734a:bf30 with SMTP id q11-20020aa7d44b000000b00525734abf30mr8183457edr.36.1694443715439; Mon, 11 Sep 2023 07:48:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694443715; cv=none; d=google.com; s=arc-20160816; b=JCOVA66s4VLBShswdtYwV41WC/IJMMUH/o/MH/WPZxLgNuKE4CNRAoaP6YW7Dszhfc 78u/vfaIa+0dISI0wM7lHWuqAhEB8qMIsFfREaHu1MyM3KQFvSLjbBTtAbpWzzKF3pDv IK2IIr0hWCyse3ZVaQucr66Fz/LBN+ru2TVRKPlGRNP0FIuxNLuYnkerF69Nhih8AxBW 3hw5nLVjT0PRbSinzk23hJNK7eZ2R7H9Sw/pteAZaf+aEw5MHnX0tYcQvq33t1CfLbhX JM4hAnxzuSi+MtJ9rOXD62cncdwSH+uMPFetHhuhULBwEpOjkEoz7H5QdvKzZp1ywszA IVVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :dkim-signature:in-reply-to:from:to:content-language:references :user-agent:mime-version:date:message-id:delivered-to; bh=jwaoInYWTlRqNfhhsO1Vj7WVX0MEIyeq2IywBwoIO0U=; fh=vgcpdHWu4da4Dk/quIxpjcmmxLeEWfPnCXzoiCPpQLU=; b=TiSZIT+w2C49WuxgYqAdakcQiv6IMLO00CJ5ztHS3+QcdBxP/S4Pco2m6RSZ1AOhKd JKNTxlIiq9fVdAQPQARWL5v+g27alPvyVqqGmEHJXPs90RDbwWQ4b3cI4T58PB6bU+vJ 3ZDhiMvTn/O23xL+29LGfD9HjzTyUjRqoYJicVH1H6dwPobJKZR9OTFOW17cYXqOUNEA JgrgDkB5MnApXh4uFLRoNDZ7HyLhOU16JuJvbIl0aGtHpkF9HorXo5H2YnX5GaafCJr6 9ivs0fd//U2Dia0hLpxgRRcpiIq//VoJ5J0xJ2V+Vh9AbRb0mPmU2/Y0QCk9zsEjICGf 3kQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@tiscali.it header.s=smtp header.b=pVOeTY9a; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=tiscali.it Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id u5-20020a056402110500b00523372ace05si6632612edv.530.2023.09.11.07.48.34; Mon, 11 Sep 2023 07:48:35 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@tiscali.it header.s=smtp header.b=pVOeTY9a; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=tiscali.it Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1440568C92F; Mon, 11 Sep 2023 17:48:30 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtp.tiscali.it (santino-notr.mail.tiscali.it [213.205.33.215]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7ECF668C772 for ; Mon, 11 Sep 2023 17:48:22 +0300 (EEST) Received: from [192.168.20.100] ([95.243.137.154]) by santino.mail.tiscali.it with id keoH2A01S3L3PKz01eoJft; Mon, 11 Sep 2023 14:48:21 +0000 X-Spam-Final-Verdict: clean X-Spam-State: 0 X-Spam-Score: 0 X-Spam-Verdict: clean x-auth-user: klimklim@tiscali.it Message-ID: <7fc3d15e-ab08-8e7b-cd68-2308e548906d@tiscali.it> Date: Mon, 11 Sep 2023 16:48:17 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.0 References: Content-Language: it To: ffmpeg-devel From: Francesco Carusi In-Reply-To: X-Forwarded-Message-Id: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tiscali.it; s=smtp; t=1694443701; bh=9tIRt1O9xKgf7owWNvumK10hsJB7xdSBPBvKrUNBLCg=; h=Date:Subject:References:To:From:In-Reply-To; b=pVOeTY9aEbwuu/VaYg8WYUAsVVLd9fy4bR/NLsCuVS4GB21giwOn3YgJkLHpvXSav QeOFM+SizXxMEHZr5HHLHXKmoFS21fMItKpZL3plj4QPs3PRIV6BJWjINxMOvH2QRO 8iRQkOsCFcoPh9sKP+7GgBaB5V2//esoNL3L85b0= Subject: [FFmpeg-devel] fix for defect #10531 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: gSye9e+KW7HR I attached a patch for defect [ #10531: vf_drawtext causing font rendering jitter after libharfbuz commit. ] Before the patch the width of a text line was measured up to the rightmost visible pixel of the last character. Pros: the right padding specified with the boxborderw parameter is exact with respect to the visible text Cons: the width of a text line depends on the last character, even with monospaced fonts After the patch the width of the last character is set equal to the width specified in the font file, which may include some empty space. Pros: when using monospaced fonts the width of a line depends only on the number of characters, this is also the standard behavior adopted by other rendering strategies, e.g. in browsers Cons: the user specified right padding may not be equal to the distance between the background box right border and the rightmost visible pixel of the text. From 62ccf3fc27f2a7df7b79a6241aae2e8d7fd8058d Mon Sep 17 00:00:00 2001 From: yethie Date: Thu, 7 Sep 2023 18:39:25 +0200 Subject: [PATCH 1/1] text width measurement fixed --- libavfilter/vf_drawtext.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index ec8d215795..9e5f013c09 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -1757,9 +1757,17 @@ continue_on_failed2: first_min_x64 = FFMIN(glyph->bbox.xMin, first_min_x64); } if (t == hb->glyph_count - 1) { - w64 += glyph->bbox.xMax; - last_max_x64 = FFMAX(glyph->bbox.xMax, last_max_x64); - cur_line->offset_right64 = glyph->bbox.xMax; + // The following code measures the width of the line up to the last + // character's horizontal advance + int last_char_width = hb->glyph_pos[t].x_advance; + + // The following code measures the width of the line up to the rightmost + // visible pixel of the last character + // int last_char_width = glyph->bbox.xMax; + + w64 += last_char_width; + last_max_x64 = FFMAX(last_char_width, last_max_x64); + cur_line->offset_right64 = last_char_width; } else { if (is_tab) { int size = s->blank_advance64 * s->tabsize;