Permalink
Browse files

0.1.0

  • Loading branch information...
spddl committed Aug 9, 2018
1 parent fb2f0b9 commit 06a7d2ebf637c44f5ae22878bc4ca0c343cf4cf2
Showing with 313 additions and 72 deletions.
  1. +163 −32 CSGOFontConfigurator.go
  2. +12 −3 README.md
  3. +20 −6 cfg/Cfg.go
  4. +0 −2 fontconfig/99SpddlConf.go
  5. +7 −17 fontconfig/WriteFontsConf.go
  6. +2 −2 fontconfig/struct.go
  7. +17 −0 helper/FileExists.go
  8. +6 −10 helper/ReadDir.go
  9. +76 −0 helper/font.go
  10. +10 −0 helper/indexOf.go
@@ -1,19 +1,24 @@
package main
import (
"fmt"
"io/ioutil"
"math"
"os"
"path/filepath"
"strings"
"./cfg"
"./fontconfig"
"./helper"
"github.com/golang/freetype/truetype"
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
)
type Reader interface {
Read(p []byte) (n int, err error)
}
type MyMainWindow struct {
*walk.MainWindow
prevFilePath string
@@ -22,9 +27,8 @@ type MyMainWindow struct {
func main() {
Config := cfg.Init()
fontsDir := filepath.Join(os.Getenv("windir"), "Fonts")
fontList, err := helper.ReadDir(fontsDir, ".ttf")
fontsDir := filepath.Join(strings.Replace(os.Getenv("windir"), "WINDOWS", "Windows", 1), "Fonts") // TODO: IDK
fontList, err := helper.ReadDir(fontsDir)
if err != nil {
panic(err)
}
@@ -43,7 +47,14 @@ func main() {
mw.AppPath, _ = filepath.Abs("./")
var LineEditPath *walk.LineEdit
var ComboBoxFont *walk.ComboBox
var NumberEditPixelSize *walk.NumberEdit
var CheckBoxEmbeddedBitmap,
CheckBoxPreferOutline,
CheckBoxDoSubstitutions,
CheckBoxBitmapMonospace,
CheckBoxForceAutohint,
CheckBoxQtUseSubpixelPositioning *walk.CheckBox
var NumberEditdpi *walk.NumberEdit
if err := (MainWindow{
AssignTo: &mw.MainWindow,
Title: "CSGOFontConfigurator",
@@ -64,7 +75,6 @@ func main() {
},
},
PushButton{
// AssignTo: &PushButtonFileExplorer,
Text: "📁",
OnClicked: func() {
path, err := mw.openFileExplorer()
@@ -78,26 +88,26 @@ func main() {
},
},
Composite{
Layout: HBox{},
Children: []Widget{
Label{
Text: "PixelSize:",
},
NumberEdit{
Enabled: false,
AssignTo: &NumberEditPixelSize,
Value: Config.PixelSize,
MinValue: 0,
MaxValue: math.Inf(+1),
Suffix: " pt",
Decimals: 2,
OnValueChanged: func() {
Config.PixelSize = NumberEditPixelSize.Value()
},
},
},
},
// Composite{ TODO:
// Layout: HBox{},
// Children: []Widget{
// Label{
// Text: "PixelSize:",
// },
// NumberEdit{
// Enabled: false,
// AssignTo: &NumberEditPixelSize,
// Value: Config.PixelSize,
// MinValue: 0,
// MaxValue: math.Inf(+1),
// Suffix: " pt",
// Decimals: 2,
// OnValueChanged: func() {
// Config.PixelSize = NumberEditPixelSize.Value()
// },
// },
// },
// },
Composite{
Layout: HBox{},
@@ -109,15 +119,114 @@ func main() {
AlwaysConsumeSpace: true,
StretchFactor: 50,
AssignTo: &ComboBoxFont,
Value: "Font",
Model: fontList,
OnCurrentIndexChanged: func() {
fmt.Println("OnCurrentIndexChanged", ComboBoxFont.CurrentIndex())
Config.File = ComboBoxFont.Text()
},
},
},
},
Composite{
Layout: Grid{Columns: 2},
Children: []Widget{
Label{
Text: "Embedded Bitmap:",
ToolTipText: "Bitmap fonts are sometimes used as fallbacks for missing fonts, which may cause text to be rendered pixelated or too large.", // TODO:
},
CheckBox{
AssignTo: &CheckBoxEmbeddedBitmap,
Checked: Config.EmbeddedBitmap,
ToolTipText: "Default: false",
OnCheckStateChanged: func() {
Config.EmbeddedBitmap = CheckBoxEmbeddedBitmap.Checked()
},
},
Label{
Text: "Prefer Outline:",
ToolTipText: "", // TODO:
},
CheckBox{
AssignTo: &CheckBoxPreferOutline,
Checked: Config.PreferOutline,
ToolTipText: "Default: true",
OnCheckStateChanged: func() {
Config.PreferOutline = CheckBoxPreferOutline.Checked()
},
},
Label{
Text: "Do Substitutions:",
ToolTipText: "", // TODO:
},
CheckBox{
AssignTo: &CheckBoxDoSubstitutions,
Checked: Config.DoSubstitutions,
ToolTipText: "Default: true",
OnCheckStateChanged: func() {
Config.DoSubstitutions = CheckBoxDoSubstitutions.Checked()
},
},
Label{
Text: "Bitmap Monospace:",
ToolTipText: "", // TODO:
},
CheckBox{
AssignTo: &CheckBoxBitmapMonospace,
Checked: Config.BitmapMonospace,
ToolTipText: "Default: false",
OnCheckStateChanged: func() {
Config.BitmapMonospace = CheckBoxBitmapMonospace.Checked()
},
},
Label{
Text: "Force Autohint:",
ToolTipText: "", // TODO:
},
CheckBox{
AssignTo: &CheckBoxForceAutohint,
Checked: Config.ForceAutohint,
ToolTipText: "Default: false",
OnCheckStateChanged: func() {
Config.ForceAutohint = CheckBoxForceAutohint.Checked()
},
},
Label{
Text: "Qt Use Subpixel Positioning:",
ToolTipText: "", // TODO:
},
CheckBox{
AssignTo: &CheckBoxQtUseSubpixelPositioning,
Checked: Config.QtUseSubpixelPositioning,
ToolTipText: "Default: false",
OnCheckStateChanged: func() {
Config.QtUseSubpixelPositioning = CheckBoxQtUseSubpixelPositioning.Checked()
},
},
Label{
Text: "dpi:",
ToolTipText: "", // TODO:
},
NumberEdit{
AssignTo: &NumberEditdpi,
Value: Config.Dpi,
MinValue: 0,
MaxValue: math.Inf(+1),
Decimals: 0,
ToolTipText: "Default: 96",
OnValueChanged: func() {
Config.Dpi = NumberEditdpi.Value()
},
},
},
},
Composite{
Layout: HBox{},
Children: []Widget{
@@ -132,11 +241,20 @@ func main() {
walk.MsgBox(mw, "Error", err.Error(), walk.MsgBoxOK|walk.MsgBoxIconError)
panic(err)
}
err = fontconfig.WriteSpddlConf(def)
spddlconfpath := filepath.Join(filepath.Dir(def.Path), "csgo", "panorama", "fonts", "conf.d", "99-spddl.conf")
exists, err := helper.FileExists(spddlconfpath)
if err != nil {
walk.MsgBox(mw, "Error", err.Error(), walk.MsgBoxOK|walk.MsgBoxIconError)
panic(err)
}
if exists {
err := os.Remove(spddlconfpath)
if err != nil {
walk.MsgBox(mw, "Error", err.Error(), walk.MsgBoxOK|walk.MsgBoxIconError)
panic(err)
}
}
walk.MsgBox(mw, "FontConfig", "done.", walk.MsgBoxIconInformation)
},
@@ -150,11 +268,15 @@ func main() {
if err != nil {
walk.MsgBox(mw, "ErrorReadFile", err.Error(), walk.MsgBoxOK|walk.MsgBoxIconError)
}
f, err := truetype.Parse(data)
fontData, err := helper.NewFontData(Config.File, data)
if err != nil {
walk.MsgBox(mw, "ErrorTrueTypeParse", err.Error(), walk.MsgBoxOK|walk.MsgBoxIconError)
walk.MsgBox(mw, "Error Parse", err.Error(), walk.MsgBoxOK|walk.MsgBoxIconError)
}
Config.Font = f.Name(truetype.NameIDFontFullName)
// fmt.Println("Name", fontData.Name) // Name AdobeHebrew-Italic
// fmt.Println("Family", fontData.Family) // Family Adobe Hebrew
// fmt.Println("FileName", fontData.FileName) // FileName AdobeHebrew-Italic.otf
Config.Font = fontData.Name
//
// https://www.freedesktop.org/software/fontconfig/fontconfig-user.html#AEN134
@@ -177,6 +299,7 @@ func main() {
}
walk.MsgBox(mw, "FontConfig", "done.", walk.MsgBoxIconInformation)
os.Exit(0)
},
},
PushButton{
@@ -192,7 +315,15 @@ func main() {
panic(err)
}
LineEditPath.SetText(Config.Path)
if Config.File != "" {
i := helper.IndexOf(Config.File, fontList)
fmt.Println("Config.File", Config.File, i)
err = ComboBoxFont.SetCurrentIndex(i)
if err != nil {
panic(err)
}
}
mw.Run() // https://github.com/lxn/walk/issues/103#issuecomment-278243090
}
@@ -1,11 +1,20 @@
# CSGOFontConfigurator 💪
First pre release
[![Downloads][1]][2] [![GitHub stars][3]][4]
TODO: more options & possibilities 🤞
[1]: https://img.shields.io/github/downloads/spddl/CSGOFontConfigurator/total.svg
[2]: https://github.com/spddl/CSGOFontConfigurator/releases "Downloads"
[3]: https://img.shields.io/github/stars/spddl/CSGOFontConfigurator.svg
[4]: https://github.com/spddl/CSGOFontConfigurator/stargazers "GitHub stars"
[![Twitter](https://img.shields.io/twitter/url/https/github.com/spddl/CSGOFontConfigurator.svg?style=social)](https://twitter.com/intent/tweet?text=Wow:&url=https%3A%2F%2Fgithub.com%2Fspddl%2FCSGOFontConfigurator)
### [Download](https://github.com/spddl/CSGOFontConfigurator/releases)
![screenshot](https://i.imgur.com/GMesuBA.png)
Not all fonts work ingame and I do not know why :/
TODO: more options & possibilities 🤞
![screenshot](https://i.imgur.com/UIVPky2.png)
### compile
@@ -10,10 +10,17 @@ import (
)
type Config struct { // https://mholt.github.io/json-to-go/
Path string `json:"path"`
PixelSize float64 `json:"pixelsize"`
Font string `json:"Font"`
File string `json:"File"`
Path string `json:"path"`
// PixelSize float64 `json:"pixelsize"`
Font string `json:"font"`
File string `json:"file"`
EmbeddedBitmap bool `json:"embeddedbitmap"`
PreferOutline bool `json:"preferoutline"`
DoSubstitutions bool `json:"dosubstitutions"`
BitmapMonospace bool `json:"bitmapmonospace"`
ForceAutohint bool `json:"forceautohint"`
QtUseSubpixelPositioning bool `json:"qtusesubpixelpositioning"`
Dpi float64 `json:"dpi"`
}
func Exists(path string) (bool, error) {
@@ -77,8 +84,15 @@ func SaveConfigFile(AppPath string, jsonBlob Config) error { // https://github.c
func NewConfig() Config {
jsonBlob := json.RawMessage(`{
"path": "",
"pixelsize": 1.2,
"font": ""
"font": "",
"file": "",
"embeddedbitmap": false,
"preferoutline": true,
"dosubstitutions": true,
"bitmapmonospace": false,
"forceautohint": false,
"qtusesubpixelpositioning": false,
"dpi": 96
}`)
var jsontype Config
@@ -10,8 +10,6 @@ import (
)
func WriteSpddlConf(c cfg.Config) error {
// file, _ := helper.FileAndExt(c.Font)
fontconfig := &Sfontconfig{}
fontconfig.Smatch = []Smatch{
{
Oops, something went wrong.

0 comments on commit 06a7d2e

Please sign in to comment.