From c0ca60a1e1b600c72b11143da1381f1d348cb097 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov <Timur.Pocheptsov@cern.ch> Date: Wed, 9 May 2012 09:00:16 +0000 Subject: [PATCH] 1. TGCanvas - draws anything only if exposed region is not empty and MAKES it empty, thus constant (by nature) function modifies object's state. This makes it impossible to paint the same widget twice by calling DoRedraw, the second time exposed region is empty. This does not work with cocoa. 2. CreateFontCollection for a specific name always finds only 1 font, not all variations of the same font, instead I have to request the full list every time and filter it myself. 3. TGFontDialog: connects signal/slot only for gVirtualX inherited from TGX11 (or TGX11 itself), must also work for TGCocoa. all_sizes and all_styles variables also were set incorrectly for TGCocoa (initialization uses check InheritsFrom("TGX11")). git-svn-id: http://root.cern.ch/svn/root/trunk@44185 27541ba8-7e3a-0410-8455-c3a389f83636 --- graf2d/cocoa/src/FontCache.mm | 42 ++++++++++++++++++++++++++++------- gui/gui/src/TGCanvas.cxx | 5 ++++- gui/gui/src/TGFontDialog.cxx | 10 ++++++++- 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/graf2d/cocoa/src/FontCache.mm b/graf2d/cocoa/src/FontCache.mm index 8e75b69c4bc..cc24c0b9c9f 100644 --- a/graf2d/cocoa/src/FontCache.mm +++ b/graf2d/cocoa/src/FontCache.mm @@ -55,9 +55,14 @@ const CFStringRef fixedFontNames[FontCache::nPadFonts] = //______________________________________________________________________________ -CTFontCollectionRef CreateFontCollection(const X11::XLFDName &xlfd) +CTFontCollectionRef CreateFontCollection(const X11::XLFDName &/*xlfd*/) { - CTFontCollectionRef ctCollection = 0; + CTFontCollectionRef ctCollection = CTFontCollectionCreateFromAvailableFonts(0); + if (!ctCollection) + ::Error("CreateFontCollection", "CTFontCollectionCreateFromAvailableFonts failed"); + + return ctCollection; +/* CTFontCollectionRef ctCollection = 0; if (xlfd.fFamilyName == "*") ctCollection = CTFontCollectionCreateFromAvailableFonts(0);//Select all available fonts. else { @@ -90,7 +95,7 @@ CTFontCollectionRef CreateFontCollection(const X11::XLFDName &xlfd) } - return ctCollection; + return ctCollection;*/ } //______________________________________________________________________________ @@ -115,6 +120,23 @@ void GetWeightAndSlant(CTFontDescriptorRef fontDescriptor, X11::XLFDName &newXLF //Let's ask for a weight and pixel size. const Util::CFScopeGuard<CFDictionaryRef> traits((CFDictionaryRef)CTFontDescriptorCopyAttribute(fontDescriptor, kCTFontTraitsAttribute)); if (traits.Get()) { + if (CFNumberRef symbolTraits = (CFNumberRef)CFDictionaryGetValue(traits.Get(), kCTFontSymbolicTrait)) { + uint32_t val = 0; + CFNumberGetValue(symbolTraits, kCFNumberIntType, &val); + if (val & kCTFontItalicTrait) + newXLFD.fSlant = X11::kFSItalic; + else + newXLFD.fSlant = X11::kFSRegular; + + if (val & kCTFontBoldTrait) + newXLFD.fWeight = X11::kFWBold; + else + newXLFD.fWeight = X11::kFWMedium; + } + + /* + //The code below is wrong - using it, I can not identify bold or italic and always have + //only medium/regular. if(CFNumberRef weight = (CFNumberRef)CFDictionaryGetValue(traits.Get(), kCTFontWeightTrait)) { double val = 0.; if (CFNumberGetValue(weight, kCFNumberDoubleType, &val)) @@ -126,6 +148,7 @@ void GetWeightAndSlant(CTFontDescriptorRef fontDescriptor, X11::XLFDName &newXLF if (CFNumberGetValue(slant, kCFNumberDoubleType, &val)) newXLFD.fSlant = val > 0. ? X11::kFSItalic : X11::kFSRegular; } + */ } } @@ -156,7 +179,7 @@ void CreateXLFDString(const X11::XLFDName &xlfd, std::string &xlfdString) if (xlfd.fWeight == X11::kFWBold) xlfdString += "-bold"; else - xlfdString += "-*"; + xlfdString += "-normal"; if (xlfd.fSlant == X11::kFSItalic) xlfdString += "-i"; @@ -266,16 +289,19 @@ char **FontCache::ListFonts(const X11::XLFDName &xlfd, int maxNames, int &count) if (!GetFamilyName(font, familyName)) continue; - //I do not check family name: if xlfd.fFamilyName is '*', all font names fit, - //if it's a special name - collection is created using this name. + + if (xlfd.fFamilyName != "*" && xlfd.fFamilyName != &familyName[0]) + continue; + newXLFD.fFamilyName = &familyName[0]; GetWeightAndSlant(font, newXLFD); + //Check weight and slant. - if (newXLFD.fWeight != xlfd.fWeight) + /*if (newXLFD.fWeight != xlfd.fWeight) continue; if (newXLFD.fSlant != xlfd.fSlant) - continue; + continue;*/ if (xlfd.fPixelSize) {//Size was requested. GetPixelSize(font, newXLFD); diff --git a/gui/gui/src/TGCanvas.cxx b/gui/gui/src/TGCanvas.cxx index c8fb0d26763..b27f2808439 100644 --- a/gui/gui/src/TGCanvas.cxx +++ b/gui/gui/src/TGCanvas.cxx @@ -792,13 +792,16 @@ void TGContainer::SetPageDimension(UInt_t w, UInt_t h) void TGContainer::DoRedraw() { // Redraw content of container in the viewport region. - +#ifdef R__HAS_COCOA + DrawRegion(0, 0, GetWidth(), GetHeight()); +#else if (!fExposedRegion.IsEmpty()) { DrawRegion(fExposedRegion.fX, fExposedRegion.fY, fExposedRegion.fW, fExposedRegion.fH); fExposedRegion.Empty(); } +#endif } //______________________________________________________________________________ diff --git a/gui/gui/src/TGFontDialog.cxx b/gui/gui/src/TGFontDialog.cxx index 582991cfe74..bcc7b53cab2 100644 --- a/gui/gui/src/TGFontDialog.cxx +++ b/gui/gui/src/TGFontDialog.cxx @@ -180,9 +180,10 @@ TGFontDialog::TGFontDialog(const TGWindow *p, const TGWindow *t, fFontNames = new TGListBox(vf, kFDLG_FONTNAMES); fFontNames->Resize(120, fFontNames->GetDefaultHeight()); - if (gVirtualX->InheritsFrom("TGX11")) { + if (gVirtualX->InheritsFrom("TGX11") || gVirtualX->InheritsFrom("TGCocoa")) { fFontNames->Connect("Selected(char*)", "TGFontDialog", this, "UpdateStyleSize(char*)"); } + fFontNames->Associate(this); vf->AddFrame(fFontNames, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); @@ -580,6 +581,13 @@ void TGFontDialog::UpdateStyleSize(const char *family) Bool_t x11 = gVirtualX->InheritsFrom("TGX11"); Bool_t all_sizes = !x11; Bool_t all_styles = !x11; + + // + if (gVirtualX->InheritsFrom("TGCocoa")) { + all_sizes = kTRUE; + all_styles = kFALSE; + } + int szn = 0; fFontSizes->AddEntry("12", szn++); -- GitLab