Draft preferences: problems with font settings

A forum dedicated to the Draft, Arch and BIM workbenches development.
User avatar
yorik
Site Admin
Posts: 11552
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Draft preferences: problems with font settings

Postby yorik » Mon Oct 07, 2019 2:16 pm

IIRC for the Draft ShapeString, the font handling is done by freefont. I don't know why the fonts are locked that way on windows, nor why freefont wouln't be able to access them read-only somehow... This needs further investigation

I'd really like to be able to get rid of that need to specify Draft ShapeString fonts by file path, and use the same Qt system as the rest of FreeCAD... Unfortunately I didn't find yet a reliable, multi-platform way of relating a Qt font with a file path...
wandererfan
Posts: 3067
Joined: Tue Nov 06, 2012 5:42 pm

Re: Draft preferences: problems with font settings

Postby wandererfan » Wed Oct 09, 2019 11:18 pm

If there's a Windows user out there that hasn't messed too much with attributes, permissions, etc, on the Fonts directory, could they try the following please?

In Tools>Edit parameters, add a parameter to the Dialog section as shown in this screen grab:
WindowsPrefDialogParm.png
WindowsPrefDialogParm.png (62.2 KiB) Viewed 247 times

On my Windows box, setting this parameter to true allows access to the Windows/Fonts directory. I'm not sure my machine is a valid test environment anymore since I've set and reset the Fonts properties so often.

Thanks,
wf
Roy_043
Posts: 504
Joined: Thu Dec 27, 2018 12:28 pm

Re: Draft preferences: problems with font settings

Postby Roy_043 » Thu Oct 10, 2019 8:03 am

@wandererfan:
Yes, it works! I'll have to get used to the dialog, but I can live with that. Thank you!
Syres
Posts: 366
Joined: Thu Aug 09, 2018 11:14 am

Re: Draft preferences: problems with font settings

Postby Syres » Fri Oct 11, 2019 9:41 am

Roy_043 wrote:
Thu Oct 10, 2019 8:03 am
@wandererfan:
Yes, it works! I'll have to get used to the dialog, but I can live with that. Thank you!
I've made a crude hack to only have the non-native dialog for the ShapeString Task Panel by changing src\Mod\Draft\DraftGui.py around line 2460 from:

