/* -*- 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 .
*/
OUString aDefStr( aFont.GetFamilyName() );
OUString aLastName; int nCount = m_xVirDev->GetFontFaceCollectionCount();
std::vector<weld::ComboBoxEntry> aEntries;
aEntries.reserve(nCount); for (int i = 0; i < nCount; ++i)
{
OUString aFontName( m_xVirDev->GetFontMetricFromCollection( i ).GetFamilyName() ); if (aFontName != aLastName)
{
aLastName = aFontName;
aEntries.emplace_back(aFontName, OUString::number(i));
}
}
m_xFontLB->insert_vector(aEntries, true); // the font may not be in the list => // try to find a font name token in list and select found font, // else select topmost entry bool bFound = (m_xFontLB->find_text(aDefStr) != -1); if (!bFound)
{
sal_Int32 nIndex = 0; do
{
OUString aToken = aDefStr.getToken(0, ';', nIndex); if (m_xFontLB->find_text(aToken) != -1)
{
aDefStr = aToken;
bFound = true; break;
}
} while ( nIndex >= 0 );
}
if (bFound)
m_xFontLB->set_active_text(aDefStr); elseif (m_xFontLB->get_count() )
m_xFontLB->set_active(0);
FontSelectHdl(*m_xFontLB); if (m_xSubsetLB->get_count())
m_xSubsetLB->set_active(0);
// tdf#117038 set the buttons width to its max possible width so it doesn't // make layout change when the label changes
m_xFavouritesBtn->set_label(SvxResId(RID_SVXSTR_REMOVE_FAVORITES)); auto nMaxWidth = m_xFavouritesBtn->get_preferred_size().Width();
m_xFavouritesBtn->set_label(SvxResId(RID_SVXSTR_ADD_FAVORITES));
nMaxWidth = std::max(nMaxWidth, m_xFavouritesBtn->get_preferred_size().Width());
m_xFavouritesBtn->set_size_request(nMaxWidth, -1);
if( SvxShowCharSet::getSelectedChar() == ' ')
{
m_xOKBtn->set_sensitive(false);
} else
{
sal_UCS4 cChar = m_xShowSet->GetSelectCharacter(); // using the new UCS4 constructor
OUString aOUStr( &cChar, 1 );
m_aShowChar.SetText(aOUStr);
void SvxCharacterMap::SetCharFont( const vcl::Font& rFont )
{ // first get the underlying info in order to get font names // like "Times New Roman;Times" resolved
vcl::Font aTmp(m_xVirDev->GetFontMetric(rFont));
// tdf#56363 - search font family without the font feature after the colon
OUString sFontFamilyName = aTmp.GetFamilyName(); if (const sal_Int32 nIndex = sFontFamilyName.indexOf(":"); nIndex != -1)
sFontFamilyName = sFontFamilyName.copy(0, nIndex); if (sFontFamilyName == "StarSymbol" && m_xFontLB->find_text(sFontFamilyName) == -1)
{ //if for some reason, like font in an old document, StarSymbol is requested and it's not available, then //try OpenSymbol instead
aTmp.SetFamilyName(u"OpenSymbol"_ustr);
}
if (m_xFontLB->find_text(sFontFamilyName) == -1) return;
m_xFontLB->set_active_text(sFontFamilyName);
aFont = std::move(aTmp);
FontSelectHdl(*m_xFontLB); if (m_xSubsetLB->get_count())
m_xSubsetLB->set_active(0);
}
// notify children using this font
m_xShowSet->SetFont( aFont );
m_xSearchSet->SetFont( aFont );
m_aShowChar.SetFont( aFont );
// setup unicode subset listbar with font specific subsets, // hide unicode subset listbar for symbol fonts // TODO: get info from the Font once it provides it
pSubsetMap.reset();
m_xSubsetLB->clear();
// update subset listbox for new font's unicode subsets for (autoconst& subset : pSubsetMap->GetSubsetMap())
{
m_xSubsetLB->append(weld::toId(&subset), subset.GetName()); // NOTE: subset must live at least as long as the selected font
}
if (m_xSubsetLB->get_count() <= 1)
bNeedSubset = false;
}
if (isSearchMode)
{ // tdf#137294 do this after modifying m_xSubsetLB sensitivity to // restore insensitive for the search case
SearchUpdateHdl(*m_xSearchText);
SearchCharHighlightHdl(m_xSearchSet.get());
}
// tdf#118304 reselect current glyph to see if it's still there in new font
selectCharByCode(Radix::hexadecimal);
}
void SvxCharacterMap::setCharName(sal_UCS4 nDecimalValue)
{ /* get the character name */
UErrorCode errorCode = U_ZERO_ERROR; // icu has a private uprv_getMaxCharNameLength function which returns the max possible // length of this property. Unicode 3.2 max char name length was 83 char buffer[100];
u_charName(nDecimalValue, U_UNICODE_CHAR_NAME, buffer, sizeof(buffer), &errorCode); if (U_SUCCESS(errorCode))
m_xCharName->set_label(OUString::createFromAscii(buffer));
}
IMPL_LINK_NOARG(SvxCharacterMap, InsertClickHdl, weld::Button&, void)
{
OUString sChar = m_aShowChar.GetText();
insertCharToDoc(sChar); // Need to update recent character list, when OK button does not insert if(!m_xFrame.is())
m_aCharmapContents.updateRecentCharacterList(sChar, aFont.GetFamilyName());
m_xDialog->response(RET_OK);
}
// show char sample if ( bSelect )
{ // using the new UCS4 constructor
aText = OUString( &cChar, 1 ); // Get the hexadecimal code
OUString aHexText = OUString::number(cChar, 16).toAsciiUpperCase(); // Get the decimal code
OUString aDecimalText = OUString::number(cChar);
setCharName(cChar);
// Update the hex and decimal codes only if necessary if (!m_xHexCodeText->get_text().equalsIgnoreAsciiCase(aHexText))
m_xHexCodeText->set_text(aHexText); if (m_xDecimalCodeText->get_text() != aDecimalText)
m_xDecimalCodeText->set_text( aDecimalText );
// show char sample if ( bSelect )
{
aText = OUString( &cChar, 1 ); // Get the hexadecimal code
OUString aHexText = OUString::number(cChar, 16).toAsciiUpperCase(); // Get the decimal code
OUString aDecimalText = OUString::number(cChar);
setCharName(cChar);
// Update the hex and decimal codes only if necessary if (!m_xHexCodeText->get_text().equalsIgnoreAsciiCase(aHexText))
m_xHexCodeText->set_text(aHexText); if (m_xDecimalCodeText->get_text() != aDecimalText)
m_xDecimalCodeText->set_text( aDecimalText );
void SvxCharacterMap::selectCharByCode(Radix radix)
{
OUString aCodeString; switch(radix)
{ case Radix::decimal:
aCodeString = m_xDecimalCodeText->get_text(); break; case Radix::hexadecimal:
aCodeString = m_xHexCodeText->get_text(); break;
} // Convert the code back to a character using the appropriate radix
sal_UCS4 cChar = aCodeString.toUInt32(static_cast<sal_Int16> (radix)); // Use FontCharMap::HasChar(sal_UCS4 cChar) to see if the desired character is in the font
FontCharMapRef xFontCharMap = m_xShowSet->GetFontCharMap(); if (xFontCharMap->HasChar(cChar)) // Select the corresponding character
SetChar(cChar); else {
m_xCharName->set_label(SvxResId(RID_SVXSTR_MISSING_CHAR));
m_aShowChar.SetText(u" "_ustr); switch(radix)
{ case Radix::decimal:
m_xHexCodeText->set_text(OUString::number(cChar, 16)); break; case Radix::hexadecimal:
m_xDecimalCodeText->set_text(OUString::number(cChar)); break;
}
}
}
for (tools::Long nFontHeight = aFontSize.Height(); nFontHeight > 0; nFontHeight -= 5)
{ if (!rRenderContext.GetTextBoundRect( aBoundRect, aText ) || aBoundRect.IsEmpty())
{
bGotBoundary = false; break;
} if (!mbCenter) break; //only shrink in the single glyph large view mode
tools::Long nTextWidth = aBoundRect.GetWidth(); if (nAvailWidth > nTextWidth) break;
vcl::Font aFont(aOrigFont);
aFontSize.setHeight( nFontHeight );
aFont.SetFontSize(aFontSize);
rRenderContext.SetFont(aFont);
mnY = (nWinHeight - rRenderContext.GetTextHeight()) / 2;
bShrankFont = true;
}
Point aPoint(2, mnY); // adjust position using ink boundary if possible if (!bGotBoundary)
aPoint.setX( (aSize.Width() - rRenderContext.GetTextWidth(aText)) / 2 ); else
{ // adjust position before it gets out of bounds
aBoundRect += aPoint;
// shift back vertically if needed int nYLDelta = aBoundRect.Top(); int nYHDelta = aSize.Height() - aBoundRect.Bottom(); if( nYLDelta <= 0 )
aPoint.AdjustY( -(nYLDelta - 1) ); elseif( nYHDelta <= 0 )
aPoint.AdjustY(nYHDelta - 1 );
if (mbCenter)
{ // move glyph to middle of cell
aPoint.setX( -aBoundRect.Left() + (aSize.Width() - aBoundRect.GetWidth()) / 2 );
} else
{ // shift back horizontally if needed int nXLDelta = aBoundRect.Left(); int nXHDelta = aSize.Width() - aBoundRect.Right(); if( nXLDelta <= 0 )
aPoint.AdjustX( -(nXLDelta - 1) ); elseif( nXHDelta <= 0 )
aPoint.AdjustX(nXHDelta - 1 );
}
}
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.