From patchwork Fri Jul 21 03:35:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: efren yang X-Patchwork-Id: 4405 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.1.76 with SMTP id 73csp387486vsb; Thu, 20 Jul 2017 20:35:34 -0700 (PDT) X-Received: by 10.223.160.139 with SMTP id m11mr6132101wrm.142.1500608134530; Thu, 20 Jul 2017 20:35:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500608134; cv=none; d=google.com; s=arc-20160816; b=jC0864e/qgWCW5YN1jX8SBTX/OWB0gX9uqdJDb62w/coSB2u/OlWQGQUDxbP6VPVc3 UQu9hQEsTPXYcHz7kH67ahpDeOU4Z8l87QtB1zkaiPvWegxagEi+Rg54K3UuWSFXmMCy VriiucQiT6619KX3i4c1+NNMsv0WaB77UANst/2RaWlc0Sgk63Jz2rvb1PGmZapJY8WK ugZ293+PrO/44Mt5yDsOw0g7ll2SkGsowqSdOMylXCez8QLicLo9Uhwbgs9jy2w6TBR3 1/j9bCXA9R87GTUJkQw+2AhdQ8M8uaTl2YMlXSaj97nFFe4Kg3nlf+064VXi6FOx1b75 sqew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:to:from:date :dkim-signature:delivered-to:arc-authentication-results; bh=Qq3GAFzzq+wDf5HDGeaypT4Jr+b/cpK1nsdXLNsK+Z0=; b=cGOMpIxbPFJ2pON+qDV7fnMQmktDtok5iEBoHZxnSqjJNnSFv1J/hy5FWkXXMzjQBU vtTYTjxWG60iFBkYttf6T3DBrFxqP9j9q0mf0zFH2z3Iq+J6I6zybT0A7gnmj8qu+3w/ npKFaLd3S3zwqdZfFbk+/+evaJTvPWoCTK+g6VWlXJRzQuMQdUx3vU76Zt2HXCoXyzTU zYeTtQkOgSfQAblemVuxvptN/oq956nc4gzBPDlDmbrFfmF/dS05ZZD+MgdeRLf90Nto 67y1FC3tvRgWlZ+gr+MwvNMEiBj9kp9IZgRLQrttyOBuZ690vkZX1PRtJJpLedwLkVjG OwGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@163.com header.b=QbUgw43l; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y60si3565549wrc.552.2017.07.20.20.35.30; Thu, 20 Jul 2017 20:35:34 -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=@163.com header.b=QbUgw43l; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3F3BB689BC3; Fri, 21 Jul 2017 06:35:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from m12-16.163.com (m12-16.163.com [220.181.12.16]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 109B0688337 for ; Fri, 21 Jul 2017 06:35:11 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=Date:From:Subject:Message-ID:MIME-Version; bh=hPhNj HOloYlfrl1RNVCCeTyLvQnmoOXx49ERnAzSmXE=; b=QbUgw43lLprRl2T37Pd2V 9s35nq1p3Lxwy1XAWAaXF5/1WYPxMpsetzZ1k0nC7NyiH7qXm0qaA/4wTAJkjsdp BdlXHN58obyLn8AFJjaiehnFrt7JkjXRMfwK2kKxIIbsnIAxnR/KRD1NRDAiyain guzJRovvU9NVb5mIeZBdl0= Received: from YW-A2526-D.local (unknown [101.227.12.253]) by smtp12 (Coremail) with SMTP id EMCowACn1WJ0dnFZeOlgNQ--.49473S2; Fri, 21 Jul 2017 11:35:16 +0800 (CST) Date: Fri, 21 Jul 2017 11:35:14 +0800 From: efren yang To: ffmpeg-devel@ffmpeg.org; Message-ID: X-Mailer: TortoiseGit MIME-Version: 1.0 X-CM-TRANSID: EMCowACn1WJ0dnFZeOlgNQ--.49473S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxGFW5XF4xAw17XrW3tryDGFg_yoW5ArWfpF 45Wan7Wwn7JF17ua4rA3WkX3W5uw1xXFy0k34rA3y7JFnYy3Z5Zw1akFy5Aw1kZr4xA3y3 ZrWY9F47twnrt3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jE9aPUUUUU= X-Originating-IP: [101.227.12.253] X-CM-SenderInfo: phiuv0xb1d0wi6rwjhhfrp/1tbiSBQcF1XljbadhQAAsE Subject: [FFmpeg-devel] [PATCH] libavfilter/vf_drawtext:support to set glyph spacing while drawing text. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Cc: , efren_yang@163.com Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" It is applied to every glyph. There is no space between all words in some languages, for example Chinese, Japanese and so on. So a sentence will look very compactly. I think if we could set glyph spacing, it will adapt to more different scenarios. Maybe it is simple but useful. ffmpeg -i input -vf drawtext="glyph_spacing=10:text="PROGRAMMING":fontfile=demo.ttf" -f flv 1.flv could set glyph spacing 10 pixel. Signed-off-by: efren yang --- doc/filters.texi | 4 ++++ libavfilter/vf_drawtext.c | 3 +++ 2 files changed, 7 insertions(+) diff --git a/doc/filters.texi b/doc/filters.texi index 119d1be69d..0f336f8826 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -7077,6 +7077,10 @@ The default value of @var{boxcolor} is "white". Set the line spacing in pixels of the border to be drawn around the box using @var{box}. The default value of @var{line_spacing} is 0. +@item glyph_spacing +Set the glyph spacing in pixels for drawing text. +The default value of @var{glyph_spacing} is 0. + @item borderw Set the width of the border to be drawn around the text using @var{bordercolor}. The default value of @var{borderw} is 0. diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index f6151443bb..152d8f35d5 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -162,6 +162,7 @@ typedef struct DrawTextContext { unsigned int default_fontsize; ///< default font size to use int line_spacing; ///< lines spacing in pixels + int glyph_spacing; ///< glyph spacing in pixels short int draw_box; ///< draw box around text - true or false int boxborderw; ///< box border width int use_kerning; ///< font kerning is used - true/false @@ -214,6 +215,7 @@ static const AVOption drawtext_options[]= { {"box", "set box", OFFSET(draw_box), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 , FLAGS}, {"boxborderw", "set box border width", OFFSET(boxborderw), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX , FLAGS}, {"line_spacing", "set line spacing in pixels", OFFSET(line_spacing), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX,FLAGS}, + {"glyph_spacing", "set glyph spacing in pixels", OFFSET(glyph_spacing), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX,FLAGS }, {"fontsize", "set font size", OFFSET(fontsize_expr), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX , FLAGS}, {"x", "set x expression", OFFSET(x_expr), AV_OPT_TYPE_STRING, {.str="0"}, CHAR_MIN, CHAR_MAX, FLAGS}, {"y", "set y expression", OFFSET(y_expr), AV_OPT_TYPE_STRING, {.str="0"}, CHAR_MIN, CHAR_MAX, FLAGS}, @@ -1374,6 +1376,7 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame, s->positions[i].y = y - glyph->bitmap_top + y_max; if (code == '\t') x = (x / s->tabsize + 1)*s->tabsize; else x += glyph->advance; + x += s->glyph_spacing; } max_text_line_w = FFMAX(x, max_text_line_w);