Code: Select all

        self.stringText = translate("draft","Default")
        self.task.leString.setText(self.stringText)
        self.task.fcFontFile.setFileName(Draft.getParam("FontFile",""))
        self.fileSpec = Draft.getParam("FontFile","")
        self.point = FreeCAD.Vector(0.0,0.0,0.0)
        self.pointPicked = False

        QtCore.QObject.connect(self.task.fcFontFile,QtCore.SIGNAL("fileNameSelected(const QString&)"),self.fileSelect)
        QtCore.QObject.connect(self.task.pbReset,QtCore.SIGNAL("clicked()"),self.resetPoint)
        self.point = None
        self.view = Draft.get3DView()
        self.call = self.view.addEventCallback("SoEvent",self.action)
        FreeCAD.Console.PrintMessage(translate("draft", "Pick ShapeString location point:")+"\n")


    def fileSelect(self, fn):
        self.fileSpec = fn

    def resetPoint(self):
        self.pointPicked = False
        origin = FreeCAD.Vector(0.0,0.0,0.0)
        self.setPoint(origin)

    def action(self,arg):
        """scene event handler"""
        import DraftTools
        if arg["Type"] == "SoKeyboardEvent":
            if arg["Key"] == "ESCAPE":
                self.reject()
        elif arg["Type"] == "SoLocation2Event": #mouse movement detection
            self.point,ctrlPoint,info = DraftTools.getPoint(self.sourceCmd,arg,noTracker=True)
            if not self.pointPicked:
                self.setPoint(self.point)
        elif arg["Type"] == "SoMouseButtonEvent":
            if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
                self.setPoint(self.point)
                self.pointPicked = True

    def setPoint(self, point):
        self.task.sbX.setProperty('rawValue',point.x)
        self.task.sbY.setProperty('rawValue',point.y)
        self.task.sbZ.setProperty('rawValue',point.z)

    def createObject(self):
        """creates object in the current doc"""
        dquote = '"'
        if sys.version_info.major < 3: # Python3: no more unicode
            String  = 'u' + dquote + str(self.task.leString.text().encode('unicode_escape')) + dquote
        else:
            String  = dquote + self.task.leString.text() + dquote
        FFile = dquote + str(self.fileSpec) + dquote

        Size = str(FreeCAD.Units.Quantity(self.task.sbHeight.text()).Value)
        Tracking = str(0.0)
        x = FreeCAD.Units.Quantity(self.task.sbX.text()).Value
        y = FreeCAD.Units.Quantity(self.task.sbY.text()).Value
        z = FreeCAD.Units.Quantity(self.task.sbZ.text()).Value
        ssBase = FreeCAD.Vector(x,y,z)
        # this try block is almost identical to the one in DraftTools
        try:
            qr,sup,points,fil = self.sourceCmd.getStrings()
            FreeCADGui.addModule("Draft")
            self.sourceCmd.commit(translate("draft","Create ShapeString"),
    ['ss=Draft.makeShapeString(String='+String+',FontFile='+FFile+',Size='+Size+',Tracking='+Tracking+')',
                         'plm=FreeCAD.Placement()',
                         'plm.Base='+DraftVecUtils.toString(ssBase),
                         'plm.Rotation.Q='+qr,
                         'ss.Placement=plm',
                         'ss.Support='+sup,
                         'Draft.autogroup(ss)'])
        except Exception as e:
            FreeCAD.Console.PrintError("Draft_ShapeString: error delaying commit\n")

    def accept(self):
        self.createObject();
        if self.call: self.view.removeEventCallback("SoEvent",self.call)
        FreeCADGui.ActiveDocument.resetEdit()
        FreeCADGui.Snapper.off()
        self.sourceCmd.creator.finish(self.sourceCmd)
        return True

    def reject(self):
        if self.call: self.view.removeEventCallback("SoEvent",self.call)
        FreeCADGui.ActiveDocument.resetEdit()
        FreeCADGui.Snapper.off()
        self.sourceCmd.creator.finish(self.sourceCmd)
        return True
to:

