/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// #i55341# for some fonts it is not a good idea to calculate // their text line metrics from the real font descent // => work around this problem just for these fonts if( 3*nDescent > mnAscent )
nDescent = mnAscent / 3;
// Don't assume that wavelines are never placed below the descent, because for most fonts the waveline // is drawn into the text
mnWUnderlineOffset = nUnderlineOffset;
tools::Long nIntLeading = mnIntLeading; // TODO: assess usage of nLeading below (changed in extleading CWS) // if no leading is available, we assume 15% of the ascent if ( nIntLeading <= 0 )
{
nIntLeading = mnAscent*15/100; if ( !nIntLeading )
nIntLeading = 1;
}
void FontMetricData::ImplInitFlags( const OutputDevice* pDev )
{ const vcl::Font& rFont ( pDev->GetFont() ); bool bCentered = true; if (MsLangId::isCJK(rFont.GetLanguage()))
{
tools::Rectangle aRect;
pDev->GetTextBoundRect( aRect, u"\x3001"_ustr ); // Fullwidth fullstop constauto nH = rFont.GetFontSize().Height(); constauto nB = aRect.Left(); // Use 18.75% as a threshold to define a centered fullwidth fullstop. // In general, nB/nH < 5% for most Japanese fonts.
bCentered = nB > (((nH >> 1)+nH)>>3);
}
SetFullstopCenteredFlag( bCentered );
}
bool FontMetricData::ShouldUseWinMetrics(int nAscent, int nDescent, int nTypoAscent, int nTypoDescent, int nWinAscent, int nWinDescent) const
{ if (comphelper::IsFuzzing()) returnfalse;
// These are “private” HarfBuzz metrics tags, they are supported by not exposed // in the public header. They are safe to use, HarfBuzz just does not want to // advertise them.
constexpr auto ASCENT_OS2 = static_cast<hb_ot_metrics_tag_t>(HB_TAG('O', 'a', 's', 'c'));
constexpr auto DESCENT_OS2 = static_cast<hb_ot_metrics_tag_t>(HB_TAG('O', 'd', 's', 'c'));
constexpr auto LINEGAP_OS2 = static_cast<hb_ot_metrics_tag_t>(HB_TAG('O', 'l', 'g', 'p'));
constexpr auto ASCENT_HHEA = static_cast<hb_ot_metrics_tag_t>(HB_TAG('H', 'a', 's', 'c'));
constexpr auto DESCENT_HHEA = static_cast<hb_ot_metrics_tag_t>(HB_TAG('H', 'd', 's', 'c'));
constexpr auto LINEGAP_HHEA = static_cast<hb_ot_metrics_tag_t>(HB_TAG('H', 'l', 'g', 'p'));
auto aFvar(pFace->GetRawFontData(HB_TAG('f', 'v', 'a', 'r'))); if (!aFvar.empty())
{ // This is a variable font, trust HarfBuzz to give us the right metrics // and apply variations to them.
hb_position_t nAscent, nDescent, nLineGap; if (hb_ot_metrics_get_position(pHbFont, HB_OT_METRICS_TAG_HORIZONTAL_ASCENDER, &nAscent)
&& hb_ot_metrics_get_position(pHbFont, HB_OT_METRICS_TAG_HORIZONTAL_DESCENDER,
&nDescent)
&& hb_ot_metrics_get_position(pHbFont, HB_OT_METRICS_TAG_HORIZONTAL_LINE_GAP,
&nLineGap))
{
fAscent = nAscent * fScale;
fDescent = -nDescent * fScale;
fExtLeading = nLineGap * fScale;
}
} else
{ // This is not a variable font, we try to choose the best metrics // ourselves for backward comparability: // // - hhea metrics should be used, since hhea is a mandatory font table // and should always be present. // - But if OS/2 is present, it should be used since it is mandatory in // Windows. // OS/2 has Typo and Win metrics, but the later was meant to control // text clipping not line spacing and can be ridiculously large. // Unfortunately many Windows application incorrectly use the Win // metrics (thanks to GDI’s TEXTMETRIC) and old fonts might be // designed with this in mind, so OpenType introduced a flag for // fonts to indicate that they really want to use Typo metrics. So // for best backward compatibility: // - Use Win metrics if available. // - Unless USE_TYPO_METRICS flag is set, in which case use Typo // metrics.
// Try hhea table first.
hb_position_t nAscent = 0, nDescent = 0, nLineGap = 0; if (hb_ot_metrics_get_position(pHbFont, ASCENT_HHEA, &nAscent)
&& hb_ot_metrics_get_position(pHbFont, DESCENT_HHEA, &nDescent)
&& hb_ot_metrics_get_position(pHbFont, LINEGAP_HHEA, &nLineGap))
{ // tdf#107605: Some fonts have weird values here, so check that // ascender is +ve and descender is -ve as they normally should. if (nAscent >= 0 && nDescent <= 0)
{
fAscent = nAscent * fScale;
fDescent = -nDescent * fScale;
fExtLeading = nLineGap * fScale;
}
}
// tdf#36709: Additional font metrics are needed for font-relative indentation
mdEmSize = static_cast<double>(mnHeight);
// The ic is defined as the advance of CJK UNIFIED IDEOGRAPH-6C34 (水). // If this character does not exist, it defaults to em.
mdHorCJKAdvanceSize = mdEmSize;
mdVertCJKAdvanceSize = mdEmSize;
hb_codepoint_t nIcGlyph; if (hb_font_get_glyph(pHbFont, 0x6C34, /*variation selector*/ 0, &nIcGlyph))
{ auto nIcHAdvance = hb_font_get_glyph_h_advance(pHbFont, nIcGlyph);
mdHorCJKAdvanceSize = static_cast<double>(nIcHAdvance) * fScale;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.