Code: Select all

        self.stringText = translate("draft","Default")
        self.task.leString.setText(self.stringText)
        tDialog = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Dialog")
        import platform
        if platform.system() == 'Windows':
            tDialog.SetBool("DontUseNativeDialog", True)
        self.task.fcFontFile.setFileName(Draft.getParam("FontFile",""))
        self.fileSpec = Draft.getParam("FontFile","")
        self.point = FreeCAD.Vector(0.0,0.0,0.0)
        self.pointPicked = False

        QtCore.QObject.connect(self.task.fcFontFile,QtCore.SIGNAL("fileNameSelected(const QString&)"),self.fileSelect)
        QtCore.QObject.connect(self.task.pbReset,QtCore.SIGNAL("clicked()"),self.resetPoint)
        self.point = None
        self.view = Draft.get3DView()
        self.call = self.view.addEventCallback("SoEvent",self.action)
        FreeCAD.Console.PrintMessage(translate("draft", "Pick ShapeString location point:")+"\n")


    def fileSelect(self, fn):
        self.fileSpec = fn

    def resetPoint(self):
        self.pointPicked = False
        origin = FreeCAD.Vector(0.0,0.0,0.0)
        self.setPoint(origin)

    def action(self,arg):
        """scene event handler"""
        import DraftTools
        if arg["Type"] == "SoKeyboardEvent":
            if arg["Key"] == "ESCAPE":
                self.reject()
        elif arg["Type"] == "SoLocation2Event": #mouse movement detection
            self.point,ctrlPoint,info = DraftTools.getPoint(self.sourceCmd,arg,noTracker=True)
            if not self.pointPicked:
                self.setPoint(self.point)
        elif arg["Type"] == "SoMouseButtonEvent":
            if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
                self.setPoint(self.point)
                self.pointPicked = True

    def setPoint(self, point):
        self.task.sbX.setProperty('rawValue',point.x)
        self.task.sbY.setProperty('rawValue',point.y)
        self.task.sbZ.setProperty('rawValue',point.z)

    def createObject(self):
        """creates object in the current doc"""
        dquote = '"'
        if sys.version_info.major < 3: # Python3: no more unicode
            String  = 'u' + dquote + str(self.task.leString.text().encode('unicode_escape')) + dquote
        else:
            String  = dquote + self.task.leString.text() + dquote
        FFile = dquote + str(self.fileSpec) + dquote

        Size = str(FreeCAD.Units.Quantity(self.task.sbHeight.text()).Value)
        Tracking = str(0.0)
        x = FreeCAD.Units.Quantity(self.task.sbX.text()).Value
        y = FreeCAD.Units.Quantity(self.task.sbY.text()).Value
        z = FreeCAD.Units.Quantity(self.task.sbZ.text()).Value
        ssBase = FreeCAD.Vector(x,y,z)
        # this try block is almost identical to the one in DraftTools
        try:
            qr,sup,points,fil = self.sourceCmd.getStrings()
            FreeCADGui.addModule("Draft")
            self.sourceCmd.commit(translate("draft","Create ShapeString"),
    ['ss=Draft.makeShapeString(String='+String+',FontFile='+FFile+',Size='+Size+',Tracking='+Tracking+')',
                         'plm=FreeCAD.Placement()',
                         'plm.Base='+DraftVecUtils.toString(ssBase),
                         'plm.Rotation.Q='+qr,
                         'ss.Placement=plm',
                         'ss.Support='+sup,
                         'Draft.autogroup(ss)'])
        except Exception as e:
            FreeCAD.Console.PrintError("Draft_ShapeString: error delaying commit\n")

    def accept(self):
        self.createObject();
        if self.call: self.view.removeEventCallback("SoEvent",self.call)
        FreeCADGui.ActiveDocument.resetEdit()
        FreeCADGui.Snapper.off()
        self.sourceCmd.creator.finish(self.sourceCmd)
        tDialog = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Dialog")
        import platform
        if platform.system() == 'Windows':
            tDialog.SetBool("DontUseNativeDialog", False)
        return True

    def reject(self):
        if self.call: self.view.removeEventCallback("SoEvent",self.call)
        FreeCADGui.ActiveDocument.resetEdit()
        FreeCADGui.Snapper.off()
        self.sourceCmd.creator.finish(self.sourceCmd)
        tDialog = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Dialog")
        import platform
        if platform.system() == 'Windows':
            tDialog.SetBool("DontUseNativeDialog", False)
        return True
OS: Windows 7 SP 1 (6.1)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.18504 (Git)
Build type: Release
Branch: master
Hash: f66023a646db4b2502bb3637897443b3525ca3c7
Python version: 3.6.8
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/United Kingdom (en_GB)
wandererfan
Posts: 3067
Joined: Tue Nov 06, 2012 5:42 pm

Re: Draft preferences: problems with font settings

Postby wandererfan » Fri Oct 11, 2019 1:18 pm

Syres wrote:
Fri Oct 11, 2019 9:41 am
I've made a crude hack to only have the non-native dialog for the ShapeString Task Panel by changing src\Mod\Draft\DraftGui.py around line 2460 from:
Nice. I've been fixated on the Preferences aspect, haven't really thought about the dialog.

I don't see your PR in the Q? :)
Syres
Posts: 366
Joined: Thu Aug 09, 2018 11:14 am

Re: Draft preferences: problems with font settings

Postby Syres » Fri Oct 11, 2019 2:27 pm