Compare commits
54 Commits
6656b6d0b2
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| bb5e0fb766 | |||
| 68fc916bc1 | |||
| 4e0d9fdcca | |||
| bf69bafd42 | |||
| 71c221aa04 | |||
| 8695f69282 | |||
| d5d2f6db8e | |||
| 48f2c51d92 | |||
| 06e1212483 | |||
| c7bb89fd6d | |||
| 13f856cfbc | |||
| 066ac22605 | |||
| b074d2113f | |||
| e35b849d49 | |||
| b11402f842 | |||
| a0875fd1ff | |||
| cb7ecbd3f7 | |||
| 5eaae4deb9 | |||
| b75cb920eb | |||
| 96f43eda44 | |||
| 9b3afcfb46 | |||
| 708192ec02 | |||
| 6c43a29f9f | |||
| fb358e3c4b | |||
| 75ac2883f7 | |||
| 52de039ca0 | |||
| 6f95c60381 | |||
| 8891dcffb8 | |||
| 5aa0d7466e | |||
| b01fa2261a | |||
| af33cf268a | |||
| 2927335975 | |||
| da6e868b0f | |||
| 9c81f21be7 | |||
| 6346dc8843 | |||
| c11c82186c | |||
| 2703bbd901 | |||
| 19bf78d635 | |||
| 3173fabfc1 | |||
| bae74d7a96 | |||
| cde77e6ae6 | |||
| 9bf5131d27 | |||
| ad30ca8cb7 | |||
| 7e298faadd | |||
| b523e233cb | |||
| 322366719e | |||
| de6c7754cb | |||
| 7902db6ec7 | |||
| b469b8212f | |||
| 46f636a9ac | |||
| 8d56ea7217 | |||
| 7a5c1c5159 | |||
| 68235b57ce | |||
| 12dae774e4 |
31
.clang-format
Normal file
31
.clang-format
Normal file
@@ -0,0 +1,31 @@
|
||||
BasedOnStyle: LLVM
|
||||
IndentWidth: 4
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
||||
BreakBeforeBraces: Custom
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: false
|
||||
AfterControlStatement: Never
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
SplitEmptyFunction: false
|
||||
SplitEmptyRecord: false
|
||||
SplitEmptyNamespace: false
|
||||
AlignConsecutiveDeclarations: true
|
||||
AlignConsecutiveAssignments: true
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
|
||||
AlignConsecutiveMacros: true
|
||||
AllowShortBlocksOnASingleLine: Always
|
||||
AllowShortCaseLabelsOnASingleLine: true
|
||||
Cpp11BracedListStyle: false
|
||||
ColumnLimit: 0
|
||||
12
.claude/settings.local.json
Normal file
12
.claude/settings.local.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"permissions": {
|
||||
"allow": [
|
||||
"Bash(cd /c/Users/mta/projects/autosample && ./nob.exe debug 2>&1)",
|
||||
"Bash(cd /c/Users/mta/projects/autosample && rm -f build/*.pdb build/*.obj build/*.ilk && ./nob.exe debug 2>&1)",
|
||||
"Bash(cd /c/Users/mta/projects/autosample && ./nob.exe 2>&1)",
|
||||
"Bash(cd:*)",
|
||||
"Bash(wc:*)",
|
||||
"Bash(./build.exe:*)"
|
||||
]
|
||||
}
|
||||
}
|
||||
22
.gitignore
vendored
22
.gitignore
vendored
@@ -1,5 +1,18 @@
|
||||
# Build output
|
||||
build/
|
||||
build
|
||||
build_debug
|
||||
build_release
|
||||
|
||||
# debugger files
|
||||
*.raddbg
|
||||
*.rdi
|
||||
|
||||
# bullshit files
|
||||
nul
|
||||
.DS_Store
|
||||
|
||||
# editor files
|
||||
*.sublime-workspace
|
||||
|
||||
# nob build system
|
||||
nob.exe
|
||||
@@ -21,7 +34,12 @@ nob.ilk
|
||||
*.dylib
|
||||
*.a
|
||||
|
||||
# Generated source
|
||||
*.gen.h
|
||||
*.gen.cpp
|
||||
*.spv.h
|
||||
|
||||
# Misc
|
||||
*.exe
|
||||
!nob.c
|
||||
|
||||
.cache
|
||||
13
.vscode/launch.json
vendored
13
.vscode/launch.json
vendored
@@ -2,10 +2,19 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Debug autosample",
|
||||
"name": "Debug autosample (macOS)",
|
||||
"type": "lldb-dap",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/build_debug/autosample.app/Contents/MacOS/autosample",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"preLaunchTask": "build-debug"
|
||||
},
|
||||
{
|
||||
"name": "Debug autosample (Windows)",
|
||||
"type": "cppvsdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/build/autosample.exe",
|
||||
"program": "${workspaceFolder}/build_debug/autosample.exe",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"console": "integratedTerminal",
|
||||
|
||||
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"lldb-dap.executable-path": "/opt/homebrew/opt/llvm/bin/lldb-dap"
|
||||
}
|
||||
70
.vscode/tasks.json
vendored
70
.vscode/tasks.json
vendored
@@ -2,48 +2,76 @@
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "bootstrap nob",
|
||||
"label": "bootstrap",
|
||||
"type": "shell",
|
||||
"command": "cl",
|
||||
"args": ["/nologo", "nob.c"],
|
||||
"command": "cc",
|
||||
"args": ["build.c", "-o", "build"],
|
||||
"windows": {
|
||||
"command": "cl",
|
||||
"args": ["/nologo", "build.c"]
|
||||
},
|
||||
"group": "build",
|
||||
"problemMatcher": "$msCompile",
|
||||
"detail": "One-time bootstrap: compile nob.c with cl.exe"
|
||||
"problemMatcher": [],
|
||||
"detail": "One-time bootstrap: compile build.c"
|
||||
},
|
||||
{
|
||||
"label": "build",
|
||||
"type": "shell",
|
||||
"command": "${workspaceFolder}/nob.exe",
|
||||
"command": "${workspaceFolder}/build",
|
||||
"windows": {
|
||||
"command": "${workspaceFolder}/build.exe"
|
||||
},
|
||||
"group": "build",
|
||||
"problemMatcher": "$msCompile",
|
||||
"problemMatcher": {
|
||||
"owner": "cpp",
|
||||
"fileLocation": ["relative", "${workspaceFolder}"],
|
||||
"pattern": {
|
||||
"regexp": "^(.+?):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
|
||||
"file": 1,
|
||||
"line": 2,
|
||||
"column": 3,
|
||||
"severity": 4,
|
||||
"message": 5
|
||||
}
|
||||
},
|
||||
"detail": "Build autosample (release)"
|
||||
},
|
||||
{
|
||||
"label": "build-debug",
|
||||
"type": "shell",
|
||||
"command": "${workspaceFolder}/nob.exe",
|
||||
"command": "${workspaceFolder}/build",
|
||||
"args": ["debug"],
|
||||
"windows": {
|
||||
"command": "${workspaceFolder}/build.exe",
|
||||
"args": ["debug"]
|
||||
},
|
||||
"group": "build",
|
||||
"problemMatcher": "$msCompile",
|
||||
"problemMatcher": {
|
||||
"owner": "c",
|
||||
"fileLocation": ["relative", "${workspaceFolder}"],
|
||||
"pattern": {
|
||||
"regexp": "^(.+?):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
|
||||
"file": 1,
|
||||
"line": 2,
|
||||
"column": 3,
|
||||
"severity": 4,
|
||||
"message": 5
|
||||
}
|
||||
},
|
||||
"detail": "Build autosample (debug)"
|
||||
},
|
||||
{
|
||||
"label": "rebuild",
|
||||
"type": "shell",
|
||||
"command": "${workspaceFolder}/nob.exe",
|
||||
"group": "build",
|
||||
"problemMatcher": "$msCompile",
|
||||
"detail": "Clean and rebuild",
|
||||
"dependsOn": "clean"
|
||||
},
|
||||
{
|
||||
"label": "clean",
|
||||
"type": "shell",
|
||||
"command": "if (Test-Path build) { Remove-Item -Recurse -Force build }",
|
||||
"args": [],
|
||||
"command": "${workspaceFolder}/build",
|
||||
"args": ["clean"],
|
||||
"windows": {
|
||||
"command": "${workspaceFolder}/build.exe",
|
||||
"args": ["clean"]
|
||||
},
|
||||
"group": "build",
|
||||
"problemMatcher": [],
|
||||
"detail": "Remove build directory"
|
||||
"detail": "Clean build artifacts via build.c"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
117
LICENSE
117
LICENSE
@@ -1,117 +0,0 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and modification follow.
|
||||
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
one line to give the program's name and an idea of what it does. Copyright (C) yyyy name of author
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
signature of Ty Coon, 1 April 1989 Ty Coon, President of Vice
|
||||
159
README.md
159
README.md
@@ -4,52 +4,171 @@ Graphical interface for automatically recording samples from existing analog aud
|
||||
|
||||
## Build
|
||||
|
||||
Requires MSVC (Visual Studio or Build Tools) with the Windows SDK.
|
||||
### Windows
|
||||
|
||||
Requires MSVC (Visual Studio 2019 Build Tools or later) with the Windows SDK and C++20 support, and the [Vulkan SDK](https://vulkan.lunarg.com/) (for headers, `vulkan-1.lib`, and `glslc`). The build system looks for `%VULKAN_SDK%` or falls back to `C:\VulkanSDK\1.4.341.1`.
|
||||
|
||||
Open a Developer Command Prompt, then:
|
||||
|
||||
```
|
||||
cl /nologo nob.c
|
||||
nob.exe
|
||||
build\autosample.exe
|
||||
cl /nologo build.c
|
||||
build.exe debug
|
||||
build_debug\autosample.exe
|
||||
```
|
||||
|
||||
The first command is a one-time bootstrap. After that, `nob.exe` detects changes to `nob.c` and rebuilds itself automatically.
|
||||
### macOS
|
||||
|
||||
Requires Xcode Command Line Tools (`xcode-select --install`).
|
||||
|
||||
```
|
||||
cc build.c -o build
|
||||
./build debug
|
||||
open build_debug/autosample.app
|
||||
```
|
||||
|
||||
The first command is a one-time bootstrap. After that, `./build` detects changes to `build.c` and rebuilds itself automatically. Pass `debug` for a debug build (output in `build_debug/`) or omit for release (`build_release/`). Pass `clean` to wipe both build directories, vendor libraries, and generated sources. Invalid arguments produce an error with usage info.
|
||||
|
||||
## Architecture
|
||||
|
||||
The project uses a **unity build**: `src/main.cpp` includes all other `.cpp`/`.mm` files, producing a single translation unit compiled with one compiler invocation. Platform selection is handled with `#ifdef __APPLE__` guards.
|
||||
|
||||
### Base layer (`src/base/`)
|
||||
|
||||
Foundational types and utilities shared across the project. Provides sized integer/float typedefs (`U8`, `S32`, `F32`, `B32`, etc.), math primitives (`Vec2F32`), string helpers, and arena allocators. This layer has no dependencies beyond the C standard library.
|
||||
|
||||
### Platform layer (`src/platform/`)
|
||||
|
||||
Abstracts window creation, event polling, menus, clipboard, and native handles behind a C-style API with opaque `PlatformWindow` handles.
|
||||
|
||||
- **Windows**: `platform_win32.cpp` — Win32/HWND, `WM_*` message loop, per-monitor DPI awareness (v2) with `WM_DPICHANGED` handling
|
||||
- **macOS**: `platform_macos.mm` — Cocoa/AppKit, NSWindow, NSTextInputClient
|
||||
|
||||
### UI layer (`src/ui/`)
|
||||
|
||||
A thin wrapper around [Clay](https://github.com/nicbarker/clay) (v0.14), a single-header C layout library. Clay uses macros (`CLAY()`, `CLAY_TEXT()`, etc.) for declarative layout with automatic sizing, flex-like child arrangement, and built-in text measurement.
|
||||
|
||||
- `ui_core.h` / `ui_core.cpp` — Defines `UI_Context` and `UI_Theme`, handles Clay initialization, lifecycle (`ui_begin_frame` / `ui_end_frame`), text measurement bridge, theme/accent management, and error handling. `CLAY_IMPLEMENTATION` is defined here.
|
||||
- `ui_widgets.h` / `ui_widgets.cpp` — Immediate-mode widget library: buttons, checkboxes, radio groups, text inputs (with selection, clipboard, Tab cycling), dropdowns, tab bars, draggable windows, and modal dialogs.
|
||||
- `ui_icons.h` / `ui_icons.cpp` — SVG icon atlas rasterized at startup via lunasvg. Icons are rendered as custom Clay elements.
|
||||
|
||||
The application layout is built in `main.cpp` using Clay macros directly. Panel builder functions (`build_browser_panel`, `build_main_panel`, etc.) compose the UI each frame.
|
||||
|
||||
#### Theme system
|
||||
|
||||
The UI supports a full theme system managed through `UI_Theme` (`ui_core.h`) with live switching at runtime:
|
||||
|
||||
- **Base themes**: Dark and Light, selectable via `ui_set_theme()`. Each defines a full palette — backgrounds, borders, text, accent colors, title bars, scrollbars, tab colors, and drop shadow opacity.
|
||||
- **Accent palettes**: 7 color options (Blue, Turquoise, Orange, Purple, Pink, Red, Green) applied via `ui_set_accent()`. Each palette provides coordinated accent, hover, tab gradient, button text, and tab text colors tuned for both dark and light base themes.
|
||||
- **Corner radius**: Configurable at runtime (None / Small / Medium / Large) via `g_theme.corner_radius`. All widgets read `CORNER_RADIUS` which scales with `uis()`.
|
||||
- **UI scale**: Cmd+/Cmd- (Ctrl on Windows) zoom from 0.5x to 3.0x. All widget sizes, padding, font sizes, and corner radii scale via `uis()` / `uip()` / `uifs()` helpers.
|
||||
|
||||
#### Visual depth
|
||||
|
||||
Interactive elements use subtle visual effects for a DAW-style look:
|
||||
|
||||
- **Gradients**: Buttons, title bars, dropdown headers, and tab bars use vertical gradients via Clay's `CLAY_RENDER_COMMAND_TYPE_CUSTOM` system and a per-frame `CustomGradientData` pool. Buttons and title bars are lighter on top (raised), text inputs are darker on top (inset/recessed).
|
||||
- **Drop shadows**: Floating windows, modals, and dropdown lists cast soft multi-layer shadows. 7 concentric rects with linearly decreasing opacity simulate a gaussian blur, offset down-right for directional lighting.
|
||||
- **Panel highlights**: 1px lighter lines at the top of panel content areas simulate beveled edges.
|
||||
|
||||
### Renderer (`src/renderer/`)
|
||||
|
||||
Custom SDF-based pipeline for UI rendering. Processes Clay's `Clay_RenderCommandArray` output directly — no intermediate scene graph.
|
||||
|
||||
- **Windows**: `renderer_vulkan.cpp` — Vulkan, GLSL shaders (compiled to SPIR-V at build time)
|
||||
- **macOS**: `renderer_metal.mm` — Metal, MSL shaders
|
||||
|
||||
Both renderers share the same vertex format (18 floats), SDF rounded-rect shader, and Clay command processing logic. Font rasterization and text measurement use FreeType on both platforms with the embedded [Inter](https://rsms.me/inter/) typeface. The font atlas is a 1024x1024 R8 texture containing ASCII glyphs 32–126 rasterized at a fixed pixel size; text at other sizes is scaled from the atlas. The Inter TTF is embedded at build time as a C byte array (`font_inter.gen.h`) so there are no runtime font file dependencies. Font scale is multiplied by the platform DPI scale factor for crisp rendering on high-DPI displays.
|
||||
|
||||
### Audio (`src/audio/`)
|
||||
|
||||
Audio device enumeration and output with test tone generation.
|
||||
|
||||
- **Windows**: `audio_asio.cpp` — ASIO driver via COM, registry enumeration, multi-format sample writing
|
||||
- **macOS**: `audio_coreaudio.cpp` — CoreAudio with AUGraph/HAL Output, Float32 non-interleaved
|
||||
|
||||
### MIDI (`src/midi/`)
|
||||
|
||||
MIDI device enumeration with real-time input monitoring.
|
||||
|
||||
- **Windows**: `midi_win32.cpp` — Win32 multimedia API (`midiIn*` / `midiOut*`)
|
||||
- **macOS**: `midi_coremidi.cpp` — CoreMIDI client with single input port, source connection
|
||||
|
||||
## Project structure
|
||||
|
||||
```
|
||||
nob.c Build script (compiled to nob.exe)
|
||||
nob.h nob build system (vendored, single-header)
|
||||
build.c Build script (cc build.c -o build)
|
||||
assets/
|
||||
fonts/
|
||||
Inter-Regular.ttf Inter typeface (SIL Open Font License)
|
||||
OFL.txt Font license
|
||||
vendor/
|
||||
nob/
|
||||
nob.h nob build system (vendored, single-header)
|
||||
clay/
|
||||
clay.h Clay v0.14 (modified for MSVC C++ compatibility)
|
||||
freetype/
|
||||
include/ FreeType 2.13.3 public headers
|
||||
src/ FreeType source (minimal module set)
|
||||
src/
|
||||
main.cpp Entry point and main loop
|
||||
main.cpp Entry point, unity build includes, Clay layout
|
||||
menus.cpp Menu bar setup
|
||||
base/
|
||||
base_core.h Sized types, macros
|
||||
base_arena.h / .cpp Arena allocator
|
||||
base_math.h Vec2, min/max
|
||||
base_strings.h / .cpp String utilities
|
||||
base_inc.h / .cpp Aggregate include/impl
|
||||
platform/
|
||||
platform.h Window management API (platform-agnostic)
|
||||
platform_win32.cpp Win32 implementation
|
||||
platform_win32.cpp Win32 implementation (per-monitor DPI aware)
|
||||
platform_macos.mm macOS Cocoa implementation
|
||||
renderer/
|
||||
renderer.h Renderer API (graphics-agnostic)
|
||||
renderer_dx12.cpp DirectX 12 implementation + Dear ImGui backend
|
||||
vendor/
|
||||
imgui/ Dear ImGui (vendored source)
|
||||
backends/ Platform and renderer backends (Win32, DX12)
|
||||
renderer_dx12.cpp DirectX 12 implementation
|
||||
renderer_metal.mm Metal implementation
|
||||
font_inter.gen.h Generated at build time — embedded font data
|
||||
ui/
|
||||
ui_core.h Clay wrapper, UI_Theme, scale helpers, custom render types
|
||||
ui_core.cpp Clay init, text measurement bridge, theme/accent palettes
|
||||
ui_widgets.h / .cpp Immediate-mode widgets (button, checkbox, radio, text input, dropdown, tab bar, window, modal)
|
||||
ui_icons.h / .cpp SVG icon atlas (check, close, chevron) via lunasvg
|
||||
audio/
|
||||
audio.h Audio device and playback API
|
||||
audio_asio.cpp Windows ASIO implementation
|
||||
audio_coreaudio.cpp macOS CoreAudio implementation
|
||||
midi/
|
||||
midi.h MIDI device enumeration API
|
||||
midi_win32.cpp Win32 multimedia implementation
|
||||
midi_coremidi.cpp macOS CoreMIDI implementation
|
||||
```
|
||||
|
||||
The platform and renderer layers are C-style APIs with opaque handles. `platform.h` abstracts window creation so other backends can be added without touching the rest of the code. `renderer.h` abstracts graphics initialization and frame management.
|
||||
### Modifications to `vendor/clay/clay.h`
|
||||
|
||||
Two targeted patches for MSVC C++ compatibility:
|
||||
|
||||
1. **`CLAY__CONFIG_WRAPPER` bypass** (lines 158–163): MSVC C++ rejects designated initializers inside function-style casts. In C++ mode, the wrapper struct is bypassed: `(type { __VA_ARGS__ })` instead of `(WrapperType { .field = ... }).wrapped`.
|
||||
|
||||
2. **Debug view stub** (lines ~3155–3858): Clay's built-in debug view functions use `CLAY__INIT(type) { .field = ... }` directly (not through `CLAY__CONFIG_WRAPPER`), which also fails in MSVC C++. An `#ifdef __cplusplus` guard stubs out the 4 debug view functions as empty no-ops. The debug overlay is not needed.
|
||||
|
||||
These patches allow the entire project (including Clay) to compile as a single C++20 translation unit, avoiding C/C++ ABI mismatches with `CLAY_PACKED_ENUM` (which controls enum sizing differently in C vs C++ mode).
|
||||
|
||||
## Code style
|
||||
|
||||
This project is written in C-style C++. We use `.cpp` files and a small subset of C++ features (default struct values, function overloading, namespaces where useful) but avoid the rest. No classes, no inheritance, limit templates, no exceptions, no RAII, avoid STL containers or algorithms. Data is plain structs. Functions operate on those structs, or pointers to them.
|
||||
This project is written in C-style C++. We use `.cpp` files and a small subset of C++ features (default struct values, function overloading, namespaces where useful) but avoid the rest. No classes, no inheritance, limit templates, no exceptions, no RTTI, avoid STL containers or algorithms. Data is plain structs. Functions operate on those structs, or pointers to them. macOS files use `.mm` extension for Objective-C++ interop.
|
||||
|
||||
Memory should be managed with arena allocators where possible rather than individual `malloc`/`free` or `new`/`delete` calls. Arenas make allocation fast, avoid fragmentation, and simplify cleanup.
|
||||
|
||||
### Syntax Style
|
||||
### Syntax style
|
||||
|
||||
- Opening braces go on the same line as the function signature (K&R style), not on the next line.
|
||||
- use CAPS_SNAKE_CASE for constants, lower_snake_case for functions and variables, and CapsCamelCase for types.
|
||||
- Use `CAPS_SNAKE_CASE` for constants, `lower_snake_case` for functions and variables, and `CapsCamelCase` for types.
|
||||
|
||||
## Dependencies
|
||||
|
||||
All dependencies are vendored as source. Nothing to download or install beyond the Windows SDK.
|
||||
All dependencies are vendored as source. On Windows, nothing to install beyond the Windows SDK. On macOS, only Xcode Command Line Tools are needed — all frameworks (Metal, Cocoa, CoreAudio, CoreMIDI, etc.) ship with the OS.
|
||||
|
||||
- [nob.h](https://github.com/tsoding/nob.h) - build system
|
||||
- [Dear ImGui](https://github.com/ocornut/imgui) - GUI
|
||||
- [nob.h](https://github.com/tsoding/nob.h) — build system
|
||||
- [Clay](https://github.com/nicbarker/clay) — single-header C layout library (v0.14, with MSVC C++ patches)
|
||||
- [FreeType](https://freetype.org/) — font rasterizer (v2.13.3, FreeType License). Compiled as a static library with a minimal module set (truetype, sfnt, smooth, autofit, psnames, pshinter, gzip). Replaces platform-specific font backends (GDI on Windows, Core Text on macOS) for consistent cross-platform text rendering. Static libraries are built into their vendor directories (`vendor/freetype/freetype.lib` on Windows, `vendor/freetype/libfreetype.a` on macOS); debug builds on Windows use a `_d` suffix to avoid CRT mismatch.
|
||||
- [Inter](https://rsms.me/inter/) — typeface (v4.1, SIL Open Font License). Embedded at build time as a C byte array header so there are no runtime font file dependencies.
|
||||
- [LunaSVG](https://github.com/nicbarker/lunasvg) — SVG rendering library (MIT, by Samuel Ugochukwu) used to rasterize icon SVGs into an R8 texture atlas at startup. Icons (close, check, chevron, knob) are defined as inline SVG strings in `ui_icons.cpp` and rendered at a fixed pixel size into a packed atlas. The atlas is uploaded to the GPU once and sampled by the renderer for icon and rotated-icon custom elements. Bundled with [PlutoVG](https://github.com/nicbarker/plutovg) as its 2D vector graphics backend.
|
||||
|
||||
399
assets/fader.svg
Normal file
399
assets/fader.svg
Normal file
@@ -0,0 +1,399 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
width="210mm"
|
||||
height="297mm"
|
||||
viewBox="0 0 210 297"
|
||||
version="1.1"
|
||||
id="svg1"
|
||||
inkscape:version="1.4.2 (f4327f4, 2025-05-13)"
|
||||
sodipodi:docname="fader.svg"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<sodipodi:namedview
|
||||
id="namedview1"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#000000"
|
||||
borderopacity="0.25"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:zoom="4.1585017"
|
||||
inkscape:cx="355.53671"
|
||||
inkscape:cy="395.21446"
|
||||
inkscape:window-width="2560"
|
||||
inkscape:window-height="1369"
|
||||
inkscape:window-x="-8"
|
||||
inkscape:window-y="-8"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="layer1" />
|
||||
<defs
|
||||
id="defs1">
|
||||
<linearGradient
|
||||
id="linearGradient7718"
|
||||
y2="528.75"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x2="87.865997"
|
||||
gradientTransform="matrix(1.0278,0,0,1,787.52,-27.904)"
|
||||
y1="516.83002"
|
||||
x1="87.865997"
|
||||
inkscape:collect="always">
|
||||
<stop
|
||||
id="stop3899-3"
|
||||
style="stop-color:#999999"
|
||||
offset="0" />
|
||||
<stop
|
||||
id="stop3901-5"
|
||||
style="stop-color:#999999;stop-opacity:0"
|
||||
offset="1" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id="linearGradient7720"
|
||||
y2="499.10001"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x2="618.48999"
|
||||
gradientTransform="matrix(1.0235,0,0,1,242.38,-1008.6)"
|
||||
y1="496.57001"
|
||||
x1="618.48999"
|
||||
inkscape:collect="always">
|
||||
<stop
|
||||
id="stop3925-4"
|
||||
style="stop-color:#cccccc"
|
||||
offset="0" />
|
||||
<stop
|
||||
id="stop3927-44"
|
||||
style="stop-color:#cccccc;stop-opacity:0"
|
||||
offset="1" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id="linearGradient7722"
|
||||
y2="499.10001"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x2="618.48999"
|
||||
gradientTransform="matrix(1,0,0,0.50643,256.46,265.42)"
|
||||
y1="496.57001"
|
||||
x1="618.48999"
|
||||
inkscape:collect="always">
|
||||
<stop
|
||||
id="stop3925-5-0"
|
||||
style="stop-color:#cccccc"
|
||||
offset="0" />
|
||||
<stop
|
||||
id="stop3927-2-7"
|
||||
style="stop-color:#cccccc;stop-opacity:0"
|
||||
offset="1" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id="linearGradient7724"
|
||||
y2="499.10001"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x2="618.48999"
|
||||
gradientTransform="matrix(1,0,0,0.42746,256.46,317.38)"
|
||||
y1="496.57001"
|
||||
x1="618.48999"
|
||||
inkscape:collect="always">
|
||||
<stop
|
||||
id="stop3925-2-9"
|
||||
style="stop-color:#cccccc"
|
||||
offset="0" />
|
||||
<stop
|
||||
id="stop3927-7-3"
|
||||
style="stop-color:#cccccc;stop-opacity:0"
|
||||
offset="1" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id="linearGradient7726"
|
||||
y2="499.10001"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x2="618.48999"
|
||||
gradientTransform="matrix(1,0,0,0.26952,256.46,405.1)"
|
||||
y1="496.57001"
|
||||
x1="618.48999"
|
||||
inkscape:collect="always">
|
||||
<stop
|
||||
id="stop3925-3-1"
|
||||
style="stop-color:#cccccc"
|
||||
offset="0" />
|
||||
<stop
|
||||
id="stop3927-29-29"
|
||||
style="stop-color:#cccccc;stop-opacity:0"
|
||||
offset="1" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id="linearGradient7728"
|
||||
y2="521.41998"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x2="87.865997"
|
||||
gradientTransform="matrix(1.0364,0,0,0.96441,786.64,-1114.5)"
|
||||
y1="516.83002"
|
||||
x1="87.865997"
|
||||
inkscape:collect="always">
|
||||
<stop
|
||||
id="stop4107-6"
|
||||
style="stop-color:#999999"
|
||||
offset="0" />
|
||||
<stop
|
||||
id="stop4109-0"
|
||||
style="stop-color:#333333"
|
||||
offset="1" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id="linearGradient7730"
|
||||
y2="499.10001"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x2="618.48999"
|
||||
gradientTransform="matrix(1.0364,0,0,0.96441,234.39,-1076.7)"
|
||||
y1="496.57001"
|
||||
x1="618.48999"
|
||||
inkscape:collect="always">
|
||||
<stop
|
||||
id="stop3925-0-3"
|
||||
style="stop-color:#cccccc"
|
||||
offset="0" />
|
||||
<stop
|
||||
id="stop3927-5-04"
|
||||
style="stop-color:#cccccc;stop-opacity:0"
|
||||
offset="1" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id="linearGradient7732"
|
||||
y2="499.10001"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x2="618.48999"
|
||||
gradientTransform="matrix(1.0274,0,0,0.48841,240.25,-833.5)"
|
||||
y1="496.57001"
|
||||
x1="618.48999"
|
||||
inkscape:collect="always">
|
||||
<stop
|
||||
id="stop3925-5-6-12"
|
||||
style="stop-color:#cccccc"
|
||||
offset="0" />
|
||||
<stop
|
||||
id="stop3927-2-3-5"
|
||||
style="stop-color:#cccccc;stop-opacity:0"
|
||||
offset="1" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id="linearGradient7734"
|
||||
y2="499.10001"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x2="618.48999"
|
||||
gradientTransform="matrix(1.0213,0,0,0.41225,243.85,-783.64)"
|
||||
y1="496.57001"
|
||||
x1="618.48999"
|
||||
inkscape:collect="always">
|
||||
<stop
|
||||
id="stop3925-2-5-8"
|
||||
style="stop-color:#cccccc"
|
||||
offset="0" />
|
||||
<stop
|
||||
id="stop3927-7-4-1"
|
||||
style="stop-color:#cccccc;stop-opacity:0"
|
||||
offset="1" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id="linearGradient7736"
|
||||
y2="499.10001"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x2="618.48999"
|
||||
gradientTransform="matrix(1.0122,0,0,0.25993,249.26,-698.66)"
|
||||
y1="496.57001"
|
||||
x1="618.48999"
|
||||
inkscape:collect="always">
|
||||
<stop
|
||||
id="stop3925-3-8-82"
|
||||
style="stop-color:#cccccc"
|
||||
offset="0" />
|
||||
<stop
|
||||
id="stop3927-29-9-9"
|
||||
style="stop-color:#cccccc;stop-opacity:0"
|
||||
offset="1" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1">
|
||||
<g
|
||||
id="g6784"
|
||||
transform="matrix(0.26458333,0,0,0.26458333,-142.0892,-39.104459)">
|
||||
<rect
|
||||
id="rect3827-6"
|
||||
style="fill:#4d4d4d"
|
||||
rx="3"
|
||||
ry="3"
|
||||
height="129.28999"
|
||||
width="62.143002"
|
||||
y="488.03"
|
||||
x="847.03003" />
|
||||
<rect
|
||||
id="rect3829-6"
|
||||
style="fill:#e6e6e6"
|
||||
height="3.5355"
|
||||
width="60.418999"
|
||||
y="552.41998"
|
||||
x="847.96997" />
|
||||
<rect
|
||||
id="rect3831-4"
|
||||
style="fill:url(#linearGradient7718)"
|
||||
rx="2.1482999"
|
||||
ry="2"
|
||||
height="21.070999"
|
||||
width="60.612999"
|
||||
y="488.73999"
|
||||
x="847.71997" />
|
||||
<rect
|
||||
id="rect3829-4-0"
|
||||
style="fill:#333333"
|
||||
height="10.119"
|
||||
width="58.811001"
|
||||
y="540.26001"
|
||||
x="847.91998" />
|
||||
<rect
|
||||
id="rect3829-47-8"
|
||||
style="fill:#333333"
|
||||
height="8.7929001"
|
||||
width="61.132999"
|
||||
y="530.89001"
|
||||
x="847.03003" />
|
||||
<rect
|
||||
id="rect3829-3-70"
|
||||
style="fill:#1a1a1a"
|
||||
height="4.5457001"
|
||||
width="61.132999"
|
||||
y="512.47998"
|
||||
x="847.03003" />
|
||||
<rect
|
||||
id="rect3829-3-7-6"
|
||||
style="fill:#1a1a1a"
|
||||
height="11.364"
|
||||
width="61.132999"
|
||||
y="518.25"
|
||||
x="847.03003" />
|
||||
<rect
|
||||
id="rect3829-9-9"
|
||||
ry="0.63958001"
|
||||
style="fill:url(#linearGradient7720)"
|
||||
rx="1.0235"
|
||||
transform="scale(1,-1)"
|
||||
height="2.2612"
|
||||
width="60.012001"
|
||||
y="-511.76001"
|
||||
x="847.71997" />
|
||||
<rect
|
||||
id="rect3829-9-0-07"
|
||||
style="fill:url(#linearGradient7722)"
|
||||
rx="1"
|
||||
ry="0.32390001"
|
||||
height="1.1452"
|
||||
width="58.632999"
|
||||
y="517.03003"
|
||||
x="847.89001" />
|
||||
<rect
|
||||
id="rect3829-9-2-4"
|
||||
style="fill:url(#linearGradient7724)"
|
||||
rx="1"
|
||||
ry="0.27340001"
|
||||
height="0.9666"
|
||||
width="58.632999"
|
||||
y="529.76001"
|
||||
x="847.89001" />
|
||||
<rect
|
||||
id="rect3829-9-07-1"
|
||||
style="fill:url(#linearGradient7726)"
|
||||
rx="1"
|
||||
ry="0.17238"
|
||||
height="0.60946"
|
||||
width="58.632999"
|
||||
y="539.01001"
|
||||
x="847.89001" />
|
||||
<rect
|
||||
id="rect3831-5-8"
|
||||
style="fill:url(#linearGradient7728)"
|
||||
transform="scale(1,-1)"
|
||||
rx="2.1661999"
|
||||
ry="1.9288"
|
||||
height="20.320999"
|
||||
width="61.118"
|
||||
y="-616.23999"
|
||||
x="847.34003" />
|
||||
<rect
|
||||
id="rect3829-4-1-2"
|
||||
style="fill:#333333"
|
||||
transform="scale(1,-1)"
|
||||
height="9.7593002"
|
||||
width="58.811001"
|
||||
y="-567.92999"
|
||||
x="847.91998" />
|
||||
<rect
|
||||
id="rect3829-47-5-6"
|
||||
style="fill:#666666"
|
||||
transform="scale(1,-1)"
|
||||
height="8.4799004"
|
||||
width="61.132999"
|
||||
y="-576.96002"
|
||||
x="847.03003" />
|
||||
<rect
|
||||
id="rect3829-3-0-9"
|
||||
style="fill:#808080"
|
||||
transform="scale(1,-1)"
|
||||
height="4.3839002"
|
||||
width="61.132999"
|
||||
y="-594.71997"
|
||||
x="847.03003" />
|
||||
<rect
|
||||
id="rect3829-3-7-0-2"
|
||||
style="fill:#808080"
|
||||
transform="scale(1,-1)"
|
||||
height="10.96"
|
||||
width="61.132999"
|
||||
y="-589.15997"
|
||||
x="847.03003" />
|
||||
<rect
|
||||
id="rect3829-9-04-2"
|
||||
style="fill:url(#linearGradient7730)"
|
||||
transform="scale(1,-1)"
|
||||
rx="1.0364"
|
||||
ry="0.61681002"
|
||||
height="2.1808"
|
||||
width="60.766998"
|
||||
y="-597.59998"
|
||||
x="847.34003" />
|
||||
<rect
|
||||
id="rect3829-9-0-0-1"
|
||||
style="fill:url(#linearGradient7732)"
|
||||
transform="scale(1,-1)"
|
||||
rx="1.0274"
|
||||
ry="0.31237"
|
||||
height="1.1044"
|
||||
width="60.240002"
|
||||
y="-590.84003"
|
||||
x="847.89001" />
|
||||
<rect
|
||||
id="rect3829-9-2-7-2"
|
||||
style="fill:url(#linearGradient7734)"
|
||||
transform="scale(1,-1)"
|
||||
rx="1.0213"
|
||||
ry="0.26366001"
|
||||
height="0.93220001"
|
||||
width="59.882999"
|
||||
y="-578.82001"
|
||||
x="847.89001" />
|
||||
<rect
|
||||
id="rect3829-9-07-5-1"
|
||||
style="fill:url(#linearGradient7736)"
|
||||
transform="scale(1,-1)"
|
||||
rx="1.0122"
|
||||
ry="0.16624001"
|
||||
height="0.58775997"
|
||||
width="59.347"
|
||||
y="-569.52002"
|
||||
x="847.89001" />
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 11 KiB |
3490
assets/faders.svg
Normal file
3490
assets/faders.svg
Normal file
File diff suppressed because it is too large
Load Diff
|
After Width: | Height: | Size: 103 KiB |
BIN
assets/fonts/Inter-Regular.ttf
Normal file
BIN
assets/fonts/Inter-Regular.ttf
Normal file
Binary file not shown.
92
assets/fonts/OFL.txt
Normal file
92
assets/fonts/OFL.txt
Normal file
@@ -0,0 +1,92 @@
|
||||
Copyright (c) 2016 The Inter Project Authors (https://github.com/rsms/inter)
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
http://scripts.sil.org/OFL
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION AND CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
@@ -1,24 +0,0 @@
|
||||
// raddbg 0.9.24 project file
|
||||
|
||||
recent_file: path: "src/main.cpp"
|
||||
recent_file: path: "src/theme.cpp"
|
||||
recent_file: path: "nob.obj"
|
||||
recent_file: path: "vendor/imgui/imgui.h"
|
||||
recent_file: path: "src/platform/platform.h"
|
||||
recent_file: path: "project.rad"
|
||||
target:
|
||||
{
|
||||
executable: "build/autosample.exe"
|
||||
working_directory: build
|
||||
}
|
||||
debug_info:
|
||||
{
|
||||
path: "C:/Users/mta/projects/autosample/build/autosample.pdb"
|
||||
timestamp: 66207529127862
|
||||
}
|
||||
target:
|
||||
{
|
||||
executable: "build/autosample.exe"
|
||||
working_directory: "build/"
|
||||
enabled: 1
|
||||
}
|
||||
495
build.c
Normal file
495
build.c
Normal file
@@ -0,0 +1,495 @@
|
||||
// Bootstrap:
|
||||
// Windows: cl /nologo build.c
|
||||
// macOS: cc build.c -o build
|
||||
// After that, just run: ./build (or build.exe on Windows)
|
||||
|
||||
#define BUILD_IMPLEMENTATION
|
||||
#include "build.h"
|
||||
|
||||
////////////////////////////////
|
||||
// FreeType source files
|
||||
|
||||
static const char *freetype_sources[] = {
|
||||
"vendor/freetype/src/base/ftsystem.c",
|
||||
"vendor/freetype/src/base/ftinit.c",
|
||||
"vendor/freetype/src/base/ftdebug.c",
|
||||
"vendor/freetype/src/base/ftbase.c",
|
||||
"vendor/freetype/src/base/ftbbox.c",
|
||||
"vendor/freetype/src/base/ftglyph.c",
|
||||
"vendor/freetype/src/base/ftbitmap.c",
|
||||
"vendor/freetype/src/base/ftmm.c",
|
||||
"vendor/freetype/src/truetype/truetype.c",
|
||||
"vendor/freetype/src/sfnt/sfnt.c",
|
||||
"vendor/freetype/src/smooth/smooth.c",
|
||||
"vendor/freetype/src/autofit/autofit.c",
|
||||
"vendor/freetype/src/psnames/psnames.c",
|
||||
"vendor/freetype/src/pshinter/pshinter.c",
|
||||
"vendor/freetype/src/gzip/ftgzip.c",
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
// Font embedding — reads a .ttf and writes a C header with the data as a byte array
|
||||
|
||||
static bool embed_font_file(const char *ttf_path, const char *header_path) {
|
||||
if (!needs_rebuild1(header_path, ttf_path)) {
|
||||
build_log(LOG_INFO, "Font header %s is up to date", header_path);
|
||||
return true;
|
||||
}
|
||||
|
||||
String_Builder sb = {0};
|
||||
if (!sb_read_file(&sb, ttf_path)) return false;
|
||||
|
||||
FILE *out = fopen(header_path, "wb");
|
||||
if (!out) {
|
||||
build_log(LOG_ERROR, "Could not open %s for writing", header_path);
|
||||
sb_free(&sb);
|
||||
return false;
|
||||
}
|
||||
|
||||
fprintf(out, "// Auto-generated from %s — do not edit\n", ttf_path);
|
||||
fprintf(out, "#pragma once\n\n");
|
||||
fprintf(out, "static const unsigned char font_inter_data[] = {\n");
|
||||
for (size_t i = 0; i < sb.count; i++) {
|
||||
if (i % 16 == 0) fprintf(out, " ");
|
||||
fprintf(out, "0x%02x,", (unsigned char)sb.items[i]);
|
||||
if (i % 16 == 15 || i == sb.count - 1) fprintf(out, "\n");
|
||||
}
|
||||
fprintf(out, "};\n\n");
|
||||
fprintf(out, "static const unsigned int font_inter_size = %zu;\n", sb.count);
|
||||
|
||||
fclose(out);
|
||||
sb_free(&sb);
|
||||
build_log(LOG_INFO, "Generated %s (%zu bytes)", header_path, sb.count);
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
////////////////////////////////
|
||||
// macOS build (clang with Objective-C)
|
||||
|
||||
static const char *frameworks[] = {
|
||||
"-framework", "Metal",
|
||||
"-framework", "Cocoa",
|
||||
"-framework", "CoreAudio",
|
||||
"-framework", "AudioToolbox",
|
||||
"-framework", "CoreMIDI",
|
||||
"-framework", "QuartzCore",
|
||||
"-framework", "CoreFoundation",
|
||||
};
|
||||
|
||||
static bool build_freetype_lib(const char *build_dir, bool debug) {
|
||||
const char *obj_dir = temp_sprintf("%s/freetype_obj", build_dir);
|
||||
const char *lib_path = "vendor/freetype/libfreetype.a";
|
||||
|
||||
if (!needs_rebuild(lib_path, freetype_sources, ARRAY_LEN(freetype_sources))) {
|
||||
build_log(LOG_INFO, "freetype is up to date");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!mkdir_if_not_exists(obj_dir)) return false;
|
||||
|
||||
for (size_t i = 0; i < ARRAY_LEN(freetype_sources); i++) {
|
||||
const char *src = freetype_sources[i];
|
||||
const char *base = strrchr(src, '/');
|
||||
base = base ? base + 1 : src;
|
||||
char obj_name[256];
|
||||
snprintf(obj_name, sizeof(obj_name), "%s", base);
|
||||
char *dot = strrchr(obj_name, '.');
|
||||
if (dot) { dot[1] = 'o'; dot[2] = '\0'; }
|
||||
const char *obj_path = temp_sprintf("%s/%s", obj_dir, obj_name);
|
||||
|
||||
Cmd cmd = {0};
|
||||
cmd_append(&cmd, "clang");
|
||||
cmd_append(&cmd, "-std=c11", "-c");
|
||||
cmd_append(&cmd, "-DFT2_BUILD_LIBRARY");
|
||||
cmd_append(&cmd, "-Ivendor/freetype/include");
|
||||
cmd_append(&cmd, "-w");
|
||||
if (debug) {
|
||||
cmd_append(&cmd, "-g", "-O0");
|
||||
} else {
|
||||
cmd_append(&cmd, "-O2");
|
||||
}
|
||||
cmd_append(&cmd, "-o", obj_path);
|
||||
cmd_append(&cmd, src);
|
||||
if (!cmd_run(&cmd)) return false;
|
||||
}
|
||||
|
||||
// Archive
|
||||
{
|
||||
Cmd cmd = {0};
|
||||
cmd_append(&cmd, "ar", "rcs", lib_path);
|
||||
for (size_t i = 0; i < ARRAY_LEN(freetype_sources); i++) {
|
||||
const char *src = freetype_sources[i];
|
||||
const char *base = strrchr(src, '/');
|
||||
base = base ? base + 1 : src;
|
||||
char obj_name[256];
|
||||
snprintf(obj_name, sizeof(obj_name), "%s", base);
|
||||
char *dot = strrchr(obj_name, '.');
|
||||
if (dot) { dot[1] = 'o'; dot[2] = '\0'; }
|
||||
cmd__append(&cmd, 1, temp_sprintf("%s/%s", obj_dir, obj_name));
|
||||
}
|
||||
if (!cmd_run(&cmd)) return false;
|
||||
}
|
||||
|
||||
// Clean up obj dir
|
||||
{
|
||||
Cmd cmd = {0};
|
||||
cmd_append(&cmd, "rm", "-rf", obj_dir);
|
||||
cmd_run(&cmd);
|
||||
}
|
||||
|
||||
build_log(LOG_INFO, "Built %s", lib_path);
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
GO_REBUILD_URSELF(argc, argv);
|
||||
|
||||
bool debug = false;
|
||||
bool clean = false;
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "debug") == 0) debug = true;
|
||||
else if (strcmp(argv[i], "clean") == 0) clean = true;
|
||||
else {
|
||||
build_log(LOG_ERROR, "unknown argument: %s", argv[i]);
|
||||
build_log(LOG_ERROR, "usage: %s [debug] [clean]", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
const char *build_dir = debug ? "build_debug" : "build_release";
|
||||
|
||||
if (clean) {
|
||||
build_log(LOG_INFO, "Cleaning build artifacts");
|
||||
{ Cmd cmd = {0}; cmd_append(&cmd, "rm", "-rf", "build_debug"); cmd_run(&cmd); }
|
||||
{ Cmd cmd = {0}; cmd_append(&cmd, "rm", "-rf", "build_release"); cmd_run(&cmd); }
|
||||
remove("vendor/freetype/libfreetype.a");
|
||||
remove("src/renderer/font_inter.gen.h");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// App bundle paths
|
||||
const char *app_dir = temp_sprintf("%s/autosample.app", build_dir);
|
||||
const char *contents = temp_sprintf("%s/Contents", app_dir);
|
||||
const char *macos_dir = temp_sprintf("%s/Contents/MacOS", app_dir);
|
||||
const char *res_dir = temp_sprintf("%s/Contents/Resources", app_dir);
|
||||
const char *binary_path = temp_sprintf("%s/Contents/MacOS/autosample", app_dir);
|
||||
|
||||
if (!mkdir_if_not_exists(build_dir)) return 1;
|
||||
if (!mkdir_if_not_exists(app_dir)) return 1;
|
||||
if (!mkdir_if_not_exists(contents)) return 1;
|
||||
if (!mkdir_if_not_exists(macos_dir)) return 1;
|
||||
if (!mkdir_if_not_exists(res_dir)) return 1;
|
||||
|
||||
// Build static libraries
|
||||
if (!build_freetype_lib(build_dir, debug)) return 1;
|
||||
|
||||
// Generate embedded font header
|
||||
if (!embed_font_file("assets/fonts/Inter-Regular.ttf",
|
||||
"src/renderer/font_inter.gen.h")) return 1;
|
||||
|
||||
// Unity build: single clang invocation compiles main.c (which #includes everything)
|
||||
{
|
||||
Cmd cmd = {0};
|
||||
cmd_append(&cmd, "clang");
|
||||
cmd_append(&cmd, "-std=c11", "-x", "objective-c");
|
||||
cmd_append(&cmd, "-Wall", "-Wextra", "-Wno-missing-field-initializers");
|
||||
cmd_append(&cmd, "-Wno-deprecated-declarations");
|
||||
cmd_append(&cmd, "-Isrc");
|
||||
cmd_append(&cmd, "-isystem", "vendor/clay");
|
||||
cmd_append(&cmd, "-isystem", "vendor/nanosvg");
|
||||
cmd_append(&cmd, "-isystem", "vendor/freetype/include");
|
||||
|
||||
if (debug) {
|
||||
cmd_append(&cmd, "-g", "-O0", "-D_DEBUG");
|
||||
} else {
|
||||
cmd_append(&cmd, "-O2", "-DNDEBUG");
|
||||
}
|
||||
|
||||
cmd_append(&cmd, "-o", binary_path);
|
||||
cmd_append(&cmd, "src/daw/daw_main.c");
|
||||
|
||||
// Reset language mode so .a is treated as a library, not source
|
||||
cmd_append(&cmd, "-x", "none");
|
||||
cmd_append(&cmd, "vendor/freetype/libfreetype.a");
|
||||
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < ARRAY_LEN(frameworks); i++)
|
||||
cmd__append(&cmd, 1, frameworks[i]);
|
||||
}
|
||||
cmd_append(&cmd, "-lm");
|
||||
if (!cmd_run(&cmd)) return 1;
|
||||
}
|
||||
|
||||
// Write Info.plist
|
||||
{
|
||||
const char *plist_path = temp_sprintf("%s/Contents/Info.plist", app_dir);
|
||||
const char *plist =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\"\n"
|
||||
" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
|
||||
"<plist version=\"1.0\">\n"
|
||||
"<dict>\n"
|
||||
" <key>CFBundleExecutable</key>\n"
|
||||
" <string>autosample</string>\n"
|
||||
" <key>CFBundleIdentifier</key>\n"
|
||||
" <string>com.autosample.app</string>\n"
|
||||
" <key>CFBundleName</key>\n"
|
||||
" <string>autosample</string>\n"
|
||||
" <key>CFBundleVersion</key>\n"
|
||||
" <string>0.1</string>\n"
|
||||
" <key>CFBundleShortVersionString</key>\n"
|
||||
" <string>0.1</string>\n"
|
||||
" <key>CFBundlePackageType</key>\n"
|
||||
" <string>APPL</string>\n"
|
||||
" <key>NSHighResolutionCapable</key>\n"
|
||||
" <true/>\n"
|
||||
" <key>NSSupportsAutomaticGraphicsSwitching</key>\n"
|
||||
" <true/>\n"
|
||||
"</dict>\n"
|
||||
"</plist>\n";
|
||||
write_entire_file(plist_path, plist, strlen(plist));
|
||||
}
|
||||
|
||||
build_log(LOG_INFO, "Build complete: %s", app_dir);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
////////////////////////////////
|
||||
// Windows build (MSVC cl.exe)
|
||||
|
||||
// Vulkan SDK path — detected from environment or default install location
|
||||
static const char *get_vulkan_sdk_path(void) {
|
||||
const char *env = getenv("VULKAN_SDK");
|
||||
if (env && env[0]) return env;
|
||||
return "C:\\VulkanSDK\\1.4.341.1";
|
||||
}
|
||||
|
||||
static const char *link_libs[] = {
|
||||
"user32.lib",
|
||||
"gdi32.lib",
|
||||
"shell32.lib",
|
||||
"ole32.lib",
|
||||
"advapi32.lib",
|
||||
"dwmapi.lib",
|
||||
"winmm.lib",
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
// SPIR-V shader compilation — compiles .glsl to .spv, then embeds as C header
|
||||
|
||||
static bool compile_shader(const char *glslc_path, const char *src, const char *spv_path, const char *stage) {
|
||||
Cmd cmd = {0};
|
||||
cmd_append(&cmd, glslc_path, temp_sprintf("-fshader-stage=%s", stage), "-o", spv_path, src);
|
||||
return cmd_run(&cmd);
|
||||
}
|
||||
|
||||
static bool embed_spirv(const char *spv_path, const char *header_path, const char *array_name) {
|
||||
String_Builder sb = {0};
|
||||
if (!sb_read_file(&sb, spv_path)) return false;
|
||||
|
||||
FILE *out = fopen(header_path, "wb");
|
||||
if (!out) {
|
||||
build_log(LOG_ERROR, "Could not open %s for writing", header_path);
|
||||
sb_free(&sb);
|
||||
return false;
|
||||
}
|
||||
|
||||
fprintf(out, "// Auto-generated from %s — do not edit\n", spv_path);
|
||||
fprintf(out, "#pragma once\n\n");
|
||||
// SPIR-V is U32-aligned, emit as uint32_t array
|
||||
size_t word_count = sb.count / 4;
|
||||
fprintf(out, "#include <stdint.h>\n\n");
|
||||
fprintf(out, "static const uint32_t %s[] = {\n", array_name);
|
||||
const uint32_t *words = (const uint32_t *)sb.items;
|
||||
for (size_t i = 0; i < word_count; i++) {
|
||||
if (i % 8 == 0) fprintf(out, " ");
|
||||
fprintf(out, "0x%08x,", words[i]);
|
||||
if (i % 8 == 7 || i == word_count - 1) fprintf(out, "\n");
|
||||
}
|
||||
fprintf(out, "};\n");
|
||||
|
||||
fclose(out);
|
||||
sb_free(&sb);
|
||||
build_log(LOG_INFO, "Generated %s (%zu bytes)", header_path, sb.count);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool compile_and_embed_shaders(const char *build_dir) {
|
||||
const char *vk_sdk = get_vulkan_sdk_path();
|
||||
const char *glslc = temp_sprintf("%s\\Bin\\glslc.exe", vk_sdk);
|
||||
|
||||
const char *vert_src = "src/renderer/ui.v.glsl";
|
||||
const char *frag_src = "src/renderer/ui.f.glsl";
|
||||
const char *vert_spv = temp_sprintf("%s/ui_vert.spv", build_dir);
|
||||
const char *frag_spv = temp_sprintf("%s/ui_frag.spv", build_dir);
|
||||
const char *vert_hdr = "src/renderer/ui_vert.spv.h";
|
||||
const char *frag_hdr = "src/renderer/ui_frag.spv.h";
|
||||
|
||||
// Check if rebuild needed
|
||||
if (needs_rebuild1(vert_hdr, vert_src)) {
|
||||
build_log(LOG_INFO, "Compiling vertex shader");
|
||||
if (!compile_shader(glslc, vert_src, vert_spv, "vertex")) return false;
|
||||
if (!embed_spirv(vert_spv, vert_hdr, "ui_vert_spv")) return false;
|
||||
} else {
|
||||
build_log(LOG_INFO, "Vertex shader is up to date");
|
||||
}
|
||||
|
||||
if (needs_rebuild1(frag_hdr, frag_src)) {
|
||||
build_log(LOG_INFO, "Compiling fragment shader");
|
||||
if (!compile_shader(glslc, frag_src, frag_spv, "fragment")) return false;
|
||||
if (!embed_spirv(frag_spv, frag_hdr, "ui_frag_spv")) return false;
|
||||
} else {
|
||||
build_log(LOG_INFO, "Fragment shader is up to date");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool build_freetype_lib(const char *build_dir, bool debug) {
|
||||
const char *obj_dir = temp_sprintf("%s\\freetype_obj", build_dir);
|
||||
const char *lib_path = debug ? "vendor\\freetype\\freetype_d.lib" : "vendor\\freetype\\freetype.lib";
|
||||
|
||||
if (!needs_rebuild(lib_path, freetype_sources, ARRAY_LEN(freetype_sources))) {
|
||||
build_log(LOG_INFO, "freetype is up to date");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!mkdir_if_not_exists(obj_dir)) return false;
|
||||
|
||||
for (size_t i = 0; i < ARRAY_LEN(freetype_sources); i++) {
|
||||
const char *src = freetype_sources[i];
|
||||
Cmd cmd = {0};
|
||||
cmd_append(&cmd, "cl.exe", "/nologo", "/c");
|
||||
cmd_append(&cmd, "/std:c11");
|
||||
cmd_append(&cmd, "/DFT2_BUILD_LIBRARY");
|
||||
cmd_append(&cmd, "/Ivendor/freetype/include");
|
||||
cmd_append(&cmd, "/W0");
|
||||
if (debug) {
|
||||
cmd_append(&cmd, "/MTd", "/Zi");
|
||||
} else {
|
||||
cmd_append(&cmd, "/MT", "/O2");
|
||||
}
|
||||
cmd_append(&cmd, temp_sprintf("/Fo:%s/", obj_dir));
|
||||
cmd_append(&cmd, src);
|
||||
if (!cmd_run(&cmd)) return false;
|
||||
}
|
||||
|
||||
// Archive
|
||||
{
|
||||
Cmd cmd = {0};
|
||||
cmd_append(&cmd, "lib.exe", "/nologo", temp_sprintf("/OUT:%s", lib_path));
|
||||
cmd_append(&cmd, temp_sprintf("%s/*.obj", obj_dir));
|
||||
if (!cmd_run(&cmd)) return false;
|
||||
}
|
||||
|
||||
// Clean up obj dir
|
||||
{
|
||||
Cmd cmd = {0};
|
||||
cmd_append(&cmd, "cmd.exe", "/c",
|
||||
temp_sprintf("if exist %s rmdir /s /q %s", obj_dir, obj_dir));
|
||||
cmd_run(&cmd);
|
||||
}
|
||||
|
||||
build_log(LOG_INFO, "Built %s", lib_path);
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
GO_REBUILD_URSELF(argc, argv);
|
||||
|
||||
bool debug = false;
|
||||
bool clean = false;
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "debug") == 0) debug = true;
|
||||
else if (strcmp(argv[i], "clean") == 0) clean = true;
|
||||
else {
|
||||
build_log(LOG_ERROR, "unknown argument: %s", argv[i]);
|
||||
build_log(LOG_ERROR, "usage: %s [debug] [clean]", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
const char *build_dir = debug ? "build_debug" : "build_release";
|
||||
|
||||
if (clean) {
|
||||
build_log(LOG_INFO, "Cleaning build artifacts");
|
||||
{ Cmd cmd = {0}; cmd_append(&cmd, "cmd.exe", "/c",
|
||||
"if exist build_debug rmdir /s /q build_debug");
|
||||
cmd_run(&cmd); }
|
||||
{ Cmd cmd = {0}; cmd_append(&cmd, "cmd.exe", "/c",
|
||||
"if exist build_release rmdir /s /q build_release");
|
||||
cmd_run(&cmd); }
|
||||
remove("vendor\\freetype\\freetype.lib");
|
||||
remove("vendor\\freetype\\freetype_d.lib");
|
||||
remove("src\\renderer\\font_inter.gen.h");
|
||||
remove("src\\renderer\\ui_vert.spv.h");
|
||||
remove("src\\renderer\\ui_frag.spv.h");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!mkdir_if_not_exists(build_dir)) return 1;
|
||||
|
||||
// Build static libraries
|
||||
if (!build_freetype_lib(build_dir, debug)) return 1;
|
||||
|
||||
// Generate embedded font header
|
||||
if (!embed_font_file("assets/fonts/Inter-Regular.ttf",
|
||||
"src\\renderer\\font_inter.gen.h")) return 1;
|
||||
|
||||
// Compile GLSL shaders to SPIR-V and embed as C headers
|
||||
if (!compile_and_embed_shaders(build_dir)) return 1;
|
||||
|
||||
const char *vk_sdk = get_vulkan_sdk_path();
|
||||
const char *vk_lib = temp_sprintf("%s/Lib/vulkan-1.lib", vk_sdk);
|
||||
|
||||
// Unity build: single cl.exe invocation compiles main.c (which #includes everything)
|
||||
{
|
||||
Cmd cmd = {0};
|
||||
cmd_append(&cmd, "cl.exe");
|
||||
cmd_append(&cmd, "/nologo", "/std:c11", "/TC", "/W3");
|
||||
cmd_append(&cmd, "/Isrc");
|
||||
cmd_append(&cmd, "/external:W0");
|
||||
cmd_append(&cmd, "/external:Ivendor/clay");
|
||||
cmd_append(&cmd, "/external:Ivendor/nanosvg");
|
||||
cmd_append(&cmd, "/external:Ivendor/freetype/include");
|
||||
cmd_append(&cmd, temp_sprintf("/external:I%s/Include", vk_sdk));
|
||||
|
||||
if (debug) {
|
||||
cmd_append(&cmd, "/MTd", "/Zi", "/D_DEBUG");
|
||||
} else {
|
||||
cmd_append(&cmd, "/MT", "/Zi", "/O2", "/DNDEBUG");
|
||||
}
|
||||
|
||||
cmd_append(&cmd, temp_sprintf("/Fe:%s/autosample.exe", build_dir));
|
||||
cmd_append(&cmd, temp_sprintf("/Fo:%s/", build_dir));
|
||||
cmd_append(&cmd, temp_sprintf("/Fd:%s/autosample.pdb", build_dir));
|
||||
|
||||
cmd_append(&cmd, "src/daw/daw_main.c");
|
||||
|
||||
cmd_append(&cmd, "/link");
|
||||
cmd_append(&cmd, "/MACHINE:X64");
|
||||
cmd_append(&cmd, debug ? "/SUBSYSTEM:CONSOLE" : "/SUBSYSTEM:WINDOWS");
|
||||
if (!debug) cmd_append(&cmd, "/ENTRY:mainCRTStartup");
|
||||
cmd_append(&cmd, temp_sprintf("/PDB:%s/autosample.pdb", build_dir));
|
||||
cmd_append(&cmd, "/DEBUG");
|
||||
cmd_append(&cmd, debug ? "vendor/freetype/freetype_d.lib" : "vendor/freetype/freetype.lib");
|
||||
cmd_append(&cmd, vk_lib);
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < ARRAY_LEN(link_libs); i++)
|
||||
cmd__append(&cmd, 1, link_libs[i]);
|
||||
}
|
||||
if (!cmd_run(&cmd)) return 1;
|
||||
}
|
||||
|
||||
// Clean up obj files
|
||||
delete_file(temp_sprintf("%s/daw_main.obj", build_dir));
|
||||
|
||||
build_log(LOG_INFO, "Build complete: %s/autosample.exe", build_dir);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
600
build.h
Normal file
600
build.h
Normal file
@@ -0,0 +1,600 @@
|
||||
// build.h — Minimal C build system (stb-style single header)
|
||||
//
|
||||
// Define BUILD_IMPLEMENTATION in exactly one file before including this header.
|
||||
//
|
||||
// Bootstrap (one-time):
|
||||
// Windows: cl /nologo build.c
|
||||
// macOS: cc build.c -o build
|
||||
// After that, just run ./build (or build.exe) — it rebuilds itself.
|
||||
|
||||
#ifndef BUILD_H
|
||||
#define BUILD_H
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
# include <direct.h>
|
||||
# include <io.h>
|
||||
#else
|
||||
# include <sys/stat.h>
|
||||
# include <sys/wait.h>
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
// Macros
|
||||
|
||||
#define ARRAY_LEN(a) (sizeof(a) / sizeof((a)[0]))
|
||||
|
||||
// Self-rebuild: call at the top of main(). Recompiles the build script
|
||||
// if the source file is newer than the running binary, then re-executes.
|
||||
#define GO_REBUILD_URSELF(argc, argv) \
|
||||
go_rebuild_urself((argc), (argv), __FILE__)
|
||||
|
||||
////////////////////////////////
|
||||
// Logging
|
||||
|
||||
typedef enum {
|
||||
LOG_INFO,
|
||||
LOG_WARNING,
|
||||
LOG_ERROR,
|
||||
} Log_Level;
|
||||
|
||||
void build_log(Log_Level level, const char *fmt, ...);
|
||||
|
||||
////////////////////////////////
|
||||
// Temp allocator — ring buffer for short-lived sprintf results
|
||||
|
||||
#ifndef TEMP_CAPACITY
|
||||
#define TEMP_CAPACITY (8 * 1024 * 1024)
|
||||
#endif
|
||||
|
||||
char *temp_sprintf(const char *fmt, ...);
|
||||
void temp_reset(void);
|
||||
|
||||
////////////////////////////////
|
||||
// String builder — growable byte buffer
|
||||
|
||||
typedef struct {
|
||||
char *items;
|
||||
size_t count;
|
||||
size_t capacity;
|
||||
} String_Builder;
|
||||
|
||||
bool sb_read_file(String_Builder *sb, const char *path);
|
||||
void sb_free(String_Builder *sb);
|
||||
|
||||
////////////////////////////////
|
||||
// File I/O
|
||||
|
||||
bool write_entire_file(const char *path, const void *data, size_t size);
|
||||
bool delete_file(const char *path);
|
||||
bool rename_file(const char *old_path, const char *new_path);
|
||||
bool mkdir_if_not_exists(const char *path);
|
||||
|
||||
////////////////////////////////
|
||||
// Rebuild checking — returns 1 if rebuild needed, 0 if up to date, -1 on error
|
||||
|
||||
int needs_rebuild(const char *output, const char **inputs, size_t count);
|
||||
int needs_rebuild1(const char *output, const char *input);
|
||||
|
||||
////////////////////////////////
|
||||
// Command builder and runner
|
||||
|
||||
typedef struct {
|
||||
const char **items;
|
||||
size_t count;
|
||||
size_t capacity;
|
||||
} Cmd;
|
||||
|
||||
// Appends arguments to a command. Use via the macro which auto-counts args.
|
||||
void cmd__append(Cmd *cmd, size_t n, ...);
|
||||
void cmd__append_arr(Cmd *cmd, const char **args, size_t n);
|
||||
#define cmd_append(cmd, ...) do { \
|
||||
const char *_cmd_args[] = {__VA_ARGS__}; \
|
||||
cmd__append_arr((cmd), _cmd_args, sizeof(_cmd_args) / sizeof(_cmd_args[0])); \
|
||||
} while(0)
|
||||
|
||||
// Runs the command synchronously, resets cmd->count to 0, returns success.
|
||||
bool cmd_run(Cmd *cmd);
|
||||
|
||||
// Frees the command's allocated memory.
|
||||
void cmd_free(Cmd *cmd);
|
||||
|
||||
////////////////////////////////
|
||||
// Self-rebuild
|
||||
|
||||
void go_rebuild_urself(int argc, char **argv, const char *source);
|
||||
|
||||
#endif // BUILD_H
|
||||
|
||||
////////////////////////////////
|
||||
// Implementation
|
||||
////////////////////////////////
|
||||
|
||||
#ifdef BUILD_IMPLEMENTATION
|
||||
|
||||
////////////////////////////////
|
||||
// Temp allocator
|
||||
|
||||
static size_t g_temp_size = 0;
|
||||
static char g_temp[TEMP_CAPACITY];
|
||||
|
||||
void temp_reset(void) {
|
||||
g_temp_size = 0;
|
||||
}
|
||||
|
||||
static char *temp_alloc(size_t size) {
|
||||
if (g_temp_size + size > TEMP_CAPACITY) {
|
||||
g_temp_size = 0; // wrap around
|
||||
}
|
||||
char *result = g_temp + g_temp_size;
|
||||
g_temp_size += size;
|
||||
return result;
|
||||
}
|
||||
|
||||
char *temp_sprintf(const char *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
va_list args2;
|
||||
va_copy(args2, args);
|
||||
int n = vsnprintf(NULL, 0, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
char *result = temp_alloc(n + 1);
|
||||
vsnprintf(result, n + 1, fmt, args2);
|
||||
va_end(args2);
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Logging
|
||||
|
||||
void build_log(Log_Level level, const char *fmt, ...) {
|
||||
switch (level) {
|
||||
case LOG_INFO: fprintf(stderr, "[INFO] "); break;
|
||||
case LOG_WARNING: fprintf(stderr, "[WARNING] "); break;
|
||||
case LOG_ERROR: fprintf(stderr, "[ERROR] "); break;
|
||||
}
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// String builder
|
||||
|
||||
static void sb_ensure(String_Builder *sb, size_t needed) {
|
||||
if (sb->count + needed <= sb->capacity) return;
|
||||
size_t new_cap = sb->capacity ? sb->capacity * 2 : 256;
|
||||
while (new_cap < sb->count + needed) new_cap *= 2;
|
||||
sb->items = (char *)realloc(sb->items, new_cap);
|
||||
sb->capacity = new_cap;
|
||||
}
|
||||
|
||||
bool sb_read_file(String_Builder *sb, const char *path) {
|
||||
FILE *f = fopen(path, "rb");
|
||||
if (!f) {
|
||||
build_log(LOG_ERROR, "Could not open %s: %s", path, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
#ifdef _WIN32
|
||||
long long m = _telli64(_fileno(f));
|
||||
#else
|
||||
long long m = ftell(f);
|
||||
#endif
|
||||
if (m < 0) {
|
||||
build_log(LOG_ERROR, "Could not get size of %s: %s", path, strerror(errno));
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
sb_ensure(sb, (size_t)m);
|
||||
fread(sb->items + sb->count, (size_t)m, 1, f);
|
||||
if (ferror(f)) {
|
||||
build_log(LOG_ERROR, "Could not read %s: %s", path, strerror(errno));
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
sb->count += (size_t)m;
|
||||
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
void sb_free(String_Builder *sb) {
|
||||
free(sb->items);
|
||||
sb->items = NULL;
|
||||
sb->count = 0;
|
||||
sb->capacity = 0;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// File I/O
|
||||
|
||||
bool write_entire_file(const char *path, const void *data, size_t size) {
|
||||
FILE *f = fopen(path, "wb");
|
||||
if (!f) {
|
||||
build_log(LOG_ERROR, "Could not open %s for writing: %s", path, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
const char *buf = (const char *)data;
|
||||
while (size > 0) {
|
||||
size_t n = fwrite(buf, 1, size, f);
|
||||
if (ferror(f)) {
|
||||
build_log(LOG_ERROR, "Could not write to %s: %s", path, strerror(errno));
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
size -= n;
|
||||
buf += n;
|
||||
}
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool delete_file(const char *path) {
|
||||
build_log(LOG_INFO, "Deleting %s", path);
|
||||
#ifdef _WIN32
|
||||
DWORD attr = GetFileAttributesA(path);
|
||||
if (attr == INVALID_FILE_ATTRIBUTES) return true; // doesn't exist
|
||||
if (attr & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
if (!RemoveDirectoryA(path)) {
|
||||
build_log(LOG_ERROR, "Could not delete directory %s", path);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!DeleteFileA(path)) {
|
||||
build_log(LOG_ERROR, "Could not delete file %s", path);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (remove(path) < 0 && errno != ENOENT) {
|
||||
build_log(LOG_ERROR, "Could not delete %s: %s", path, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool rename_file(const char *old_path, const char *new_path) {
|
||||
build_log(LOG_INFO, "Renaming %s -> %s", old_path, new_path);
|
||||
#ifdef _WIN32
|
||||
if (!MoveFileEx(old_path, new_path, MOVEFILE_REPLACE_EXISTING)) {
|
||||
build_log(LOG_ERROR, "Could not rename %s to %s", old_path, new_path);
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
if (rename(old_path, new_path) < 0) {
|
||||
build_log(LOG_ERROR, "Could not rename %s to %s: %s", old_path, new_path, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool mkdir_if_not_exists(const char *path) {
|
||||
#ifdef _WIN32
|
||||
int result = _mkdir(path);
|
||||
#else
|
||||
int result = mkdir(path, 0755);
|
||||
#endif
|
||||
if (result < 0) {
|
||||
if (errno == EEXIST) return true;
|
||||
build_log(LOG_ERROR, "Could not create directory %s: %s", path, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
build_log(LOG_INFO, "Created directory %s", path);
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Rebuild checking
|
||||
|
||||
int needs_rebuild(const char *output, const char **inputs, size_t count) {
|
||||
#ifdef _WIN32
|
||||
HANDLE out_h = CreateFile(output, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
|
||||
if (out_h == INVALID_HANDLE_VALUE) {
|
||||
if (GetLastError() == ERROR_FILE_NOT_FOUND) return 1;
|
||||
build_log(LOG_ERROR, "Could not open %s", output);
|
||||
return -1;
|
||||
}
|
||||
FILETIME out_time;
|
||||
if (!GetFileTime(out_h, NULL, NULL, &out_time)) {
|
||||
CloseHandle(out_h);
|
||||
build_log(LOG_ERROR, "Could not get time of %s", output);
|
||||
return -1;
|
||||
}
|
||||
CloseHandle(out_h);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
HANDLE in_h = CreateFile(inputs[i], GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
|
||||
if (in_h == INVALID_HANDLE_VALUE) {
|
||||
build_log(LOG_ERROR, "Could not open %s", inputs[i]);
|
||||
return -1;
|
||||
}
|
||||
FILETIME in_time;
|
||||
if (!GetFileTime(in_h, NULL, NULL, &in_time)) {
|
||||
CloseHandle(in_h);
|
||||
build_log(LOG_ERROR, "Could not get time of %s", inputs[i]);
|
||||
return -1;
|
||||
}
|
||||
CloseHandle(in_h);
|
||||
if (CompareFileTime(&in_time, &out_time) == 1) return 1;
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
struct stat sb;
|
||||
memset(&sb, 0, sizeof(sb));
|
||||
if (stat(output, &sb) < 0) {
|
||||
if (errno == ENOENT) return 1;
|
||||
build_log(LOG_ERROR, "Could not stat %s: %s", output, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
time_t out_time = sb.st_mtime;
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
if (stat(inputs[i], &sb) < 0) {
|
||||
build_log(LOG_ERROR, "Could not stat %s: %s", inputs[i], strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (sb.st_mtime > out_time) return 1;
|
||||
}
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int needs_rebuild1(const char *output, const char *input) {
|
||||
return needs_rebuild(output, &input, 1);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Command builder and runner
|
||||
|
||||
static void cmd__grow(Cmd *cmd) {
|
||||
size_t new_cap = cmd->capacity ? cmd->capacity * 2 : 32;
|
||||
cmd->items = (const char **)realloc(cmd->items, new_cap * sizeof(const char *));
|
||||
cmd->capacity = new_cap;
|
||||
}
|
||||
|
||||
void cmd__append(Cmd *cmd, size_t n, ...) {
|
||||
va_list args;
|
||||
va_start(args, n);
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
const char *arg = va_arg(args, const char *);
|
||||
if (cmd->count >= cmd->capacity) cmd__grow(cmd);
|
||||
cmd->items[cmd->count++] = arg;
|
||||
}
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void cmd__append_arr(Cmd *cmd, const char **args, size_t n) {
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
if (cmd->count >= cmd->capacity) cmd__grow(cmd);
|
||||
cmd->items[cmd->count++] = args[i];
|
||||
}
|
||||
}
|
||||
|
||||
static void cmd_render(Cmd *cmd, char *buf, size_t buf_size) {
|
||||
size_t pos = 0;
|
||||
for (size_t i = 0; i < cmd->count && pos < buf_size - 1; i++) {
|
||||
if (i > 0 && pos < buf_size - 1) buf[pos++] = ' ';
|
||||
const char *arg = cmd->items[i];
|
||||
size_t len = strlen(arg);
|
||||
if (pos + len < buf_size - 1) {
|
||||
memcpy(buf + pos, arg, len);
|
||||
pos += len;
|
||||
}
|
||||
}
|
||||
buf[pos] = '\0';
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
// Properly quote a command line for CreateProcess on Windows.
|
||||
static void cmd_quote_win32(Cmd *cmd, String_Builder *quoted) {
|
||||
for (size_t i = 0; i < cmd->count; i++) {
|
||||
const char *arg = cmd->items[i];
|
||||
size_t len = strlen(arg);
|
||||
if (i > 0) {
|
||||
sb_ensure(quoted, 1);
|
||||
quoted->items[quoted->count++] = ' ';
|
||||
}
|
||||
if (len != 0 && strpbrk(arg, " \t\n\v\"") == NULL) {
|
||||
sb_ensure(quoted, len);
|
||||
memcpy(quoted->items + quoted->count, arg, len);
|
||||
quoted->count += len;
|
||||
} else {
|
||||
sb_ensure(quoted, len * 2 + 3);
|
||||
quoted->items[quoted->count++] = '"';
|
||||
size_t backslashes = 0;
|
||||
for (size_t j = 0; j < len; j++) {
|
||||
char c = arg[j];
|
||||
if (c == '\\') {
|
||||
backslashes++;
|
||||
} else {
|
||||
if (c == '"') {
|
||||
for (size_t k = 0; k < backslashes + 1; k++)
|
||||
quoted->items[quoted->count++] = '\\';
|
||||
}
|
||||
backslashes = 0;
|
||||
}
|
||||
quoted->items[quoted->count++] = c;
|
||||
}
|
||||
for (size_t k = 0; k < backslashes; k++)
|
||||
quoted->items[quoted->count++] = '\\';
|
||||
quoted->items[quoted->count++] = '"';
|
||||
}
|
||||
}
|
||||
sb_ensure(quoted, 1);
|
||||
quoted->items[quoted->count] = '\0';
|
||||
}
|
||||
#endif
|
||||
|
||||
bool cmd_run(Cmd *cmd) {
|
||||
if (cmd->count == 0) {
|
||||
build_log(LOG_ERROR, "Cannot run empty command");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Log the command
|
||||
{
|
||||
char render_buf[4096];
|
||||
cmd_render(cmd, render_buf, sizeof(render_buf));
|
||||
build_log(LOG_INFO, "CMD: %s", render_buf);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
STARTUPINFO si;
|
||||
memset(&si, 0, sizeof(si));
|
||||
si.cb = sizeof(si);
|
||||
si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
|
||||
si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
|
||||
si.dwFlags |= STARTF_USESTDHANDLES;
|
||||
|
||||
PROCESS_INFORMATION pi;
|
||||
memset(&pi, 0, sizeof(pi));
|
||||
|
||||
String_Builder quoted = {0};
|
||||
cmd_quote_win32(cmd, "ed);
|
||||
|
||||
BOOL ok = CreateProcessA(NULL, quoted.items, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
|
||||
sb_free("ed);
|
||||
|
||||
cmd->count = 0;
|
||||
|
||||
if (!ok) {
|
||||
build_log(LOG_ERROR, "Could not create process for %s", cmd->items[0]);
|
||||
return false;
|
||||
}
|
||||
|
||||
CloseHandle(pi.hThread);
|
||||
WaitForSingleObject(pi.hProcess, INFINITE);
|
||||
|
||||
DWORD exit_code;
|
||||
if (!GetExitCodeProcess(pi.hProcess, &exit_code)) {
|
||||
build_log(LOG_ERROR, "Could not get exit code");
|
||||
CloseHandle(pi.hProcess);
|
||||
return false;
|
||||
}
|
||||
CloseHandle(pi.hProcess);
|
||||
|
||||
if (exit_code != 0) {
|
||||
build_log(LOG_ERROR, "Command exited with code %lu", exit_code);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
pid_t pid = fork();
|
||||
if (pid < 0) {
|
||||
build_log(LOG_ERROR, "Could not fork: %s", strerror(errno));
|
||||
cmd->count = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pid == 0) {
|
||||
// Child: build null-terminated argv
|
||||
const char **argv_null = (const char **)malloc((cmd->count + 1) * sizeof(const char *));
|
||||
memcpy(argv_null, cmd->items, cmd->count * sizeof(const char *));
|
||||
argv_null[cmd->count] = NULL;
|
||||
execvp(argv_null[0], (char *const *)argv_null);
|
||||
build_log(LOG_ERROR, "Could not exec %s: %s", argv_null[0], strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
cmd->count = 0;
|
||||
|
||||
int wstatus;
|
||||
for (;;) {
|
||||
if (waitpid(pid, &wstatus, 0) < 0) {
|
||||
build_log(LOG_ERROR, "Could not wait on pid %d: %s", pid, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
if (WIFEXITED(wstatus)) {
|
||||
int code = WEXITSTATUS(wstatus);
|
||||
if (code != 0) {
|
||||
build_log(LOG_ERROR, "Command exited with code %d", code);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (WIFSIGNALED(wstatus)) {
|
||||
build_log(LOG_ERROR, "Command killed by signal %d", WTERMSIG(wstatus));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void cmd_free(Cmd *cmd) {
|
||||
free(cmd->items);
|
||||
cmd->items = NULL;
|
||||
cmd->count = 0;
|
||||
cmd->capacity = 0;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Self-rebuild
|
||||
|
||||
#ifdef _WIN32
|
||||
# define REBUILD_CMD(binary, source) "cl.exe", "/nologo", temp_sprintf("/Fe:%s", binary), source
|
||||
#else
|
||||
# define REBUILD_CMD(binary, source) "cc", "-o", binary, source
|
||||
#endif
|
||||
|
||||
void go_rebuild_urself(int argc, char **argv, const char *source) {
|
||||
const char *binary = argv[0];
|
||||
|
||||
#ifdef _WIN32
|
||||
// Ensure .exe extension for Windows
|
||||
size_t len = strlen(binary);
|
||||
if (len < 4 || strcmp(binary + len - 4, ".exe") != 0) {
|
||||
binary = temp_sprintf("%s.exe", binary);
|
||||
}
|
||||
#endif
|
||||
|
||||
int rebuild = needs_rebuild1(binary, source);
|
||||
if (rebuild < 0) exit(1);
|
||||
if (rebuild == 0) return;
|
||||
|
||||
const char *old_binary = temp_sprintf("%s.old", binary);
|
||||
if (!rename_file(binary, old_binary)) exit(1);
|
||||
|
||||
Cmd cmd = {0};
|
||||
cmd_append(&cmd, REBUILD_CMD(binary, source));
|
||||
if (!cmd_run(&cmd)) {
|
||||
rename_file(old_binary, binary);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Re-execute with the new binary
|
||||
cmd_append(&cmd, binary);
|
||||
{
|
||||
int i;
|
||||
for (i = 1; i < argc; i++) {
|
||||
cmd__append(&cmd, 1, argv[i]);
|
||||
}
|
||||
}
|
||||
if (!cmd_run(&cmd)) exit(1);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#endif // BUILD_IMPLEMENTATION
|
||||
24
compile_commands.json
Normal file
24
compile_commands.json
Normal file
@@ -0,0 +1,24 @@
|
||||
[
|
||||
{
|
||||
"directory": "/Users/mta/projects/autosample",
|
||||
"file": "src/main.cpp",
|
||||
"arguments": [
|
||||
"clang++",
|
||||
"-std=c++20",
|
||||
"-x", "objective-c++",
|
||||
"-fno-exceptions",
|
||||
"-fno-rtti",
|
||||
"-Isrc",
|
||||
"-Ivendor/clay",
|
||||
"-Ivendor/lunasvg/include",
|
||||
"-DLUNASVG_BUILD_STATIC",
|
||||
"-D_DEBUG",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Wno-missing-field-initializers",
|
||||
"-Wno-deprecated-declarations",
|
||||
"-c",
|
||||
"src/main.cpp"
|
||||
]
|
||||
}
|
||||
]
|
||||
48
imgui.ini
48
imgui.ini
@@ -1,48 +0,0 @@
|
||||
[Window][Browser]
|
||||
Pos=0,0
|
||||
Size=191,700
|
||||
Collapsed=0
|
||||
DockId=0x00000001,0
|
||||
|
||||
[Window][Main]
|
||||
Pos=193,0
|
||||
Size=868,523
|
||||
Collapsed=0
|
||||
DockId=0x00000005,0
|
||||
|
||||
[Window][Properties]
|
||||
Pos=1063,0
|
||||
Size=217,700
|
||||
Collapsed=0
|
||||
DockId=0x00000004,0
|
||||
|
||||
[Window][Log]
|
||||
Pos=193,525
|
||||
Size=868,175
|
||||
Collapsed=0
|
||||
DockId=0x00000006,0
|
||||
|
||||
[Window][WindowOverViewport_11111111]
|
||||
Pos=0,0
|
||||
Size=1280,700
|
||||
Collapsed=0
|
||||
|
||||
[Window][Debug##Default]
|
||||
Pos=60,60
|
||||
Size=400,400
|
||||
Collapsed=0
|
||||
|
||||
[Window][Dear ImGui Demo]
|
||||
Pos=650,20
|
||||
Size=550,680
|
||||
Collapsed=0
|
||||
|
||||
[Docking][Data]
|
||||
DockSpace ID=0xF8498067 Window=0x1BBC0F80 Pos=0,0 Size=1280,700 Split=X
|
||||
DockNode ID=0x00000001 Parent=0xF8498067 SizeRef=191,700 Selected=0x54719807
|
||||
DockNode ID=0x00000002 Parent=0xF8498067 SizeRef=1087,700 Split=X
|
||||
DockNode ID=0x00000003 Parent=0x00000002 SizeRef=868,700 Split=Y
|
||||
DockNode ID=0x00000005 Parent=0x00000003 SizeRef=868,523 CentralNode=1 Selected=0x3E095604
|
||||
DockNode ID=0x00000006 Parent=0x00000003 SizeRef=868,175 Selected=0x139FDA3F
|
||||
DockNode ID=0x00000004 Parent=0x00000002 SizeRef=217,700 Selected=0x8C72BEA8
|
||||
|
||||
152
nob.c
152
nob.c
@@ -1,152 +0,0 @@
|
||||
// Bootstrap: cl /nologo nob.c
|
||||
// After that, just run: nob.exe
|
||||
|
||||
#define NOB_IMPLEMENTATION
|
||||
#include "nob.h"
|
||||
|
||||
#define BUILD_DIR "build"
|
||||
#define IMGUI_LIB_DEBUG BUILD_DIR "/imgui_d.lib"
|
||||
#define IMGUI_LIB_RELEASE BUILD_DIR "/imgui.lib"
|
||||
|
||||
static const char *src_files[] = {
|
||||
"src/main.cpp",
|
||||
};
|
||||
|
||||
static const char *imgui_files[] = {
|
||||
"vendor/imgui/imgui.cpp",
|
||||
"vendor/imgui/imgui_draw.cpp",
|
||||
"vendor/imgui/imgui_tables.cpp",
|
||||
"vendor/imgui/imgui_widgets.cpp",
|
||||
"vendor/imgui/imgui_demo.cpp",
|
||||
"vendor/imgui/backends/imgui_impl_win32.cpp",
|
||||
"vendor/imgui/backends/imgui_impl_dx12.cpp",
|
||||
};
|
||||
|
||||
static const char *link_libs[] = {
|
||||
"d3d12.lib",
|
||||
"dxgi.lib",
|
||||
"d3dcompiler.lib",
|
||||
"user32.lib",
|
||||
"gdi32.lib",
|
||||
"shell32.lib",
|
||||
"ole32.lib",
|
||||
"dwmapi.lib",
|
||||
"winmm.lib",
|
||||
};
|
||||
|
||||
static const char *obj_name(const char *src_path) {
|
||||
const char *slash = strrchr(src_path, '/');
|
||||
const char *name = slash ? slash + 1 : src_path;
|
||||
size_t len = strlen(name);
|
||||
return nob_temp_sprintf("%s/%.*s.obj", BUILD_DIR, (int)(len - 4), name);
|
||||
}
|
||||
|
||||
static bool build_imgui_lib(bool debug) {
|
||||
const char *lib_path = debug ? IMGUI_LIB_DEBUG : IMGUI_LIB_RELEASE;
|
||||
|
||||
int need = nob_needs_rebuild(lib_path, imgui_files, NOB_ARRAY_LEN(imgui_files));
|
||||
if (need < 0) return false;
|
||||
if (!need) {
|
||||
nob_log(NOB_INFO, "%s is up to date", lib_path);
|
||||
return true;
|
||||
}
|
||||
|
||||
nob_log(NOB_INFO, "Building %s...", lib_path);
|
||||
|
||||
Nob_Cmd cmd = {0};
|
||||
nob_cmd_append(&cmd, "cl.exe");
|
||||
nob_cmd_append(&cmd, "/nologo", "/std:c++17", "/EHsc", "/W3", "/c");
|
||||
nob_cmd_append(&cmd, "/Ivendor/imgui", "/Ivendor/imgui/backends");
|
||||
|
||||
if (debug) {
|
||||
nob_cmd_append(&cmd, "/MTd", "/Zi", "/Od", "/D_DEBUG");
|
||||
} else {
|
||||
nob_cmd_append(&cmd, "/MT", "/O2", "/DNDEBUG");
|
||||
}
|
||||
|
||||
nob_cmd_append(&cmd, nob_temp_sprintf("/Fo:%s/", BUILD_DIR));
|
||||
nob_cmd_append(&cmd, nob_temp_sprintf("/Fd:%s/", BUILD_DIR));
|
||||
|
||||
for (size_t i = 0; i < NOB_ARRAY_LEN(imgui_files); i++)
|
||||
nob_cmd_append(&cmd, imgui_files[i]);
|
||||
|
||||
if (!nob_cmd_run(&cmd)) return false;
|
||||
|
||||
// Archive .obj files into a .lib
|
||||
cmd.count = 0;
|
||||
nob_cmd_append(&cmd, "lib.exe", "/nologo", "/MACHINE:X64");
|
||||
nob_cmd_append(&cmd, nob_temp_sprintf("/OUT:%s", lib_path));
|
||||
|
||||
for (size_t i = 0; i < NOB_ARRAY_LEN(imgui_files); i++)
|
||||
nob_cmd_append(&cmd, obj_name(imgui_files[i]));
|
||||
|
||||
if (!nob_cmd_run(&cmd)) return false;
|
||||
|
||||
// Clean up imgui .obj files
|
||||
for (size_t i = 0; i < NOB_ARRAY_LEN(imgui_files); i++)
|
||||
nob_delete_file(obj_name(imgui_files[i]));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
NOB_GO_REBUILD_URSELF(argc, argv);
|
||||
|
||||
bool debug = false;
|
||||
bool clean = false;
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "debug") == 0) debug = true;
|
||||
else if (strcmp(argv[i], "clean") == 0) clean = true;
|
||||
}
|
||||
|
||||
if (clean) {
|
||||
nob_log(NOB_INFO, "Cleaning %s/", BUILD_DIR);
|
||||
Nob_Cmd cmd = {0};
|
||||
nob_cmd_append(&cmd, "cmd.exe", "/c", "if exist " BUILD_DIR " rmdir /s /q " BUILD_DIR);
|
||||
if (!nob_cmd_run(&cmd)) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!nob_mkdir_if_not_exists(BUILD_DIR)) return 1;
|
||||
|
||||
// Build vendor libs (unless already built)
|
||||
if (!build_imgui_lib(debug)) return 1;
|
||||
|
||||
// Compile and link
|
||||
Nob_Cmd cmd = {0};
|
||||
|
||||
nob_cmd_append(&cmd, "cl.exe");
|
||||
nob_cmd_append(&cmd, "/nologo", "/std:c++17", "/EHsc", "/W3");
|
||||
nob_cmd_append(&cmd, "/Isrc", "/Ivendor/imgui", "/Ivendor/imgui/backends");
|
||||
|
||||
if (debug) {
|
||||
nob_cmd_append(&cmd, "/MTd", "/Zi", "/Od", "/D_DEBUG");
|
||||
} else {
|
||||
nob_cmd_append(&cmd, "/MT", "/Zi", "/O2", "/DNDEBUG");
|
||||
}
|
||||
|
||||
nob_cmd_append(&cmd, nob_temp_sprintf("/Fe:%s/autosample.exe", BUILD_DIR));
|
||||
nob_cmd_append(&cmd, nob_temp_sprintf("/Fo:%s/", BUILD_DIR));
|
||||
nob_cmd_append(&cmd, nob_temp_sprintf("/Fd:%s/autosample.pdb", BUILD_DIR));
|
||||
|
||||
for (size_t i = 0; i < NOB_ARRAY_LEN(src_files); i++)
|
||||
nob_cmd_append(&cmd, src_files[i]);
|
||||
|
||||
nob_cmd_append(&cmd, "/link");
|
||||
nob_cmd_append(&cmd, "/MACHINE:X64");
|
||||
nob_cmd_append(&cmd, "/SUBSYSTEM:CONSOLE");
|
||||
nob_cmd_append(&cmd, nob_temp_sprintf("/PDB:%s/autosample.pdb", BUILD_DIR));
|
||||
nob_cmd_append(&cmd, "/DEBUG");
|
||||
nob_cmd_append(&cmd, debug ? IMGUI_LIB_DEBUG : IMGUI_LIB_RELEASE);
|
||||
for (size_t i = 0; i < NOB_ARRAY_LEN(link_libs); i++)
|
||||
nob_cmd_append(&cmd, link_libs[i]);
|
||||
|
||||
if (!nob_cmd_run(&cmd)) return 1;
|
||||
|
||||
// Clean up .obj files
|
||||
for (size_t i = 0; i < NOB_ARRAY_LEN(src_files); i++)
|
||||
nob_delete_file(obj_name(src_files[i]));
|
||||
|
||||
nob_log(NOB_INFO, "Build complete: %s/autosample.exe", BUILD_DIR);
|
||||
return 0;
|
||||
}
|
||||
23
src/audio/audio.h
Normal file
23
src/audio/audio.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "base/base_core.h"
|
||||
|
||||
typedef struct AudioEngine AudioEngine;
|
||||
|
||||
typedef struct AudioDeviceInfo {
|
||||
char name[128];
|
||||
S32 id; // index into engine's device list
|
||||
} AudioDeviceInfo;
|
||||
|
||||
AudioEngine *audio_create(void *hwnd);
|
||||
void audio_destroy(AudioEngine *engine);
|
||||
void audio_refresh_devices(AudioEngine *engine);
|
||||
S32 audio_get_device_count(AudioEngine *engine);
|
||||
AudioDeviceInfo*audio_get_device(AudioEngine *engine, S32 index);
|
||||
|
||||
B32 audio_open_device(AudioEngine *engine, S32 index);
|
||||
void audio_close_device(AudioEngine *engine);
|
||||
|
||||
void audio_play_test_tone(AudioEngine *engine);
|
||||
B32 audio_is_test_tone_playing(AudioEngine *engine);
|
||||
void audio_update(AudioEngine *engine, F32 dt);
|
||||
576
src/audio/audio_asio.c
Normal file
576
src/audio/audio_asio.c
Normal file
@@ -0,0 +1,576 @@
|
||||
#include "audio/audio.h"
|
||||
#include <windows.h>
|
||||
#include <objbase.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#define AUDIO_MAX_DEVICES 32
|
||||
#define AUDIO_MAX_CHANNELS 32
|
||||
#define AUDIO_TEST_TONE_HZ 440.0
|
||||
#define AUDIO_TEST_TONE_SEC 2.0
|
||||
#define AUDIO_PI 3.14159265358979323846
|
||||
|
||||
////////////////////////////////
|
||||
// ASIO type definitions (minimal set for a host)
|
||||
|
||||
typedef long ASIOError;
|
||||
typedef long ASIOBool;
|
||||
typedef long long int ASIOSamples;
|
||||
typedef long long int ASIOTimeStamp;
|
||||
|
||||
enum {
|
||||
ASE_OK = 0,
|
||||
ASE_SUCCESS = 0x3f4847a0,
|
||||
ASE_NotPresent = -1000,
|
||||
ASE_HWMalfunction = -999,
|
||||
ASE_InvalidParameter = -998,
|
||||
ASE_InvalidMode = -997,
|
||||
ASE_SPNotAdvancing = -996,
|
||||
ASE_NoClock = -995,
|
||||
ASE_NoMemory = -994,
|
||||
};
|
||||
|
||||
typedef enum ASIOSampleType {
|
||||
ASIOSTInt16MSB = 0,
|
||||
ASIOSTInt24MSB = 1,
|
||||
ASIOSTInt32MSB = 2,
|
||||
ASIOSTFloat32MSB = 3,
|
||||
ASIOSTFloat64MSB = 4,
|
||||
|
||||
ASIOSTInt32MSB16 = 8,
|
||||
ASIOSTInt32MSB18 = 9,
|
||||
ASIOSTInt32MSB20 = 10,
|
||||
ASIOSTInt32MSB24 = 11,
|
||||
|
||||
ASIOSTInt16LSB = 16,
|
||||
ASIOSTInt24LSB = 17,
|
||||
ASIOSTInt32LSB = 18,
|
||||
ASIOSTFloat32LSB = 19,
|
||||
ASIOSTFloat64LSB = 20,
|
||||
|
||||
ASIOSTInt32LSB16 = 24,
|
||||
ASIOSTInt32LSB18 = 25,
|
||||
ASIOSTInt32LSB20 = 26,
|
||||
ASIOSTInt32LSB24 = 27,
|
||||
} ASIOSampleType;
|
||||
|
||||
typedef struct ASIOClockSource {
|
||||
long index;
|
||||
long channel;
|
||||
long group;
|
||||
ASIOBool isCurrentSource;
|
||||
char name[32];
|
||||
} ASIOClockSource;
|
||||
|
||||
typedef struct ASIOChannelInfo {
|
||||
long channel;
|
||||
ASIOBool isInput;
|
||||
ASIOBool isActive;
|
||||
long channelGroup;
|
||||
ASIOSampleType type;
|
||||
char name[32];
|
||||
} ASIOChannelInfo;
|
||||
|
||||
typedef struct ASIOBufferInfo {
|
||||
ASIOBool isInput;
|
||||
long channelNum;
|
||||
void *buffers[2]; // F64 buffer
|
||||
} ASIOBufferInfo;
|
||||
|
||||
typedef struct ASIOTimeCode {
|
||||
F64 speed;
|
||||
ASIOSamples timeCodeSamples;
|
||||
unsigned long flags;
|
||||
char future[64];
|
||||
} ASIOTimeCode;
|
||||
|
||||
typedef struct AsioTimeInfo {
|
||||
F64 speed;
|
||||
ASIOTimeStamp systemTime;
|
||||
ASIOSamples samplePosition;
|
||||
F64 sampleRate;
|
||||
unsigned long flags;
|
||||
char reserved[12];
|
||||
} AsioTimeInfo;
|
||||
|
||||
typedef struct ASIOTime {
|
||||
long reserved[4];
|
||||
AsioTimeInfo timeInfo;
|
||||
ASIOTimeCode timeCode;
|
||||
} ASIOTime;
|
||||
|
||||
typedef struct ASIOCallbacks {
|
||||
void (*bufferSwitch)(long doubleBufferIndex, ASIOBool directProcess);
|
||||
void (*sampleRateDidChange)(F64 sRate);
|
||||
long (*asioMessage)(long selector, long value, void *message, F64 *opt);
|
||||
ASIOTime *(*bufferSwitchTimeInfo)(ASIOTime *params, long doubleBufferIndex, ASIOBool directProcess);
|
||||
} ASIOCallbacks;
|
||||
|
||||
// ASIO message selectors
|
||||
enum {
|
||||
kAsioSelectorSupported = 1,
|
||||
kAsioEngineVersion,
|
||||
kAsioResetRequest,
|
||||
kAsioBufferSizeChange,
|
||||
kAsioResyncRequest,
|
||||
kAsioLatenciesChanged,
|
||||
kAsioSupportsTimeInfo,
|
||||
kAsioSupportsTimeCode,
|
||||
kAsioSupportsInputMonitor,
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
// IASIO COM interface (C vtable)
|
||||
// Standard ASIO vtable — inherits IUnknown
|
||||
|
||||
typedef struct IASIOVtbl {
|
||||
// IUnknown
|
||||
HRESULT (STDMETHODCALLTYPE *QueryInterface)(void *this_, REFIID riid, void **ppvObject);
|
||||
ULONG (STDMETHODCALLTYPE *AddRef)(void *this_);
|
||||
ULONG (STDMETHODCALLTYPE *Release)(void *this_);
|
||||
// IASIO
|
||||
ASIOBool (*init)(void *this_, void *sysHandle);
|
||||
void (*getDriverName)(void *this_, char *name);
|
||||
long (*getDriverVersion)(void *this_);
|
||||
void (*getErrorMessage)(void *this_, char *string);
|
||||
ASIOError (*start)(void *this_);
|
||||
ASIOError (*stop)(void *this_);
|
||||
ASIOError (*getChannels)(void *this_, long *numInputChannels, long *numOutputChannels);
|
||||
ASIOError (*getLatencies)(void *this_, long *inputLatency, long *outputLatency);
|
||||
ASIOError (*getBufferSize)(void *this_, long *minSize, long *maxSize, long *preferredSize, long *granularity);
|
||||
ASIOError (*canSampleRate)(void *this_, F64 sampleRate);
|
||||
ASIOError (*getSampleRate)(void *this_, F64 *sampleRate);
|
||||
ASIOError (*setSampleRate)(void *this_, F64 sampleRate);
|
||||
ASIOError (*getClockSources)(void *this_, ASIOClockSource *clocks, long *numSources);
|
||||
ASIOError (*setClockSource)(void *this_, long reference);
|
||||
ASIOError (*getSamplePosition)(void *this_, ASIOSamples *sPos, ASIOTimeStamp *tStamp);
|
||||
ASIOError (*getChannelInfo)(void *this_, ASIOChannelInfo *info);
|
||||
ASIOError (*createBuffers)(void *this_, ASIOBufferInfo *bufferInfos, long numChannels, long bufferSize, ASIOCallbacks *callbacks);
|
||||
ASIOError (*disposeBuffers)(void *this_);
|
||||
ASIOError (*controlPanel)(void *this_);
|
||||
ASIOError (*future)(void *this_, long selector, void *opt);
|
||||
ASIOError (*outputReady)(void *this_);
|
||||
} IASIOVtbl;
|
||||
|
||||
typedef struct IASIO {
|
||||
IASIOVtbl *lpVtbl;
|
||||
} IASIO;
|
||||
|
||||
////////////////////////////////
|
||||
// Internal state
|
||||
|
||||
typedef struct AsioDriverInfo {
|
||||
char name[128];
|
||||
CLSID clsid;
|
||||
} AsioDriverInfo;
|
||||
|
||||
struct AudioEngine {
|
||||
void *hwnd; // HWND for ASIO init
|
||||
|
||||
// Device enumeration
|
||||
AudioDeviceInfo devices[AUDIO_MAX_DEVICES];
|
||||
AsioDriverInfo drivers[AUDIO_MAX_DEVICES];
|
||||
S32 device_count;
|
||||
|
||||
// Active driver
|
||||
IASIO *driver;
|
||||
S32 active_device_index; // -1 = none
|
||||
|
||||
// Buffer state
|
||||
ASIOBufferInfo buffer_infos[AUDIO_MAX_CHANNELS];
|
||||
long num_output_channels;
|
||||
long num_input_channels;
|
||||
long buffer_size;
|
||||
F64 sample_rate;
|
||||
ASIOSampleType output_sample_type;
|
||||
ASIOCallbacks callbacks;
|
||||
|
||||
// Test tone state (accessed from callback thread)
|
||||
volatile LONG test_tone_active;
|
||||
volatile LONG test_tone_samples_remaining;
|
||||
F64 test_tone_phase; // written only from callback thread
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
// Global engine pointer for ASIO callbacks (standard pattern — callbacks have no user-data param)
|
||||
|
||||
static AudioEngine *g_audio_engine = NULL;
|
||||
|
||||
////////////////////////////////
|
||||
// Sample writing helper
|
||||
|
||||
static void write_sample(void *dest, ASIOSampleType type, F64 value) {
|
||||
// Clamp to [-1, 1]
|
||||
if (value > 1.0) value = 1.0;
|
||||
if (value < -1.0) value = -1.0;
|
||||
|
||||
switch (type) {
|
||||
case ASIOSTInt16LSB: {
|
||||
S16 s = (S16)(value * 32767.0);
|
||||
memcpy(dest, &s, 2);
|
||||
} break;
|
||||
case ASIOSTInt24LSB: {
|
||||
S32 s = (S32)(value * 8388607.0);
|
||||
U8 *d = (U8 *)dest;
|
||||
d[0] = (U8)(s & 0xFF);
|
||||
d[1] = (U8)((s >> 8) & 0xFF);
|
||||
d[2] = (U8)((s >> 16) & 0xFF);
|
||||
} break;
|
||||
case ASIOSTInt32LSB: {
|
||||
S32 s = (S32)(value * 2147483647.0);
|
||||
memcpy(dest, &s, 4);
|
||||
} break;
|
||||
case ASIOSTFloat32LSB: {
|
||||
F32 f = (F32)value;
|
||||
memcpy(dest, &f, 4);
|
||||
} break;
|
||||
case ASIOSTFloat64LSB: {
|
||||
memcpy(dest, &value, 8);
|
||||
} break;
|
||||
default: {
|
||||
// Unsupported type — write silence (4 bytes of zero)
|
||||
U32 z = 0;
|
||||
memcpy(dest, &z, 4);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
static int sample_type_size(ASIOSampleType type) {
|
||||
switch (type) {
|
||||
case ASIOSTInt16LSB: return 2;
|
||||
case ASIOSTInt24LSB: return 3;
|
||||
case ASIOSTInt32LSB: return 4;
|
||||
case ASIOSTFloat32LSB: return 4;
|
||||
case ASIOSTFloat64LSB: return 8;
|
||||
default: return 4;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// ASIO callbacks (static — called from driver thread)
|
||||
|
||||
static void asio_buffer_switch(long doubleBufferIndex, ASIOBool directProcess) {
|
||||
(void)directProcess;
|
||||
|
||||
AudioEngine *engine = g_audio_engine;
|
||||
if (!engine) return;
|
||||
|
||||
long buf_size = engine->buffer_size;
|
||||
ASIOSampleType type = engine->output_sample_type;
|
||||
S32 bytes_per_sample = sample_type_size(type);
|
||||
|
||||
LONG tone_active = InterlockedCompareExchange(&engine->test_tone_active, 0, 0);
|
||||
|
||||
for (long ch = 0; ch < engine->num_output_channels; ch++) {
|
||||
void *buf = engine->buffer_infos[ch].buffers[doubleBufferIndex];
|
||||
if (!buf) continue;
|
||||
|
||||
if (tone_active) {
|
||||
// Only generate tone, don't branch per-sample for active check
|
||||
} else {
|
||||
// Silence
|
||||
memset(buf, 0, (size_t)(buf_size * bytes_per_sample));
|
||||
}
|
||||
}
|
||||
|
||||
if (tone_active) {
|
||||
F64 phase = engine->test_tone_phase;
|
||||
F64 phase_inc = 2.0 * AUDIO_PI * AUDIO_TEST_TONE_HZ / engine->sample_rate;
|
||||
LONG remaining = InterlockedCompareExchange(&engine->test_tone_samples_remaining, 0, 0);
|
||||
long samples_to_gen = (remaining < buf_size) ? (long)remaining : buf_size;
|
||||
|
||||
for (long s = 0; s < buf_size; s++) {
|
||||
F64 sample_val = 0.0;
|
||||
if (s < samples_to_gen) {
|
||||
sample_val = sin(phase) * 0.5; // -6dB to avoid clipping
|
||||
phase += phase_inc;
|
||||
if (phase >= 2.0 * AUDIO_PI) phase -= 2.0 * AUDIO_PI;
|
||||
}
|
||||
|
||||
// Write to all output channels (stereo or more)
|
||||
for (long ch = 0; ch < engine->num_output_channels; ch++) {
|
||||
void *buf = engine->buffer_infos[ch].buffers[doubleBufferIndex];
|
||||
if (!buf) continue;
|
||||
U8 *dest = (U8 *)buf + (size_t)(s * bytes_per_sample);
|
||||
write_sample(dest, type, sample_val);
|
||||
}
|
||||
}
|
||||
|
||||
engine->test_tone_phase = phase;
|
||||
|
||||
LONG new_remaining = InterlockedExchangeAdd(&engine->test_tone_samples_remaining, -samples_to_gen);
|
||||
if (new_remaining <= samples_to_gen) {
|
||||
InterlockedExchange(&engine->test_tone_active, 0);
|
||||
InterlockedExchange(&engine->test_tone_samples_remaining, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void asio_sample_rate_changed(F64 sRate) {
|
||||
AudioEngine *engine = g_audio_engine;
|
||||
if (engine) {
|
||||
engine->sample_rate = sRate;
|
||||
}
|
||||
}
|
||||
|
||||
static long asio_message(long selector, long value, void *message, F64 *opt) {
|
||||
(void)value;
|
||||
(void)message;
|
||||
(void)opt;
|
||||
|
||||
switch (selector) {
|
||||
case kAsioSelectorSupported:
|
||||
// Report which selectors we support
|
||||
if (value == kAsioEngineVersion ||
|
||||
value == kAsioResetRequest ||
|
||||
value == kAsioSupportsTimeInfo)
|
||||
return 1;
|
||||
return 0;
|
||||
case kAsioEngineVersion:
|
||||
return 2; // ASIO 2.0
|
||||
case kAsioResetRequest:
|
||||
return 1;
|
||||
case kAsioLatenciesChanged:
|
||||
return 1;
|
||||
case kAsioSupportsTimeInfo:
|
||||
return 0; // We use bufferSwitch, not bufferSwitchTimeInfo
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static ASIOTime *asio_buffer_switch_time_info(ASIOTime *params, long doubleBufferIndex, ASIOBool directProcess) {
|
||||
asio_buffer_switch(doubleBufferIndex, directProcess);
|
||||
return params;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Registry enumeration
|
||||
|
||||
static void enumerate_asio_drivers(AudioEngine *engine) {
|
||||
engine->device_count = 0;
|
||||
|
||||
HKEY asio_key;
|
||||
if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\ASIO", 0, KEY_READ, &asio_key) != ERROR_SUCCESS)
|
||||
return;
|
||||
|
||||
char subkey_name[256];
|
||||
DWORD subkey_name_len;
|
||||
|
||||
for (DWORD i = 0; engine->device_count < AUDIO_MAX_DEVICES; i++) {
|
||||
subkey_name_len = sizeof(subkey_name);
|
||||
if (RegEnumKeyExA(asio_key, i, subkey_name, &subkey_name_len, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
|
||||
break;
|
||||
|
||||
HKEY driver_key;
|
||||
if (RegOpenKeyExA(asio_key, subkey_name, 0, KEY_READ, &driver_key) != ERROR_SUCCESS)
|
||||
continue;
|
||||
|
||||
// Read CLSID string
|
||||
char clsid_str[64] = {0};
|
||||
DWORD clsid_len = sizeof(clsid_str);
|
||||
DWORD type = 0;
|
||||
if (RegQueryValueExA(driver_key, "CLSID", NULL, &type, (LPBYTE)clsid_str, &clsid_len) != ERROR_SUCCESS ||
|
||||
type != REG_SZ) {
|
||||
RegCloseKey(driver_key);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Parse CLSID string to GUID
|
||||
CLSID clsid;
|
||||
wchar_t clsid_wide[64];
|
||||
MultiByteToWideChar(CP_ACP, 0, clsid_str, -1, clsid_wide, 64);
|
||||
if (CLSIDFromString(clsid_wide, &clsid) != S_OK) {
|
||||
RegCloseKey(driver_key);
|
||||
continue;
|
||||
}
|
||||
|
||||
S32 idx = engine->device_count++;
|
||||
strncpy_s(engine->devices[idx].name, sizeof(engine->devices[idx].name), subkey_name, _TRUNCATE);
|
||||
engine->devices[idx].id = idx;
|
||||
engine->drivers[idx].clsid = clsid;
|
||||
strncpy_s(engine->drivers[idx].name, sizeof(engine->drivers[idx].name), subkey_name, _TRUNCATE);
|
||||
|
||||
RegCloseKey(driver_key);
|
||||
}
|
||||
|
||||
RegCloseKey(asio_key);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Public API
|
||||
|
||||
AudioEngine *audio_create(void *hwnd) {
|
||||
AudioEngine *engine = (AudioEngine *)calloc(1, sizeof(AudioEngine));
|
||||
engine->hwnd = hwnd;
|
||||
engine->active_device_index = -1;
|
||||
g_audio_engine = engine;
|
||||
|
||||
CoInitialize(NULL);
|
||||
enumerate_asio_drivers(engine);
|
||||
return engine;
|
||||
}
|
||||
|
||||
void audio_destroy(AudioEngine *engine) {
|
||||
audio_close_device(engine);
|
||||
if (g_audio_engine == engine) g_audio_engine = NULL;
|
||||
free(engine);
|
||||
}
|
||||
|
||||
void audio_refresh_devices(AudioEngine *engine) {
|
||||
audio_close_device(engine);
|
||||
enumerate_asio_drivers(engine);
|
||||
}
|
||||
|
||||
S32 audio_get_device_count(AudioEngine *engine) {
|
||||
return engine->device_count;
|
||||
}
|
||||
|
||||
AudioDeviceInfo *audio_get_device(AudioEngine *engine, S32 index) {
|
||||
if (index < 0 || index >= engine->device_count)
|
||||
return NULL;
|
||||
return &engine->devices[index];
|
||||
}
|
||||
|
||||
B32 audio_open_device(AudioEngine *engine, S32 index) {
|
||||
// Close any existing device first
|
||||
audio_close_device(engine);
|
||||
|
||||
if (index < 0 || index >= engine->device_count)
|
||||
return false;
|
||||
|
||||
// Create COM instance of the ASIO driver
|
||||
IASIO *driver = NULL;
|
||||
HRESULT hr = CoCreateInstance(&engine->drivers[index].clsid,
|
||||
NULL, CLSCTX_INPROC_SERVER,
|
||||
&engine->drivers[index].clsid,
|
||||
(void **)&driver);
|
||||
if (FAILED(hr) || !driver)
|
||||
return false;
|
||||
|
||||
// Initialize the driver
|
||||
if (!driver->lpVtbl->init(driver, engine->hwnd)) {
|
||||
driver->lpVtbl->Release(driver);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Query channel counts
|
||||
long num_in = 0, num_out = 0;
|
||||
if (driver->lpVtbl->getChannels(driver, &num_in, &num_out) != ASE_OK || num_out <= 0) {
|
||||
driver->lpVtbl->Release(driver);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Query buffer size
|
||||
long min_size = 0, max_size = 0, preferred_size = 0, granularity = 0;
|
||||
if (driver->lpVtbl->getBufferSize(driver, &min_size, &max_size, &preferred_size, &granularity) != ASE_OK) {
|
||||
driver->lpVtbl->Release(driver);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Query sample rate
|
||||
F64 sample_rate = 0;
|
||||
if (driver->lpVtbl->getSampleRate(driver, &sample_rate) != ASE_OK || sample_rate <= 0) {
|
||||
// Try setting a common rate
|
||||
if (driver->lpVtbl->setSampleRate(driver, 44100.0) == ASE_OK) {
|
||||
sample_rate = 44100.0;
|
||||
} else {
|
||||
driver->lpVtbl->Release(driver);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Query output channel sample type
|
||||
ASIOChannelInfo chan_info = {0};
|
||||
chan_info.channel = 0;
|
||||
chan_info.isInput = 0;
|
||||
if (driver->lpVtbl->getChannelInfo(driver, &chan_info) != ASE_OK) {
|
||||
driver->lpVtbl->Release(driver);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Limit output channels
|
||||
if (num_out > AUDIO_MAX_CHANNELS) num_out = AUDIO_MAX_CHANNELS;
|
||||
|
||||
// Setup buffer infos for output channels only
|
||||
memset(engine->buffer_infos, 0, sizeof(engine->buffer_infos));
|
||||
for (long ch = 0; ch < num_out; ch++) {
|
||||
engine->buffer_infos[ch].isInput = 0;
|
||||
engine->buffer_infos[ch].channelNum = ch;
|
||||
engine->buffer_infos[ch].buffers[0] = NULL;
|
||||
engine->buffer_infos[ch].buffers[1] = NULL;
|
||||
}
|
||||
|
||||
// Setup callbacks
|
||||
engine->callbacks.bufferSwitch = asio_buffer_switch;
|
||||
engine->callbacks.sampleRateDidChange = asio_sample_rate_changed;
|
||||
engine->callbacks.asioMessage = asio_message;
|
||||
engine->callbacks.bufferSwitchTimeInfo = asio_buffer_switch_time_info;
|
||||
|
||||
// Create buffers
|
||||
if (driver->lpVtbl->createBuffers(driver, engine->buffer_infos, num_out, preferred_size, &engine->callbacks) != ASE_OK) {
|
||||
driver->lpVtbl->Release(driver);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Store state
|
||||
engine->driver = driver;
|
||||
engine->active_device_index = index;
|
||||
engine->num_output_channels = num_out;
|
||||
engine->num_input_channels = num_in;
|
||||
engine->buffer_size = preferred_size;
|
||||
engine->sample_rate = sample_rate;
|
||||
engine->output_sample_type = chan_info.type;
|
||||
engine->test_tone_active = 0;
|
||||
engine->test_tone_samples_remaining = 0;
|
||||
engine->test_tone_phase = 0.0;
|
||||
|
||||
// Start the driver
|
||||
if (driver->lpVtbl->start(driver) != ASE_OK) {
|
||||
driver->lpVtbl->disposeBuffers(driver);
|
||||
driver->lpVtbl->Release(driver);
|
||||
engine->driver = NULL;
|
||||
engine->active_device_index = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Notify driver that output is ready (optional, some drivers benefit)
|
||||
driver->lpVtbl->outputReady(driver);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void audio_close_device(AudioEngine *engine) {
|
||||
if (!engine->driver) return;
|
||||
|
||||
InterlockedExchange(&engine->test_tone_active, 0);
|
||||
InterlockedExchange(&engine->test_tone_samples_remaining, 0);
|
||||
|
||||
engine->driver->lpVtbl->stop(engine->driver);
|
||||
engine->driver->lpVtbl->disposeBuffers(engine->driver);
|
||||
engine->driver->lpVtbl->Release(engine->driver);
|
||||
engine->driver = NULL;
|
||||
engine->active_device_index = -1;
|
||||
engine->test_tone_phase = 0.0;
|
||||
}
|
||||
|
||||
void audio_play_test_tone(AudioEngine *engine) {
|
||||
if (!engine->driver) return;
|
||||
|
||||
engine->test_tone_phase = 0.0;
|
||||
LONG total_samples = (LONG)(engine->sample_rate * AUDIO_TEST_TONE_SEC);
|
||||
InterlockedExchange(&engine->test_tone_samples_remaining, total_samples);
|
||||
InterlockedExchange(&engine->test_tone_active, 1);
|
||||
}
|
||||
|
||||
B32 audio_is_test_tone_playing(AudioEngine *engine) {
|
||||
return InterlockedCompareExchange(&engine->test_tone_active, 0, 0) != 0;
|
||||
}
|
||||
|
||||
void audio_update(AudioEngine *engine, F32 dt) {
|
||||
(void)engine;
|
||||
(void)dt;
|
||||
// Currently no per-frame work needed on the main thread.
|
||||
// The ASIO callback handles all audio processing.
|
||||
// This hook exists for future use (e.g., level metering).
|
||||
}
|
||||
342
src/audio/audio_coreaudio.c
Normal file
342
src/audio/audio_coreaudio.c
Normal file
@@ -0,0 +1,342 @@
|
||||
#include "audio/audio.h"
|
||||
#include <AudioToolbox/AudioToolbox.h>
|
||||
#include <CoreAudio/CoreAudio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <stdatomic.h>
|
||||
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
|
||||
#define AUDIO_MAX_DEVICES 32
|
||||
#define AUDIO_MAX_CHANNELS 32
|
||||
#define AUDIO_TEST_TONE_HZ 440.0
|
||||
#define AUDIO_TEST_TONE_SEC 2.0
|
||||
#define AUDIO_PI 3.14159265358979323846
|
||||
|
||||
typedef struct CoreAudioDeviceInfo {
|
||||
AudioDeviceID device_id;
|
||||
} CoreAudioDeviceInfo;
|
||||
|
||||
struct AudioEngine {
|
||||
AudioDeviceInfo devices[AUDIO_MAX_DEVICES];
|
||||
CoreAudioDeviceInfo ca_devices[AUDIO_MAX_DEVICES];
|
||||
S32 device_count;
|
||||
|
||||
AUGraph graph;
|
||||
AudioUnit output_unit;
|
||||
S32 active_device_index;
|
||||
F64 sample_rate;
|
||||
S32 num_channels;
|
||||
|
||||
// Test tone state (accessed from audio render thread)
|
||||
_Atomic S32 test_tone_active;
|
||||
_Atomic S32 test_tone_samples_remaining;
|
||||
F64 test_tone_phase;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
// Audio render callback
|
||||
|
||||
static AudioEngine *g_audio_engine = NULL;
|
||||
|
||||
static OSStatus audio_render_callback(void *inRefCon,
|
||||
AudioUnitRenderActionFlags *ioActionFlags,
|
||||
const AudioTimeStamp *inTimeStamp,
|
||||
UInt32 inBusNumber,
|
||||
UInt32 inNumberFrames,
|
||||
AudioBufferList *ioData)
|
||||
{
|
||||
(void)inRefCon; (void)ioActionFlags; (void)inTimeStamp; (void)inBusNumber;
|
||||
|
||||
AudioEngine *engine = g_audio_engine;
|
||||
if (!engine) {
|
||||
for (UInt32 buf = 0; buf < ioData->mNumberBuffers; buf++)
|
||||
memset(ioData->mBuffers[buf].mData, 0, ioData->mBuffers[buf].mDataByteSize);
|
||||
return noErr;
|
||||
}
|
||||
|
||||
S32 tone_active = atomic_load(&engine->test_tone_active);
|
||||
|
||||
if (!tone_active) {
|
||||
for (UInt32 buf = 0; buf < ioData->mNumberBuffers; buf++)
|
||||
memset(ioData->mBuffers[buf].mData, 0, ioData->mBuffers[buf].mDataByteSize);
|
||||
return noErr;
|
||||
}
|
||||
|
||||
F64 phase = engine->test_tone_phase;
|
||||
F64 phase_inc = 2.0 * AUDIO_PI * AUDIO_TEST_TONE_HZ / engine->sample_rate;
|
||||
S32 remaining = atomic_load(&engine->test_tone_samples_remaining);
|
||||
S32 samples_to_gen = (remaining < (S32)inNumberFrames) ? remaining : (S32)inNumberFrames;
|
||||
|
||||
// CoreAudio with kAudioFormatFlagIsNonInterleaved: each buffer = one channel
|
||||
for (UInt32 buf = 0; buf < ioData->mNumberBuffers; buf++) {
|
||||
F32 *out = (F32 *)ioData->mBuffers[buf].mData;
|
||||
F64 p = phase;
|
||||
for (UInt32 s = 0; s < inNumberFrames; s++) {
|
||||
if ((S32)s < samples_to_gen) {
|
||||
out[s] = (F32)(sin(p) * 0.5); // -6dB
|
||||
p += phase_inc;
|
||||
if (p >= 2.0 * AUDIO_PI) p -= 2.0 * AUDIO_PI;
|
||||
} else {
|
||||
out[s] = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Advance phase using first channel's traversal
|
||||
phase += phase_inc * samples_to_gen;
|
||||
while (phase >= 2.0 * AUDIO_PI) phase -= 2.0 * AUDIO_PI;
|
||||
engine->test_tone_phase = phase;
|
||||
|
||||
S32 new_remaining = atomic_fetch_sub(&engine->test_tone_samples_remaining, samples_to_gen);
|
||||
if (new_remaining <= samples_to_gen) {
|
||||
atomic_store(&engine->test_tone_active, 0);
|
||||
atomic_store(&engine->test_tone_samples_remaining, 0);
|
||||
}
|
||||
|
||||
return noErr;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Device enumeration
|
||||
|
||||
static void enumerate_output_devices(AudioEngine *engine) {
|
||||
engine->device_count = 0;
|
||||
|
||||
AudioObjectPropertyAddress prop = {
|
||||
kAudioHardwarePropertyDevices,
|
||||
kAudioObjectPropertyScopeGlobal,
|
||||
kAudioObjectPropertyElementMain
|
||||
};
|
||||
|
||||
UInt32 data_size = 0;
|
||||
if (AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &prop, 0, NULL, &data_size) != noErr)
|
||||
return;
|
||||
|
||||
S32 device_count = (S32)(data_size / sizeof(AudioDeviceID));
|
||||
if (device_count <= 0) return;
|
||||
|
||||
AudioDeviceID *device_ids = (AudioDeviceID *)malloc(data_size);
|
||||
if (AudioObjectGetPropertyData(kAudioObjectSystemObject, &prop, 0, NULL, &data_size, device_ids) != noErr) {
|
||||
free(device_ids);
|
||||
return;
|
||||
}
|
||||
|
||||
for (S32 i = 0; i < device_count && engine->device_count < AUDIO_MAX_DEVICES; i++) {
|
||||
// Check if device has output channels
|
||||
AudioObjectPropertyAddress stream_prop = {
|
||||
kAudioDevicePropertyStreamConfiguration,
|
||||
kAudioDevicePropertyScopeOutput,
|
||||
kAudioObjectPropertyElementMain
|
||||
};
|
||||
|
||||
UInt32 stream_size = 0;
|
||||
if (AudioObjectGetPropertyDataSize(device_ids[i], &stream_prop, 0, NULL, &stream_size) != noErr)
|
||||
continue;
|
||||
|
||||
AudioBufferList *buf_list = (AudioBufferList *)malloc(stream_size);
|
||||
if (AudioObjectGetPropertyData(device_ids[i], &stream_prop, 0, NULL, &stream_size, buf_list) != noErr) {
|
||||
free(buf_list);
|
||||
continue;
|
||||
}
|
||||
|
||||
S32 output_channels = 0;
|
||||
for (UInt32 b = 0; b < buf_list->mNumberBuffers; b++)
|
||||
output_channels += (S32)buf_list->mBuffers[b].mNumberChannels;
|
||||
free(buf_list);
|
||||
|
||||
if (output_channels == 0) continue;
|
||||
|
||||
// Get device name
|
||||
AudioObjectPropertyAddress name_prop = {
|
||||
kAudioObjectPropertyName,
|
||||
kAudioObjectPropertyScopeGlobal,
|
||||
kAudioObjectPropertyElementMain
|
||||
};
|
||||
|
||||
CFStringRef name_ref = NULL;
|
||||
UInt32 name_size = sizeof(name_ref);
|
||||
if (AudioObjectGetPropertyData(device_ids[i], &name_prop, 0, NULL, &name_size, &name_ref) != noErr)
|
||||
continue;
|
||||
|
||||
S32 idx = engine->device_count++;
|
||||
CFStringGetCString(name_ref, engine->devices[idx].name, sizeof(engine->devices[idx].name),
|
||||
kCFStringEncodingUTF8);
|
||||
CFRelease(name_ref);
|
||||
engine->devices[idx].id = idx;
|
||||
engine->ca_devices[idx].device_id = device_ids[i];
|
||||
}
|
||||
|
||||
free(device_ids);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Public API
|
||||
|
||||
AudioEngine *audio_create(void *hwnd) {
|
||||
(void)hwnd;
|
||||
|
||||
AudioEngine *engine = (AudioEngine *)calloc(1, sizeof(AudioEngine));
|
||||
engine->active_device_index = -1;
|
||||
atomic_store(&engine->test_tone_active, 0);
|
||||
atomic_store(&engine->test_tone_samples_remaining, 0);
|
||||
g_audio_engine = engine;
|
||||
|
||||
enumerate_output_devices(engine);
|
||||
return engine;
|
||||
}
|
||||
|
||||
void audio_destroy(AudioEngine *engine) {
|
||||
audio_close_device(engine);
|
||||
if (g_audio_engine == engine) g_audio_engine = NULL;
|
||||
free(engine);
|
||||
}
|
||||
|
||||
void audio_refresh_devices(AudioEngine *engine) {
|
||||
audio_close_device(engine);
|
||||
enumerate_output_devices(engine);
|
||||
}
|
||||
|
||||
S32 audio_get_device_count(AudioEngine *engine) {
|
||||
return engine->device_count;
|
||||
}
|
||||
|
||||
AudioDeviceInfo *audio_get_device(AudioEngine *engine, S32 index) {
|
||||
if (index < 0 || index >= engine->device_count) return NULL;
|
||||
return &engine->devices[index];
|
||||
}
|
||||
|
||||
B32 audio_open_device(AudioEngine *engine, S32 index) {
|
||||
audio_close_device(engine);
|
||||
|
||||
if (index < 0 || index >= engine->device_count) return false;
|
||||
|
||||
AudioDeviceID device_id = engine->ca_devices[index].device_id;
|
||||
|
||||
// Create AUGraph
|
||||
if (NewAUGraph(&engine->graph) != noErr) return false;
|
||||
|
||||
// Add HAL output node
|
||||
AudioComponentDescription output_desc = {0};
|
||||
output_desc.componentType = kAudioUnitType_Output;
|
||||
output_desc.componentSubType = kAudioUnitSubType_HALOutput;
|
||||
output_desc.componentManufacturer = kAudioUnitManufacturer_Apple;
|
||||
|
||||
AUNode output_node;
|
||||
if (AUGraphAddNode(engine->graph, &output_desc, &output_node) != noErr) {
|
||||
DisposeAUGraph(engine->graph);
|
||||
engine->graph = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (AUGraphOpen(engine->graph) != noErr) {
|
||||
DisposeAUGraph(engine->graph);
|
||||
engine->graph = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (AUGraphNodeInfo(engine->graph, output_node, NULL, &engine->output_unit) != noErr) {
|
||||
DisposeAUGraph(engine->graph);
|
||||
engine->graph = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set device
|
||||
if (AudioUnitSetProperty(engine->output_unit, kAudioOutputUnitProperty_CurrentDevice,
|
||||
kAudioUnitScope_Global, 0, &device_id, sizeof(device_id)) != noErr) {
|
||||
DisposeAUGraph(engine->graph);
|
||||
engine->graph = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get device sample rate
|
||||
AudioObjectPropertyAddress rate_prop = {
|
||||
kAudioDevicePropertyNominalSampleRate,
|
||||
kAudioDevicePropertyScopeOutput,
|
||||
kAudioObjectPropertyElementMain
|
||||
};
|
||||
Float64 sample_rate = 44100.0;
|
||||
UInt32 rate_size = sizeof(sample_rate);
|
||||
AudioObjectGetPropertyData(device_id, &rate_prop, 0, NULL, &rate_size, &sample_rate);
|
||||
engine->sample_rate = sample_rate;
|
||||
|
||||
// Set stream format: Float32, non-interleaved
|
||||
AudioStreamBasicDescription fmt = {0};
|
||||
fmt.mSampleRate = sample_rate;
|
||||
fmt.mFormatID = kAudioFormatLinearPCM;
|
||||
fmt.mFormatFlags = kAudioFormatFlagIsFloat | kAudioFormatFlagIsNonInterleaved | kAudioFormatFlagIsPacked;
|
||||
fmt.mBitsPerChannel = 32;
|
||||
fmt.mChannelsPerFrame = 2;
|
||||
fmt.mFramesPerPacket = 1;
|
||||
fmt.mBytesPerFrame = 4;
|
||||
fmt.mBytesPerPacket = 4;
|
||||
engine->num_channels = 2;
|
||||
|
||||
AudioUnitSetProperty(engine->output_unit, kAudioUnitProperty_StreamFormat,
|
||||
kAudioUnitScope_Input, 0, &fmt, sizeof(fmt));
|
||||
|
||||
// Set render callback
|
||||
AURenderCallbackStruct cb = {0};
|
||||
cb.inputProc = audio_render_callback;
|
||||
cb.inputProcRefCon = engine;
|
||||
|
||||
if (AudioUnitSetProperty(engine->output_unit, kAudioUnitProperty_SetRenderCallback,
|
||||
kAudioUnitScope_Input, 0, &cb, sizeof(cb)) != noErr) {
|
||||
DisposeAUGraph(engine->graph);
|
||||
engine->graph = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Initialize and start
|
||||
if (AUGraphInitialize(engine->graph) != noErr) {
|
||||
DisposeAUGraph(engine->graph);
|
||||
engine->graph = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (AUGraphStart(engine->graph) != noErr) {
|
||||
DisposeAUGraph(engine->graph);
|
||||
engine->graph = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
engine->active_device_index = index;
|
||||
engine->test_tone_phase = 0.0;
|
||||
atomic_store(&engine->test_tone_active, 0);
|
||||
atomic_store(&engine->test_tone_samples_remaining, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void audio_close_device(AudioEngine *engine) {
|
||||
if (!engine->graph) return;
|
||||
|
||||
atomic_store(&engine->test_tone_active, 0);
|
||||
atomic_store(&engine->test_tone_samples_remaining, 0);
|
||||
|
||||
AUGraphStop(engine->graph);
|
||||
AUGraphUninitialize(engine->graph);
|
||||
DisposeAUGraph(engine->graph);
|
||||
engine->graph = NULL;
|
||||
engine->output_unit = NULL;
|
||||
engine->active_device_index = -1;
|
||||
engine->test_tone_phase = 0.0;
|
||||
}
|
||||
|
||||
void audio_play_test_tone(AudioEngine *engine) {
|
||||
if (!engine->graph) return;
|
||||
|
||||
engine->test_tone_phase = 0.0;
|
||||
S32 total_samples = (S32)(engine->sample_rate * AUDIO_TEST_TONE_SEC);
|
||||
atomic_store(&engine->test_tone_samples_remaining, total_samples);
|
||||
atomic_store(&engine->test_tone_active, 1);
|
||||
}
|
||||
|
||||
B32 audio_is_test_tone_playing(AudioEngine *engine) {
|
||||
return atomic_load(&engine->test_tone_active) != 0;
|
||||
}
|
||||
|
||||
void audio_update(AudioEngine *engine, F32 dt) {
|
||||
(void)engine;
|
||||
(void)dt;
|
||||
}
|
||||
53
src/base/base_arena.c
Normal file
53
src/base/base_arena.c
Normal file
@@ -0,0 +1,53 @@
|
||||
#include "base/base_arena.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
Arena *arena_alloc(U64 cap) {
|
||||
U8 *mem = (U8 *)malloc(sizeof(Arena) + cap);
|
||||
if (!mem) return NULL;
|
||||
Arena *arena = (Arena *)mem;
|
||||
arena->base = mem + sizeof(Arena);
|
||||
arena->pos = 0;
|
||||
arena->cap = cap;
|
||||
return arena;
|
||||
}
|
||||
|
||||
void arena_release(Arena *arena) {
|
||||
if (arena) free(arena);
|
||||
}
|
||||
|
||||
void *arena_push(Arena *arena, U64 size) {
|
||||
U64 aligned = AlignPow2(size, 8);
|
||||
if (arena->pos + aligned > arena->cap) {
|
||||
Assert(!"Arena overflow");
|
||||
return NULL;
|
||||
}
|
||||
void *result = arena->base + arena->pos;
|
||||
arena->pos += aligned;
|
||||
MemoryZero(result, aligned);
|
||||
return result;
|
||||
}
|
||||
|
||||
void *arena_push_no_zero(Arena *arena, U64 size) {
|
||||
U64 aligned = AlignPow2(size, 8);
|
||||
if (arena->pos + aligned > arena->cap) {
|
||||
Assert(!"Arena overflow");
|
||||
return NULL;
|
||||
}
|
||||
void *result = arena->base + arena->pos;
|
||||
arena->pos += aligned;
|
||||
return result;
|
||||
}
|
||||
|
||||
U64 arena_pos(Arena *arena) {
|
||||
return arena->pos;
|
||||
}
|
||||
|
||||
void arena_pop_to(Arena *arena, U64 pos) {
|
||||
if (pos < arena->pos) {
|
||||
arena->pos = pos;
|
||||
}
|
||||
}
|
||||
|
||||
void arena_clear(Arena *arena) {
|
||||
arena->pos = 0;
|
||||
}
|
||||
44
src/base/base_arena.h
Normal file
44
src/base/base_arena.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
// base_arena.h - Linear arena allocator
|
||||
// Simplified from raddebugger's virtual-memory-backed arena to a malloc-based one.
|
||||
// Suitable for per-frame scratch allocations and persistent state.
|
||||
|
||||
#include "base/base_core.h"
|
||||
|
||||
////////////////////////////////
|
||||
// Arena type
|
||||
|
||||
typedef struct Arena {
|
||||
U8 *base;
|
||||
U64 pos;
|
||||
U64 cap;
|
||||
} Arena;
|
||||
|
||||
// Temporary scope (save/restore position)
|
||||
typedef struct Temp {
|
||||
Arena *arena;
|
||||
U64 pos;
|
||||
} Temp;
|
||||
|
||||
////////////////////////////////
|
||||
// Arena functions
|
||||
|
||||
Arena *arena_alloc(U64 cap);
|
||||
void arena_release(Arena *arena);
|
||||
void *arena_push(Arena *arena, U64 size);
|
||||
void *arena_push_no_zero(Arena *arena, U64 size);
|
||||
U64 arena_pos(Arena *arena);
|
||||
void arena_pop_to(Arena *arena, U64 pos);
|
||||
void arena_clear(Arena *arena);
|
||||
|
||||
////////////////////////////////
|
||||
// Temporary scope helpers
|
||||
|
||||
static inline Temp temp_begin(Arena *arena) { Temp t = {arena, arena->pos}; return t; }
|
||||
static inline void temp_end(Temp temp) { arena_pop_to(temp.arena, temp.pos); }
|
||||
|
||||
////////////////////////////////
|
||||
// Push helper macros
|
||||
|
||||
#define push_array(arena, T, count) ((T *)arena_push((arena), sizeof(T) * (count)))
|
||||
#define push_array_no_zero(arena, T, count) ((T *)arena_push_no_zero((arena), sizeof(T) * (count)))
|
||||
181
src/base/base_core.h
Normal file
181
src/base/base_core.h
Normal file
@@ -0,0 +1,181 @@
|
||||
#pragma once
|
||||
// base_core.h - Fundamental types, macros, and linked list helpers
|
||||
// Inspired by raddebugger's base_core.h
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
////////////////////////////////
|
||||
// Codebase keywords
|
||||
|
||||
#ifndef __APPLE__
|
||||
#define internal static
|
||||
#define global static
|
||||
#endif
|
||||
#define local_persist static
|
||||
|
||||
#define trvke 1
|
||||
|
||||
////////////////////////////////
|
||||
// Base types
|
||||
|
||||
typedef uint8_t U8;
|
||||
typedef uint16_t U16;
|
||||
typedef uint32_t U32;
|
||||
typedef uint64_t U64;
|
||||
typedef int8_t S8;
|
||||
typedef int16_t S16;
|
||||
typedef int32_t S32;
|
||||
typedef int64_t S64;
|
||||
typedef S32 B32;
|
||||
typedef float F32;
|
||||
typedef double F64;
|
||||
|
||||
////////////////////////////////
|
||||
// Limits
|
||||
|
||||
#define max_U8 0xFF
|
||||
#define max_U16 0xFFFF
|
||||
#define max_U32 0xFFFFFFFF
|
||||
#define max_U64 0xFFFFFFFFFFFFFFFFull
|
||||
#define max_S8 0x7F
|
||||
#define max_S16 0x7FFF
|
||||
#define max_S32 0x7FFFFFFF
|
||||
#define max_S64 0x7FFFFFFFFFFFFFFFll
|
||||
|
||||
////////////////////////////////
|
||||
// Units
|
||||
|
||||
#define KB(n) (((U64)(n)) << 10)
|
||||
#define MB(n) (((U64)(n)) << 20)
|
||||
#define GB(n) (((U64)(n)) << 30)
|
||||
|
||||
////////////////////////////////
|
||||
// Clamps, Mins, Maxes
|
||||
|
||||
#define Min(A, B) (((A) < (B)) ? (A) : (B))
|
||||
#define Max(A, B) (((A) > (B)) ? (A) : (B))
|
||||
#define ClampTop(A, X) Min(A, X)
|
||||
#define ClampBot(X, B) Max(X, B)
|
||||
#define Clamp(A, X, B) (((X) < (A)) ? (A) : ((X) > (B)) ? (B) : (X))
|
||||
|
||||
////////////////////////////////
|
||||
// Alignment / Sizing
|
||||
|
||||
#define AlignPow2(x, b) (((x) + (b) - 1) & (~((b) - 1)))
|
||||
#define AlignDownPow2(x, b) ((x) & (~((b) - 1)))
|
||||
#define ArrayCount(a) (sizeof(a) / sizeof((a)[0]))
|
||||
|
||||
////////////////////////////////
|
||||
// Memory macros
|
||||
|
||||
#define MemoryCopy(dst, src, size) memmove((dst), (src), (size))
|
||||
#define MemorySet(dst, byte, size) memset((dst), (byte), (size))
|
||||
#define MemoryCompare(a, b, size) memcmp((a), (b), (size))
|
||||
#define MemoryZero(s, z) memset((s), 0, (z))
|
||||
#define MemoryZeroStruct(s) MemoryZero((s), sizeof(*(s)))
|
||||
#define MemoryZeroArray(a) MemoryZero((a), sizeof(a))
|
||||
#define MemoryMatch(a, b, z) (MemoryCompare((a), (b), (z)) == 0)
|
||||
|
||||
////////////////////////////////
|
||||
// Pointer / integer casts
|
||||
|
||||
#define IntFromPtr(ptr) ((U64)(ptr))
|
||||
#define PtrFromInt(i) (void *)(i)
|
||||
#define OffsetOf(T, m) IntFromPtr(&(((T *)0)->m))
|
||||
|
||||
////////////////////////////////
|
||||
// Member access
|
||||
|
||||
#define CastFromMember(T, m, ptr) (T *)(((U8 *)(ptr)) - OffsetOf(T, m))
|
||||
|
||||
////////////////////////////////
|
||||
// For-Loop construct macros
|
||||
|
||||
#define DeferLoop(begin, end) for (int _i_ = ((begin), 0); !_i_; _i_ += 1, (end))
|
||||
#define DeferLoopChecked(begin, end) for (int _i_ = 2 * !(begin); (_i_ == 2 ? ((end), 0) : !_i_); _i_ += 1, (end))
|
||||
|
||||
#define EachIndex(it, count) (U64 it = 0; it < (count); it += 1)
|
||||
#define EachElement(it, array) (U64 it = 0; it < ArrayCount(array); it += 1)
|
||||
|
||||
////////////////////////////////
|
||||
// Glue / Stringify
|
||||
|
||||
#define Stringify_(S) #S
|
||||
#define Stringify(S) Stringify_(S)
|
||||
#define Glue_(A, B) A##B
|
||||
#define Glue(A, B) Glue_(A, B)
|
||||
|
||||
#define Swap(T, a, b) do { T t__ = a; a = b; b = t__; } while (0)
|
||||
|
||||
////////////////////////////////
|
||||
// Assert
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# define Trap() __debugbreak()
|
||||
#elif defined(__clang__) || defined(__GNUC__)
|
||||
# define Trap() __builtin_trap()
|
||||
#else
|
||||
# define Trap() (*(volatile int *)0 = 0)
|
||||
#endif
|
||||
|
||||
#define AssertAlways(x) do { if (!(x)) { Trap(); } } while (0)
|
||||
|
||||
#ifdef _DEBUG
|
||||
# define Assert(x) AssertAlways(x)
|
||||
#else
|
||||
# define Assert(x) (void)(x)
|
||||
#endif
|
||||
|
||||
#define InvalidPath Assert(!"Invalid Path!")
|
||||
#define NotImplemented Assert(!"Not Implemented!")
|
||||
|
||||
////////////////////////////////
|
||||
// Linked list macros
|
||||
// Nil-aware doubly-linked-list operations
|
||||
|
||||
#define CheckNil(nil, p) ((p) == 0 || (p) == nil)
|
||||
#define SetNil(nil, p) ((p) = nil)
|
||||
|
||||
// Doubly-linked-list (with nil support)
|
||||
#define DLLInsert_NPZ(nil, f, l, p, n, next, prev) \
|
||||
(CheckNil(nil, f) ? \
|
||||
((f) = (l) = (n), SetNil(nil, (n)->next), SetNil(nil, (n)->prev)) : \
|
||||
CheckNil(nil, p) ? \
|
||||
((n)->next = (f), (f)->prev = (n), (f) = (n), SetNil(nil, (n)->prev)) : \
|
||||
((p) == (l)) ? \
|
||||
((l)->next = (n), (n)->prev = (l), (l) = (n), SetNil(nil, (n)->next)) : \
|
||||
(((!CheckNil(nil, p) && CheckNil(nil, (p)->next)) ? (0) : ((p)->next->prev = (n))), \
|
||||
((n)->next = (p)->next), ((p)->next = (n)), ((n)->prev = (p))))
|
||||
|
||||
#define DLLPushBack_NPZ(nil, f, l, n, next, prev) DLLInsert_NPZ(nil, f, l, l, n, next, prev)
|
||||
#define DLLPushFront_NPZ(nil, f, l, n, next, prev) DLLInsert_NPZ(nil, l, f, f, n, prev, next)
|
||||
|
||||
#define DLLRemove_NPZ(nil, f, l, n, next, prev) \
|
||||
(((n) == (f) ? (f) = (n)->next : (0)), \
|
||||
((n) == (l) ? (l) = (l)->prev : (0)), \
|
||||
(CheckNil(nil, (n)->prev) ? (0) : ((n)->prev->next = (n)->next)), \
|
||||
(CheckNil(nil, (n)->next) ? (0) : ((n)->next->prev = (n)->prev)))
|
||||
|
||||
// Convenience wrappers using 0 as nil
|
||||
#define DLLPushBack(f, l, n) DLLPushBack_NPZ(0, f, l, n, next, prev)
|
||||
#define DLLPushFront(f, l, n) DLLPushFront_NPZ(0, f, l, n, next, prev)
|
||||
#define DLLRemove(f, l, n) DLLRemove_NPZ(0, f, l, n, next, prev)
|
||||
|
||||
// Singly-linked queue (doubly-headed)
|
||||
#define SLLQueuePush_NZ(nil, f, l, n, next) \
|
||||
(CheckNil(nil, f) ? \
|
||||
((f) = (l) = (n), SetNil(nil, (n)->next)) : \
|
||||
((l)->next = (n), (l) = (n), SetNil(nil, (n)->next)))
|
||||
|
||||
#define SLLQueuePush(f, l, n) SLLQueuePush_NZ(0, f, l, n, next)
|
||||
#define SLLQueuePushFront(f, l, n) (((n)->next = (f)), ((f) = (n)))
|
||||
#define SLLQueuePop(f, l) ((f) == (l) ? ((f) = 0, (l) = 0) : ((f) = (f)->next))
|
||||
|
||||
// Singly-linked stack
|
||||
#define SLLStackPush(f, n) ((n)->next = (f), (f) = (n))
|
||||
#define SLLStackPop(f) ((f) = (f)->next)
|
||||
3
src/base/base_inc.c
Normal file
3
src/base/base_inc.c
Normal file
@@ -0,0 +1,3 @@
|
||||
// base_inc.c - Unity build for the base layer
|
||||
#include "base/base_arena.c"
|
||||
#include "base/base_strings.c"
|
||||
8
src/base/base_inc.h
Normal file
8
src/base/base_inc.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
// base_inc.h - Umbrella include for the base layer
|
||||
// Include this one header to get all base types.
|
||||
|
||||
#include "base/base_core.h"
|
||||
#include "base/base_arena.h"
|
||||
#include "base/base_math.h"
|
||||
#include "base/base_strings.h"
|
||||
110
src/base/base_math.h
Normal file
110
src/base/base_math.h
Normal file
@@ -0,0 +1,110 @@
|
||||
#pragma once
|
||||
// base_math.h - Vector, range, and color types
|
||||
// Inspired by raddebugger's base_math.h
|
||||
|
||||
#include "base/base_core.h"
|
||||
|
||||
////////////////////////////////
|
||||
// Axis enum
|
||||
|
||||
typedef enum Axis2 {
|
||||
Axis2_X = 0,
|
||||
Axis2_Y = 1,
|
||||
Axis2_COUNT,
|
||||
} Axis2;
|
||||
|
||||
typedef enum Side {
|
||||
Side_Min = 0,
|
||||
Side_Max = 1,
|
||||
Side_COUNT,
|
||||
} Side;
|
||||
|
||||
typedef enum Corner {
|
||||
Corner_00 = 0, // top-left
|
||||
Corner_01 = 1, // top-right
|
||||
Corner_10 = 2, // bottom-left
|
||||
Corner_11 = 3, // bottom-right
|
||||
Corner_COUNT,
|
||||
} Corner;
|
||||
|
||||
////////////////////////////////
|
||||
// Vector types
|
||||
|
||||
typedef struct Vec2F32 { F32 x, y; } Vec2F32;
|
||||
typedef struct Vec2S32 { S32 x, y; } Vec2S32;
|
||||
typedef struct Vec3F32 { F32 x, y, z; } Vec3F32;
|
||||
typedef struct Vec4F32 { F32 x, y, z, w; } Vec4F32;
|
||||
|
||||
////////////////////////////////
|
||||
// Range types
|
||||
|
||||
typedef struct Rng1F32 { F32 min, max; } Rng1F32;
|
||||
typedef struct Rng1S64 { S64 min, max; } Rng1S64;
|
||||
typedef struct Rng2F32 { Vec2F32 p0, p1; } Rng2F32;
|
||||
|
||||
////////////////////////////////
|
||||
// Constructors
|
||||
|
||||
static inline Vec2F32 v2f32(F32 x, F32 y) { return (Vec2F32){x, y}; }
|
||||
static inline Vec2S32 v2s32(S32 x, S32 y) { return (Vec2S32){x, y}; }
|
||||
static inline Vec3F32 v3f32(F32 x, F32 y, F32 z) { return (Vec3F32){x, y, z}; }
|
||||
static inline Vec4F32 v4f32(F32 x, F32 y, F32 z, F32 w) { return (Vec4F32){x, y, z, w}; }
|
||||
static inline Rng1F32 rng1f32(F32 min, F32 max) { return (Rng1F32){min, max}; }
|
||||
static inline Rng1S64 rng1s64(S64 min, S64 max) { return (Rng1S64){min, max}; }
|
||||
static inline Rng2F32 rng2f32(Vec2F32 p0, Vec2F32 p1) { return (Rng2F32){p0, p1}; }
|
||||
static inline Rng2F32 rng2f32p(F32 x0, F32 y0, F32 x1, F32 y1) { return (Rng2F32){{x0, y0}, {x1, y1}}; }
|
||||
|
||||
////////////////////////////////
|
||||
// Vec2F32 operations
|
||||
|
||||
static inline Vec2F32 add_2f32(Vec2F32 a, Vec2F32 b) { return (Vec2F32){a.x + b.x, a.y + b.y}; }
|
||||
static inline Vec2F32 sub_2f32(Vec2F32 a, Vec2F32 b) { return (Vec2F32){a.x - b.x, a.y - b.y}; }
|
||||
static inline Vec2F32 mul_2f32(Vec2F32 a, Vec2F32 b) { return (Vec2F32){a.x * b.x, a.y * b.y}; }
|
||||
static inline Vec2F32 scale_2f32(Vec2F32 v, F32 s) { return (Vec2F32){v.x * s, v.y * s}; }
|
||||
|
||||
// Axis-indexed access
|
||||
static inline F32 v2f32_axis(Vec2F32 v, Axis2 a) { return a == Axis2_X ? v.x : v.y; }
|
||||
static inline void v2f32_set_axis(Vec2F32 *v, Axis2 a, F32 val) {
|
||||
if (a == Axis2_X) v->x = val; else v->y = val;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Vec4F32 operations
|
||||
|
||||
static inline Vec4F32 add_4f32(Vec4F32 a, Vec4F32 b) { return (Vec4F32){a.x+b.x, a.y+b.y, a.z+b.z, a.w+b.w}; }
|
||||
static inline Vec4F32 scale_4f32(Vec4F32 v, F32 s) { return (Vec4F32){v.x*s, v.y*s, v.z*s, v.w*s}; }
|
||||
static inline Vec4F32 lerp_4f32(Vec4F32 a, Vec4F32 b, F32 t) {
|
||||
return (Vec4F32){a.x + (b.x - a.x)*t, a.y + (b.y - a.y)*t, a.z + (b.z - a.z)*t, a.w + (b.w - a.w)*t};
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Rng2F32 operations
|
||||
|
||||
static inline F32 rng2f32_width(Rng2F32 r) { return r.p1.x - r.p0.x; }
|
||||
static inline F32 rng2f32_height(Rng2F32 r) { return r.p1.y - r.p0.y; }
|
||||
static inline Vec2F32 rng2f32_dim(Rng2F32 r) { return (Vec2F32){r.p1.x - r.p0.x, r.p1.y - r.p0.y}; }
|
||||
static inline Vec2F32 rng2f32_center(Rng2F32 r) { return (Vec2F32){(r.p0.x + r.p1.x)*0.5f, (r.p0.y + r.p1.y)*0.5f}; }
|
||||
static inline B32 rng2f32_contains(Rng2F32 r, Vec2F32 p) {
|
||||
return p.x >= r.p0.x && p.x <= r.p1.x && p.y >= r.p0.y && p.y <= r.p1.y;
|
||||
}
|
||||
static inline Rng2F32 rng2f32_pad(Rng2F32 r, F32 p) {
|
||||
return (Rng2F32){{r.p0.x - p, r.p0.y - p}, {r.p1.x + p, r.p1.y + p}};
|
||||
}
|
||||
static inline Rng2F32 rng2f32_shift(Rng2F32 r, Vec2F32 v) {
|
||||
return (Rng2F32){{r.p0.x + v.x, r.p0.y + v.y}, {r.p1.x + v.x, r.p1.y + v.y}};
|
||||
}
|
||||
static inline Rng2F32 rng2f32_intersect(Rng2F32 a, Rng2F32 b) {
|
||||
return (Rng2F32){{Max(a.p0.x, b.p0.x), Max(a.p0.y, b.p0.y)},
|
||||
{Min(a.p1.x, b.p1.x), Min(a.p1.y, b.p1.y)}};
|
||||
}
|
||||
|
||||
// Axis-indexed range dimension
|
||||
static inline F32 rng2f32_dim_axis(Rng2F32 r, Axis2 a) {
|
||||
return a == Axis2_X ? (r.p1.x - r.p0.x) : (r.p1.y - r.p0.y);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// F32 helpers
|
||||
|
||||
static inline F32 lerp_1f32(F32 a, F32 b, F32 t) { return a + (b - a) * t; }
|
||||
static inline F32 abs_f32(F32 x) { return x < 0 ? -x : x; }
|
||||
34
src/base/base_strings.c
Normal file
34
src/base/base_strings.c
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "base/base_strings.h"
|
||||
#include "base/base_arena.h"
|
||||
|
||||
Str8 str8_pushf(Arena *arena, const char *fmt, ...) {
|
||||
va_list args, args2;
|
||||
va_start(args, fmt);
|
||||
va_copy(args2, args);
|
||||
S32 len = vsnprintf(NULL, 0, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
char *buf = push_array(arena, char, len + 1);
|
||||
vsnprintf(buf, len + 1, fmt, args2);
|
||||
va_end(args2);
|
||||
|
||||
Str8 r = {buf, (U64)len};
|
||||
return r;
|
||||
}
|
||||
|
||||
Str8 str8_push_copy(Arena *arena, Str8 s) {
|
||||
if (s.size == 0 || !s.str) { Str8 r = {NULL, 0}; return r; }
|
||||
char *buf = push_array_no_zero(arena, char, s.size + 1);
|
||||
MemoryCopy(buf, s.str, s.size);
|
||||
buf[s.size] = 0;
|
||||
Str8 r = {buf, s.size};
|
||||
return r;
|
||||
}
|
||||
|
||||
void str8_list_push(Arena *arena, Str8List *list, Str8 s) {
|
||||
Str8Node *node = push_array(arena, Str8Node, 1);
|
||||
node->string = s;
|
||||
SLLQueuePush(list->first, list->last, node);
|
||||
list->count++;
|
||||
list->total_size += s.size;
|
||||
}
|
||||
49
src/base/base_strings.h
Normal file
49
src/base/base_strings.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
// base_strings.h - Simple length-delimited string type
|
||||
// Inspired by raddebugger's String8
|
||||
|
||||
#include "base/base_core.h"
|
||||
|
||||
////////////////////////////////
|
||||
// String types
|
||||
|
||||
typedef struct Str8 {
|
||||
const char *str;
|
||||
U64 size;
|
||||
} Str8;
|
||||
|
||||
typedef struct Str8Node {
|
||||
struct Str8Node *next;
|
||||
Str8 string;
|
||||
} Str8Node;
|
||||
|
||||
typedef struct Str8List {
|
||||
Str8Node *first;
|
||||
Str8Node *last;
|
||||
U64 count;
|
||||
U64 total_size;
|
||||
} Str8List;
|
||||
|
||||
////////////////////////////////
|
||||
// Forward declaration for Arena
|
||||
typedef struct Arena Arena;
|
||||
|
||||
////////////////////////////////
|
||||
// Constructors
|
||||
|
||||
static inline Str8 str8(const char *s, U64 len) { Str8 r = {s, len}; return r; }
|
||||
static inline Str8 str8_cstr(const char *s) { Str8 r = {s, s ? (U64)strlen(s) : 0}; return r; }
|
||||
static inline Str8 str8_lit(const char *s) { Str8 r = {s, s ? (U64)strlen(s) : 0}; return r; }
|
||||
static inline B32 str8_match(Str8 a, Str8 b) {
|
||||
if (a.size != b.size) return 0;
|
||||
return MemoryCompare(a.str, b.str, a.size) == 0;
|
||||
}
|
||||
static inline B32 str8_is_empty(Str8 s) { return s.size == 0 || s.str == NULL; }
|
||||
|
||||
////////////////////////////////
|
||||
// String operations (require arena)
|
||||
|
||||
Str8 str8_pushf(Arena *arena, const char *fmt, ...);
|
||||
Str8 str8_push_copy(Arena *arena, Str8 s);
|
||||
|
||||
void str8_list_push(Arena *arena, Str8List *list, Str8 s);
|
||||
1987
src/daw/daw_main.c
Normal file
1987
src/daw/daw_main.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
#include "platform/platform.h"
|
||||
|
||||
enum MenuCmd {
|
||||
typedef enum MenuCmd {
|
||||
MENU_NONE = 0,
|
||||
MENU_FILE_NEW,
|
||||
MENU_FILE_OPEN,
|
||||
@@ -14,7 +14,8 @@ enum MenuCmd {
|
||||
MENU_VIEW_LOG,
|
||||
MENU_VIEW_DEMO,
|
||||
MENU_VIEW_MIDI_DEVICES,
|
||||
};
|
||||
MENU_PREFERENCES_EDIT,
|
||||
} MenuCmd;
|
||||
|
||||
static void setup_menus(PlatformWindow *window) {
|
||||
PlatformMenuItem file_items[] = {
|
||||
@@ -22,7 +23,7 @@ static void setup_menus(PlatformWindow *window) {
|
||||
{ "Open...", MENU_FILE_OPEN },
|
||||
{ "Save", MENU_FILE_SAVE },
|
||||
{ "Save As...", MENU_FILE_SAVE_AS },
|
||||
{ nullptr, 0 },
|
||||
{ NULL, 0 },
|
||||
{ "Exit", MENU_FILE_EXIT },
|
||||
};
|
||||
|
||||
@@ -35,15 +36,20 @@ static void setup_menus(PlatformWindow *window) {
|
||||
{ "Browser", MENU_VIEW_BROWSER },
|
||||
{ "Properties", MENU_VIEW_PROPERTIES },
|
||||
{ "Log", MENU_VIEW_LOG },
|
||||
{ nullptr, 0 },
|
||||
{ NULL, 0 },
|
||||
{ "Demo", MENU_VIEW_DEMO },
|
||||
{ "MIDI Devices", MENU_VIEW_MIDI_DEVICES },
|
||||
};
|
||||
|
||||
PlatformMenuItem prefs_items[] = {
|
||||
{ "Edit Preferences", MENU_PREFERENCES_EDIT },
|
||||
};
|
||||
|
||||
PlatformMenu menus[] = {
|
||||
{ "File", file_items, sizeof(file_items) / sizeof(file_items[0]) },
|
||||
{ "Import", import_items, sizeof(import_items) / sizeof(import_items[0]) },
|
||||
{ "View", view_items, sizeof(view_items) / sizeof(view_items[0]) },
|
||||
{ "File", file_items, sizeof(file_items) / sizeof(file_items[0]) },
|
||||
{ "Import", import_items, sizeof(import_items) / sizeof(import_items[0]) },
|
||||
{ "View", view_items, sizeof(view_items) / sizeof(view_items[0]) },
|
||||
{ "Preferences", prefs_items, sizeof(prefs_items) / sizeof(prefs_items[0]) },
|
||||
};
|
||||
|
||||
platform_set_menu(window, menus, sizeof(menus) / sizeof(menus[0]));
|
||||
161
src/main.cpp
161
src/main.cpp
@@ -1,161 +0,0 @@
|
||||
// Unity build - include all src files here
|
||||
// -mta
|
||||
// [h]
|
||||
#include "platform/platform.h"
|
||||
#include "renderer/renderer.h"
|
||||
#include "midi/midi.h"
|
||||
#include "imgui.h"
|
||||
#include "imgui_internal.h"
|
||||
#include <iostream>
|
||||
|
||||
// [cpp]
|
||||
#include "platform/platform_win32.cpp"
|
||||
#include "renderer/renderer_dx12.cpp"
|
||||
#include "midi/midi_win32.cpp"
|
||||
#include "menus.cpp"
|
||||
#include "theme.cpp"
|
||||
|
||||
|
||||
static void build_default_layout(ImGuiID dockspace_id) {
|
||||
ImGui::DockBuilderRemoveNode(dockspace_id);
|
||||
ImGui::DockBuilderAddNode(dockspace_id, ImGuiDockNodeFlags_DockSpace);
|
||||
ImGui::DockBuilderSetNodeSize(dockspace_id, ImGui::GetMainViewport()->Size);
|
||||
|
||||
ImGuiID center = dockspace_id;
|
||||
ImGuiID left = ImGui::DockBuilderSplitNode(center, ImGuiDir_Left, 0.15f, nullptr, ¢er);
|
||||
ImGuiID right = ImGui::DockBuilderSplitNode(center, ImGuiDir_Right, 0.20f, nullptr, ¢er);
|
||||
ImGuiID bottom = ImGui::DockBuilderSplitNode(center, ImGuiDir_Down, 0.25f, nullptr, ¢er);
|
||||
|
||||
ImGui::DockBuilderDockWindow("Browser", left);
|
||||
ImGui::DockBuilderDockWindow("Main", center);
|
||||
ImGui::DockBuilderDockWindow("Properties", right);
|
||||
ImGui::DockBuilderDockWindow("MIDI Devices", right);
|
||||
ImGui::DockBuilderDockWindow("Log", bottom);
|
||||
|
||||
ImGui::DockBuilderFinish(dockspace_id);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
std::cout << "Hello" << std::endl;
|
||||
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
PlatformWindowDesc window_desc = {};
|
||||
PlatformWindow *window = platform_create_window(&window_desc);
|
||||
if (!window)
|
||||
return 1;
|
||||
|
||||
int32_t w, h;
|
||||
platform_get_size(window, &w, &h);
|
||||
|
||||
RendererDesc renderer_desc = {};
|
||||
renderer_desc.window_handle = platform_get_native_handle(window);
|
||||
renderer_desc.width = w;
|
||||
renderer_desc.height = h;
|
||||
Renderer *renderer = renderer_create(&renderer_desc);
|
||||
if (!renderer) {
|
||||
platform_destroy_window(window);
|
||||
return 1;
|
||||
}
|
||||
|
||||
MidiEngine *midi = midi_create();
|
||||
|
||||
setup_theme();
|
||||
setup_menus(window);
|
||||
|
||||
int32_t last_w = w, last_h = h;
|
||||
bool show_demo = true;
|
||||
bool show_browser = true;
|
||||
bool show_props = true;
|
||||
bool show_log = true;
|
||||
bool show_midi_devices = true;
|
||||
bool first_frame = true;
|
||||
|
||||
while (platform_poll_events(window)) {
|
||||
int32_t menu_cmd = platform_poll_menu_command(window);
|
||||
switch (menu_cmd) {
|
||||
case MENU_FILE_EXIT: platform_destroy_window(window); return 0;
|
||||
case MENU_VIEW_BROWSER: show_browser = !show_browser; break;
|
||||
case MENU_VIEW_PROPERTIES:show_props = !show_props; break;
|
||||
case MENU_VIEW_LOG: show_log = !show_log; break;
|
||||
case MENU_VIEW_DEMO: show_demo = !show_demo; break;
|
||||
case MENU_VIEW_MIDI_DEVICES: show_midi_devices = !show_midi_devices; break;
|
||||
default: break;
|
||||
}
|
||||
platform_get_size(window, &w, &h);
|
||||
if (w != last_w || h != last_h) {
|
||||
renderer_resize(renderer, w, h);
|
||||
last_w = w;
|
||||
last_h = h;
|
||||
}
|
||||
|
||||
if (!renderer_begin_frame(renderer))
|
||||
continue;
|
||||
|
||||
// Full-window dockspace
|
||||
ImGuiID dockspace_id = ImGui::GetID("MainDockSpace");
|
||||
ImGui::DockSpaceOverViewport(dockspace_id, ImGui::GetMainViewport());
|
||||
|
||||
if (first_frame) {
|
||||
build_default_layout(dockspace_id);
|
||||
first_frame = false;
|
||||
}
|
||||
|
||||
// Left panel
|
||||
if (show_browser) {
|
||||
ImGui::Begin("Browser", &show_browser);
|
||||
ImGui::Text("Instruments");
|
||||
ImGui::Separator();
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
// Main content
|
||||
ImGui::Begin("Main");
|
||||
ImGui::Text("Main content area");
|
||||
ImGui::End();
|
||||
|
||||
// Right panel
|
||||
if (show_props) {
|
||||
ImGui::Begin("Properties", &show_props);
|
||||
ImGui::Text("Details");
|
||||
ImGui::Separator();
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
// MIDI Devices panel
|
||||
if (show_midi_devices) {
|
||||
ImGui::Begin("MIDI Devices", &show_midi_devices);
|
||||
if (ImGui::Button("Refresh"))
|
||||
midi_refresh_devices(midi);
|
||||
ImGui::Separator();
|
||||
for (int32_t i = 0; i < midi_get_device_count(midi); i++) {
|
||||
MidiDeviceInfo *dev = midi_get_device(midi, i);
|
||||
ImGui::Text("[%s] %s", dev->is_input ? "IN" : "OUT", dev->name);
|
||||
}
|
||||
if (midi_get_device_count(midi) == 0)
|
||||
ImGui::TextDisabled("No MIDI devices found");
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
// Bottom panel
|
||||
if (show_log) {
|
||||
ImGui::Begin("Log", &show_log);
|
||||
ImGui::Text("Output / Log");
|
||||
ImGui::Separator();
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
// Demo window
|
||||
if (show_demo)
|
||||
ImGui::ShowDemoWindow(&show_demo);
|
||||
|
||||
renderer_end_frame(renderer);
|
||||
}
|
||||
|
||||
midi_destroy(midi);
|
||||
renderer_destroy(renderer);
|
||||
platform_destroy_window(window);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,18 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "base/base_core.h"
|
||||
|
||||
struct MidiEngine;
|
||||
typedef struct MidiEngine MidiEngine;
|
||||
|
||||
struct MidiDeviceInfo {
|
||||
typedef struct MidiDeviceInfo {
|
||||
char name[64];
|
||||
int32_t id;
|
||||
bool is_input;
|
||||
};
|
||||
S32 id;
|
||||
B32 is_input;
|
||||
B32 active; // true when note(s) currently held
|
||||
B32 releasing; // true during release flash
|
||||
S32 velocity; // last note-on velocity (0-127)
|
||||
S32 note; // last MIDI note number (0-127)
|
||||
} MidiDeviceInfo;
|
||||
|
||||
MidiEngine *midi_create();
|
||||
MidiEngine *midi_create(void);
|
||||
void midi_destroy(MidiEngine *engine);
|
||||
void midi_refresh_devices(MidiEngine *engine);
|
||||
int32_t midi_get_device_count(MidiEngine *engine);
|
||||
MidiDeviceInfo *midi_get_device(MidiEngine *engine, int32_t index);
|
||||
S32 midi_get_device_count(MidiEngine *engine);
|
||||
MidiDeviceInfo *midi_get_device(MidiEngine *engine, S32 index);
|
||||
|
||||
void midi_open_all_inputs(MidiEngine *engine);
|
||||
void midi_close_all_inputs(MidiEngine *engine);
|
||||
void midi_update(MidiEngine *engine, F32 dt);
|
||||
B32 midi_is_input_active(MidiEngine *engine, S32 device_index);
|
||||
|
||||
// Per-note state: returns true if note (0-127) is currently held on any input device
|
||||
B32 midi_is_note_held(MidiEngine *engine, S32 note);
|
||||
// Returns the last note-on velocity (0-127) for a given note, or 0 if not held
|
||||
S32 midi_get_note_velocity(MidiEngine *engine, S32 note);
|
||||
|
||||
281
src/midi/midi_coremidi.c
Normal file
281
src/midi/midi_coremidi.c
Normal file
@@ -0,0 +1,281 @@
|
||||
#include "midi/midi.h"
|
||||
#include <CoreMIDI/CoreMIDI.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <string.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define MIDI_MAX_DEVICES 64
|
||||
#define MIDI_RELEASE_FLASH_DURATION 0.15f
|
||||
|
||||
struct MidiEngine {
|
||||
MidiDeviceInfo devices[MIDI_MAX_DEVICES];
|
||||
S32 device_count;
|
||||
|
||||
MIDIClientRef client;
|
||||
MIDIPortRef input_port;
|
||||
|
||||
// Map: source endpoint index -> our device array index
|
||||
S32 source_to_device[MIDI_MAX_DEVICES];
|
||||
|
||||
// Set atomically from callback thread
|
||||
_Atomic S32 pending_note_on_vel[MIDI_MAX_DEVICES];
|
||||
_Atomic S32 pending_note_num[MIDI_MAX_DEVICES];
|
||||
_Atomic S32 pending_note_off[MIDI_MAX_DEVICES];
|
||||
_Atomic S32 held_note_count[MIDI_MAX_DEVICES];
|
||||
|
||||
// Per-note state (across all devices), set atomically from callback
|
||||
_Atomic S32 note_states[128]; // held count
|
||||
_Atomic S32 note_velocities[128]; // last note-on velocity
|
||||
|
||||
// Main thread only
|
||||
S32 display_velocity[MIDI_MAX_DEVICES];
|
||||
S32 display_note[MIDI_MAX_DEVICES];
|
||||
F32 release_timers[MIDI_MAX_DEVICES];
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
// MIDI read callback
|
||||
|
||||
static void midi_read_callback(const MIDIPacketList *pktlist, void *readProcRefCon, void *srcConnRefCon) {
|
||||
(void)readProcRefCon;
|
||||
|
||||
MidiEngine *engine = (MidiEngine *)readProcRefCon;
|
||||
S32 device_idx = (S32)(intptr_t)srcConnRefCon;
|
||||
if (!engine || device_idx < 0 || device_idx >= MIDI_MAX_DEVICES) return;
|
||||
|
||||
const MIDIPacket *packet = &pktlist->packet[0];
|
||||
for (UInt32 i = 0; i < pktlist->numPackets; i++) {
|
||||
// Parse MIDI bytes
|
||||
for (UInt16 j = 0; j < packet->length; ) {
|
||||
U8 status = packet->data[j];
|
||||
|
||||
// Skip non-status bytes (running status not handled for simplicity)
|
||||
if (status < 0x80) { j++; continue; }
|
||||
|
||||
U8 kind = status & 0xF0;
|
||||
|
||||
if (kind == 0x90 && j + 2 < packet->length) {
|
||||
U8 note = packet->data[j + 1];
|
||||
U8 velocity = packet->data[j + 2];
|
||||
j += 3;
|
||||
|
||||
if (velocity > 0) {
|
||||
atomic_store(&engine->pending_note_on_vel[device_idx], (S32)velocity);
|
||||
atomic_store(&engine->pending_note_num[device_idx], (S32)(note + 1));
|
||||
atomic_fetch_add(&engine->held_note_count[device_idx], 1);
|
||||
if (note < 128) {
|
||||
atomic_fetch_add(&engine->note_states[note], 1);
|
||||
atomic_store(&engine->note_velocities[note], (S32)velocity);
|
||||
}
|
||||
} else {
|
||||
// Note-on with velocity 0 = note-off
|
||||
atomic_store(&engine->pending_note_off[device_idx], 1);
|
||||
S32 count = atomic_fetch_sub(&engine->held_note_count[device_idx], 1);
|
||||
if (count <= 1) atomic_store(&engine->held_note_count[device_idx], 0);
|
||||
if (note < 128) {
|
||||
S32 c = atomic_fetch_sub(&engine->note_states[note], 1);
|
||||
if (c <= 1) atomic_store(&engine->note_states[note], 0);
|
||||
}
|
||||
}
|
||||
} else if (kind == 0x80 && j + 2 < packet->length) {
|
||||
U8 note_off = packet->data[j + 1];
|
||||
j += 3;
|
||||
atomic_store(&engine->pending_note_off[device_idx], 1);
|
||||
S32 count = atomic_fetch_sub(&engine->held_note_count[device_idx], 1);
|
||||
if (count <= 1) atomic_store(&engine->held_note_count[device_idx], 0);
|
||||
if (note_off < 128) {
|
||||
S32 c = atomic_fetch_sub(&engine->note_states[note_off], 1);
|
||||
if (c <= 1) atomic_store(&engine->note_states[note_off], 0);
|
||||
}
|
||||
} else if (kind == 0xC0 || kind == 0xD0) {
|
||||
j += 2; // Program Change, Channel Pressure (2 bytes)
|
||||
} else if (kind == 0xF0) {
|
||||
// System messages — skip to end or next status byte
|
||||
j++;
|
||||
while (j < packet->length && packet->data[j] < 0x80) j++;
|
||||
} else {
|
||||
j += 3; // Default: 3-byte message
|
||||
}
|
||||
}
|
||||
|
||||
packet = MIDIPacketNext(packet);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Device enumeration
|
||||
|
||||
static void enumerate_midi_devices(MidiEngine *engine) {
|
||||
engine->device_count = 0;
|
||||
|
||||
// Input sources
|
||||
ItemCount num_sources = MIDIGetNumberOfSources();
|
||||
for (ItemCount i = 0; i < num_sources && engine->device_count < MIDI_MAX_DEVICES; i++) {
|
||||
MIDIEndpointRef endpoint = MIDIGetSource((ItemCount)i);
|
||||
|
||||
CFStringRef name_ref = NULL;
|
||||
MIDIObjectGetStringProperty(endpoint, kMIDIPropertyName, &name_ref);
|
||||
|
||||
MidiDeviceInfo *dev = &engine->devices[engine->device_count];
|
||||
memset(dev, 0, sizeof(*dev));
|
||||
|
||||
if (name_ref) {
|
||||
CFStringGetCString(name_ref, dev->name, sizeof(dev->name), kCFStringEncodingUTF8);
|
||||
CFRelease(name_ref);
|
||||
} else {
|
||||
snprintf(dev->name, sizeof(dev->name), "MIDI Source %d", (S32)i);
|
||||
}
|
||||
|
||||
dev->id = engine->device_count;
|
||||
dev->is_input = true;
|
||||
dev->active = false;
|
||||
|
||||
engine->source_to_device[i] = engine->device_count;
|
||||
engine->device_count++;
|
||||
}
|
||||
|
||||
// Output destinations
|
||||
ItemCount num_dests = MIDIGetNumberOfDestinations();
|
||||
for (ItemCount i = 0; i < num_dests && engine->device_count < MIDI_MAX_DEVICES; i++) {
|
||||
MIDIEndpointRef endpoint = MIDIGetDestination((ItemCount)i);
|
||||
|
||||
CFStringRef name_ref = NULL;
|
||||
MIDIObjectGetStringProperty(endpoint, kMIDIPropertyName, &name_ref);
|
||||
|
||||
MidiDeviceInfo *dev = &engine->devices[engine->device_count];
|
||||
memset(dev, 0, sizeof(*dev));
|
||||
|
||||
if (name_ref) {
|
||||
CFStringGetCString(name_ref, dev->name, sizeof(dev->name), kCFStringEncodingUTF8);
|
||||
CFRelease(name_ref);
|
||||
} else {
|
||||
snprintf(dev->name, sizeof(dev->name), "MIDI Dest %d", (S32)i);
|
||||
}
|
||||
|
||||
dev->id = engine->device_count;
|
||||
dev->is_input = false;
|
||||
dev->active = false;
|
||||
|
||||
engine->device_count++;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Public API
|
||||
|
||||
MidiEngine *midi_create(void) {
|
||||
MidiEngine *engine = (MidiEngine *)calloc(1, sizeof(MidiEngine));
|
||||
|
||||
MIDIClientCreate(CFSTR("autosample"), NULL, NULL, &engine->client);
|
||||
MIDIInputPortCreate(engine->client, CFSTR("Input"), midi_read_callback, engine, &engine->input_port);
|
||||
|
||||
midi_refresh_devices(engine);
|
||||
return engine;
|
||||
}
|
||||
|
||||
void midi_destroy(MidiEngine *engine) {
|
||||
midi_close_all_inputs(engine);
|
||||
if (engine->input_port) MIDIPortDispose(engine->input_port);
|
||||
if (engine->client) MIDIClientDispose(engine->client);
|
||||
free(engine);
|
||||
}
|
||||
|
||||
void midi_open_all_inputs(MidiEngine *engine) {
|
||||
ItemCount num_sources = MIDIGetNumberOfSources();
|
||||
for (ItemCount i = 0; i < num_sources && (S32)i < MIDI_MAX_DEVICES; i++) {
|
||||
MIDIEndpointRef endpoint = MIDIGetSource(i);
|
||||
S32 dev_idx = engine->source_to_device[i];
|
||||
MIDIPortConnectSource(engine->input_port, endpoint, (void *)(intptr_t)dev_idx);
|
||||
}
|
||||
}
|
||||
|
||||
void midi_close_all_inputs(MidiEngine *engine) {
|
||||
ItemCount num_sources = MIDIGetNumberOfSources();
|
||||
for (ItemCount i = 0; i < num_sources; i++) {
|
||||
MIDIEndpointRef endpoint = MIDIGetSource(i);
|
||||
MIDIPortDisconnectSource(engine->input_port, endpoint);
|
||||
}
|
||||
|
||||
for (S32 i = 0; i < MIDI_MAX_DEVICES; i++) {
|
||||
atomic_store(&engine->pending_note_on_vel[i], 0);
|
||||
atomic_store(&engine->pending_note_num[i], 0);
|
||||
atomic_store(&engine->pending_note_off[i], 0);
|
||||
atomic_store(&engine->held_note_count[i], 0);
|
||||
engine->display_velocity[i] = 0;
|
||||
engine->display_note[i] = 0;
|
||||
engine->release_timers[i] = 0.0f;
|
||||
}
|
||||
for (S32 i = 0; i < 128; i++) {
|
||||
atomic_store(&engine->note_states[i], 0);
|
||||
atomic_store(&engine->note_velocities[i], 0);
|
||||
}
|
||||
}
|
||||
|
||||
void midi_update(MidiEngine *engine, F32 dt) {
|
||||
for (S32 i = 0; i < engine->device_count; i++) {
|
||||
if (!engine->devices[i].is_input) continue;
|
||||
|
||||
S32 vel = atomic_exchange(&engine->pending_note_on_vel[i], 0);
|
||||
S32 note_p1 = atomic_exchange(&engine->pending_note_num[i], 0);
|
||||
if (vel > 0) engine->display_velocity[i] = vel;
|
||||
if (note_p1 > 0) engine->display_note[i] = note_p1 - 1;
|
||||
|
||||
S32 off = atomic_exchange(&engine->pending_note_off[i], 0);
|
||||
S32 held = atomic_load(&engine->held_note_count[i]);
|
||||
|
||||
if (held > 0) {
|
||||
engine->devices[i].active = true;
|
||||
engine->devices[i].releasing = false;
|
||||
engine->release_timers[i] = 0.0f;
|
||||
} else if (off || (engine->devices[i].active && held <= 0)) {
|
||||
engine->devices[i].active = false;
|
||||
engine->devices[i].releasing = true;
|
||||
engine->release_timers[i] = MIDI_RELEASE_FLASH_DURATION;
|
||||
}
|
||||
|
||||
if (engine->release_timers[i] > 0.0f) {
|
||||
engine->release_timers[i] -= dt;
|
||||
if (engine->release_timers[i] <= 0.0f) {
|
||||
engine->release_timers[i] = 0.0f;
|
||||
engine->devices[i].releasing = false;
|
||||
engine->display_velocity[i] = 0;
|
||||
engine->display_note[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
engine->devices[i].velocity = engine->display_velocity[i];
|
||||
engine->devices[i].note = engine->display_note[i];
|
||||
}
|
||||
}
|
||||
|
||||
B32 midi_is_input_active(MidiEngine *engine, S32 device_index) {
|
||||
if (device_index < 0 || device_index >= engine->device_count) return false;
|
||||
return engine->devices[device_index].active;
|
||||
}
|
||||
|
||||
B32 midi_is_note_held(MidiEngine *engine, S32 note) {
|
||||
if (note < 0 || note > 127) return false;
|
||||
return atomic_load(&engine->note_states[note]) > 0;
|
||||
}
|
||||
|
||||
S32 midi_get_note_velocity(MidiEngine *engine, S32 note) {
|
||||
if (note < 0 || note > 127) return 0;
|
||||
if (atomic_load(&engine->note_states[note]) <= 0) return 0;
|
||||
return atomic_load(&engine->note_velocities[note]);
|
||||
}
|
||||
|
||||
void midi_refresh_devices(MidiEngine *engine) {
|
||||
midi_close_all_inputs(engine);
|
||||
enumerate_midi_devices(engine);
|
||||
midi_open_all_inputs(engine);
|
||||
}
|
||||
|
||||
S32 midi_get_device_count(MidiEngine *engine) {
|
||||
return engine->device_count;
|
||||
}
|
||||
|
||||
MidiDeviceInfo *midi_get_device(MidiEngine *engine, S32 index) {
|
||||
if (index < 0 || index >= engine->device_count) return NULL;
|
||||
return &engine->devices[index];
|
||||
}
|
||||
229
src/midi/midi_win32.c
Normal file
229
src/midi/midi_win32.c
Normal file
@@ -0,0 +1,229 @@
|
||||
#include "midi/midi.h"
|
||||
#include <windows.h>
|
||||
#include <mmeapi.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define MIDI_MAX_DEVICES 64
|
||||
#define MIDI_RELEASE_FLASH_DURATION 0.15f
|
||||
|
||||
struct MidiEngine {
|
||||
MidiDeviceInfo devices[MIDI_MAX_DEVICES];
|
||||
S32 device_count;
|
||||
|
||||
HMIDIIN input_handles[MIDI_MAX_DEVICES];
|
||||
|
||||
// Set atomically from callback thread
|
||||
volatile LONG pending_note_on_vel[MIDI_MAX_DEVICES]; // last note-on velocity (0 = consumed)
|
||||
volatile LONG pending_note_num[MIDI_MAX_DEVICES]; // last note-on note number + 1 (0 = consumed)
|
||||
volatile LONG pending_note_off[MIDI_MAX_DEVICES]; // note-off received flag
|
||||
volatile LONG held_note_count[MIDI_MAX_DEVICES]; // number of notes currently held
|
||||
|
||||
// Per-note state (across all devices), set atomically from callback
|
||||
volatile LONG note_states[128]; // held count
|
||||
volatile LONG note_velocities[128]; // last note-on velocity
|
||||
|
||||
// Main thread only
|
||||
S32 display_velocity[MIDI_MAX_DEVICES];
|
||||
S32 display_note[MIDI_MAX_DEVICES];
|
||||
F32 release_timers[MIDI_MAX_DEVICES];
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
// MIDI input callback — called from Win32 MIDI driver thread
|
||||
|
||||
static MidiEngine *g_midi_engine = NULL;
|
||||
|
||||
static void CALLBACK midi_in_callback(HMIDIIN hMidiIn, UINT wMsg, DWORD_PTR dwInstance,
|
||||
DWORD_PTR dwParam1, DWORD_PTR dwParam2) {
|
||||
(void)hMidiIn;
|
||||
(void)dwParam2;
|
||||
|
||||
if (wMsg != MIM_DATA) return;
|
||||
if (!g_midi_engine) return;
|
||||
|
||||
S32 idx = (S32)dwInstance;
|
||||
if (idx < 0 || idx >= MIDI_MAX_DEVICES) return;
|
||||
|
||||
BYTE status = (BYTE)(dwParam1 & 0xFF);
|
||||
BYTE note = (BYTE)((dwParam1 >> 8) & 0xFF);
|
||||
BYTE velocity = (BYTE)((dwParam1 >> 16) & 0xFF);
|
||||
BYTE kind = status & 0xF0;
|
||||
|
||||
// Note-on with velocity > 0
|
||||
if (kind == 0x90 && velocity > 0) {
|
||||
InterlockedExchange(&g_midi_engine->pending_note_on_vel[idx], (LONG)velocity);
|
||||
InterlockedExchange(&g_midi_engine->pending_note_num[idx], (LONG)(note + 1)); // +1 so 0 means "no pending"
|
||||
InterlockedIncrement(&g_midi_engine->held_note_count[idx]);
|
||||
if (note < 128) {
|
||||
InterlockedIncrement(&g_midi_engine->note_states[note]);
|
||||
InterlockedExchange(&g_midi_engine->note_velocities[note], (LONG)velocity);
|
||||
}
|
||||
}
|
||||
// Note-off (0x80) or note-on with velocity 0 (running status note-off)
|
||||
else if (kind == 0x80 || (kind == 0x90 && velocity == 0)) {
|
||||
InterlockedExchange(&g_midi_engine->pending_note_off[idx], 1);
|
||||
LONG count = InterlockedDecrement(&g_midi_engine->held_note_count[idx]);
|
||||
if (count < 0) InterlockedExchange(&g_midi_engine->held_note_count[idx], 0);
|
||||
if (note < 128) {
|
||||
LONG c = InterlockedDecrement(&g_midi_engine->note_states[note]);
|
||||
if (c < 0) InterlockedExchange(&g_midi_engine->note_states[note], 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MidiEngine *midi_create(void) {
|
||||
MidiEngine *engine = (MidiEngine *)calloc(1, sizeof(MidiEngine));
|
||||
g_midi_engine = engine;
|
||||
midi_refresh_devices(engine);
|
||||
return engine;
|
||||
}
|
||||
|
||||
void midi_destroy(MidiEngine *engine) {
|
||||
midi_close_all_inputs(engine);
|
||||
if (g_midi_engine == engine) g_midi_engine = NULL;
|
||||
free(engine);
|
||||
}
|
||||
|
||||
void midi_open_all_inputs(MidiEngine *engine) {
|
||||
for (S32 i = 0; i < engine->device_count; i++) {
|
||||
MidiDeviceInfo *dev = &engine->devices[i];
|
||||
if (!dev->is_input) continue;
|
||||
if (engine->input_handles[i]) continue; // already open
|
||||
|
||||
HMIDIIN handle = NULL;
|
||||
MMRESULT res = midiInOpen(&handle, (UINT)dev->id,
|
||||
(DWORD_PTR)midi_in_callback,
|
||||
(DWORD_PTR)i, CALLBACK_FUNCTION);
|
||||
if (res == MMSYSERR_NOERROR) {
|
||||
engine->input_handles[i] = handle;
|
||||
midiInStart(handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void midi_close_all_inputs(MidiEngine *engine) {
|
||||
for (S32 i = 0; i < MIDI_MAX_DEVICES; i++) {
|
||||
if (engine->input_handles[i]) {
|
||||
midiInStop(engine->input_handles[i]);
|
||||
midiInClose(engine->input_handles[i]);
|
||||
engine->input_handles[i] = NULL;
|
||||
}
|
||||
engine->pending_note_on_vel[i] = 0;
|
||||
engine->pending_note_num[i] = 0;
|
||||
engine->pending_note_off[i] = 0;
|
||||
engine->held_note_count[i] = 0;
|
||||
engine->display_velocity[i] = 0;
|
||||
engine->display_note[i] = 0;
|
||||
engine->release_timers[i] = 0.0f;
|
||||
}
|
||||
for (S32 i = 0; i < 128; i++) {
|
||||
engine->note_states[i] = 0;
|
||||
engine->note_velocities[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void midi_update(MidiEngine *engine, F32 dt) {
|
||||
for (S32 i = 0; i < engine->device_count; i++) {
|
||||
if (!engine->devices[i].is_input) continue;
|
||||
|
||||
// Consume pending note-on velocity and note number
|
||||
LONG vel = InterlockedExchange(&engine->pending_note_on_vel[i], 0);
|
||||
LONG note_p1 = InterlockedExchange(&engine->pending_note_num[i], 0);
|
||||
if (vel > 0) {
|
||||
engine->display_velocity[i] = (S32)vel;
|
||||
}
|
||||
if (note_p1 > 0) {
|
||||
engine->display_note[i] = (S32)(note_p1 - 1);
|
||||
}
|
||||
|
||||
// Consume pending note-off
|
||||
LONG off = InterlockedExchange(&engine->pending_note_off[i], 0);
|
||||
|
||||
// Read held note count
|
||||
LONG held = engine->held_note_count[i];
|
||||
|
||||
if (held > 0) {
|
||||
engine->devices[i].active = true;
|
||||
engine->devices[i].releasing = false;
|
||||
engine->release_timers[i] = 0.0f;
|
||||
} else if (off || (engine->devices[i].active && held <= 0)) {
|
||||
// All notes just released — start release flash
|
||||
engine->devices[i].active = false;
|
||||
engine->devices[i].releasing = true;
|
||||
engine->release_timers[i] = MIDI_RELEASE_FLASH_DURATION;
|
||||
}
|
||||
|
||||
// Decay release flash timer
|
||||
if (engine->release_timers[i] > 0.0f) {
|
||||
engine->release_timers[i] -= dt;
|
||||
if (engine->release_timers[i] <= 0.0f) {
|
||||
engine->release_timers[i] = 0.0f;
|
||||
engine->devices[i].releasing = false;
|
||||
engine->display_velocity[i] = 0;
|
||||
engine->display_note[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
engine->devices[i].velocity = engine->display_velocity[i];
|
||||
engine->devices[i].note = engine->display_note[i];
|
||||
}
|
||||
}
|
||||
|
||||
B32 midi_is_input_active(MidiEngine *engine, S32 device_index) {
|
||||
if (device_index < 0 || device_index >= engine->device_count)
|
||||
return false;
|
||||
return engine->devices[device_index].active;
|
||||
}
|
||||
|
||||
B32 midi_is_note_held(MidiEngine *engine, S32 note) {
|
||||
if (note < 0 || note > 127) return false;
|
||||
return engine->note_states[note] > 0;
|
||||
}
|
||||
|
||||
S32 midi_get_note_velocity(MidiEngine *engine, S32 note) {
|
||||
if (note < 0 || note > 127) return 0;
|
||||
if (engine->note_states[note] <= 0) return 0;
|
||||
return (S32)engine->note_velocities[note];
|
||||
}
|
||||
|
||||
void midi_refresh_devices(MidiEngine *engine) {
|
||||
midi_close_all_inputs(engine);
|
||||
engine->device_count = 0;
|
||||
|
||||
UINT num_in = midiInGetNumDevs();
|
||||
for (UINT i = 0; i < num_in && engine->device_count < MIDI_MAX_DEVICES; i++) {
|
||||
MIDIINCAPSA caps = {0};
|
||||
if (midiInGetDevCapsA(i, &caps, sizeof(caps)) == MMSYSERR_NOERROR) {
|
||||
MidiDeviceInfo *dev = &engine->devices[engine->device_count++];
|
||||
strncpy_s(dev->name, sizeof(dev->name), caps.szPname, _TRUNCATE);
|
||||
dev->id = (S32)i;
|
||||
dev->is_input = true;
|
||||
dev->active = false;
|
||||
}
|
||||
}
|
||||
|
||||
UINT num_out = midiOutGetNumDevs();
|
||||
for (UINT i = 0; i < num_out && engine->device_count < MIDI_MAX_DEVICES; i++) {
|
||||
MIDIOUTCAPSA caps = {0};
|
||||
if (midiOutGetDevCapsA(i, &caps, sizeof(caps)) == MMSYSERR_NOERROR) {
|
||||
MidiDeviceInfo *dev = &engine->devices[engine->device_count++];
|
||||
strncpy_s(dev->name, sizeof(dev->name), caps.szPname, _TRUNCATE);
|
||||
dev->id = (S32)i;
|
||||
dev->is_input = false;
|
||||
dev->active = false;
|
||||
}
|
||||
}
|
||||
|
||||
midi_open_all_inputs(engine);
|
||||
}
|
||||
|
||||
S32 midi_get_device_count(MidiEngine *engine) {
|
||||
return engine->device_count;
|
||||
}
|
||||
|
||||
MidiDeviceInfo *midi_get_device(MidiEngine *engine, S32 index) {
|
||||
if (index < 0 || index >= engine->device_count)
|
||||
return NULL;
|
||||
return &engine->devices[index];
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
#include "midi/midi.h"
|
||||
#include <windows.h>
|
||||
#include <mmeapi.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MIDI_MAX_DEVICES 64
|
||||
|
||||
struct MidiEngine {
|
||||
MidiDeviceInfo devices[MIDI_MAX_DEVICES];
|
||||
int32_t device_count;
|
||||
};
|
||||
|
||||
MidiEngine *midi_create() {
|
||||
MidiEngine *engine = new MidiEngine();
|
||||
engine->device_count = 0;
|
||||
midi_refresh_devices(engine);
|
||||
return engine;
|
||||
}
|
||||
|
||||
void midi_destroy(MidiEngine *engine) {
|
||||
delete engine;
|
||||
}
|
||||
|
||||
void midi_refresh_devices(MidiEngine *engine) {
|
||||
engine->device_count = 0;
|
||||
|
||||
UINT num_in = midiInGetNumDevs();
|
||||
for (UINT i = 0; i < num_in && engine->device_count < MIDI_MAX_DEVICES; i++) {
|
||||
MIDIINCAPSA caps = {};
|
||||
if (midiInGetDevCapsA(i, &caps, sizeof(caps)) == MMSYSERR_NOERROR) {
|
||||
MidiDeviceInfo *dev = &engine->devices[engine->device_count++];
|
||||
strncpy_s(dev->name, sizeof(dev->name), caps.szPname, _TRUNCATE);
|
||||
dev->id = (int32_t)i;
|
||||
dev->is_input = true;
|
||||
}
|
||||
}
|
||||
|
||||
UINT num_out = midiOutGetNumDevs();
|
||||
for (UINT i = 0; i < num_out && engine->device_count < MIDI_MAX_DEVICES; i++) {
|
||||
MIDIOUTCAPSA caps = {};
|
||||
if (midiOutGetDevCapsA(i, &caps, sizeof(caps)) == MMSYSERR_NOERROR) {
|
||||
MidiDeviceInfo *dev = &engine->devices[engine->device_count++];
|
||||
strncpy_s(dev->name, sizeof(dev->name), caps.szPname, _TRUNCATE);
|
||||
dev->id = (int32_t)i;
|
||||
dev->is_input = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t midi_get_device_count(MidiEngine *engine) {
|
||||
return engine->device_count;
|
||||
}
|
||||
|
||||
MidiDeviceInfo *midi_get_device(MidiEngine *engine, int32_t index) {
|
||||
if (index < 0 || index >= engine->device_count)
|
||||
return nullptr;
|
||||
return &engine->devices[index];
|
||||
}
|
||||
@@ -1,32 +1,142 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "base/base_core.h"
|
||||
#include "base/base_math.h"
|
||||
|
||||
struct PlatformWindow;
|
||||
////////////////////////////////
|
||||
// Input — accumulated per frame, consumed by the app each tick.
|
||||
|
||||
struct PlatformWindowDesc {
|
||||
const char *title = "autosample";
|
||||
int32_t width = 1280;
|
||||
int32_t height = 720;
|
||||
#define PLATFORM_MAX_CHARS_PER_FRAME 64
|
||||
#define PLATFORM_MAX_KEYS_PER_FRAME 32
|
||||
|
||||
// Virtual key codes (subset matching Win32 VK_ codes)
|
||||
enum {
|
||||
PKEY_BACKSPACE = 0x08,
|
||||
PKEY_TAB = 0x09,
|
||||
PKEY_RETURN = 0x0D,
|
||||
PKEY_ESCAPE = 0x1B,
|
||||
PKEY_DELETE = 0x2E,
|
||||
PKEY_LEFT = 0x25,
|
||||
PKEY_UP = 0x26,
|
||||
PKEY_RIGHT = 0x27,
|
||||
PKEY_DOWN = 0x28,
|
||||
PKEY_HOME = 0x24,
|
||||
PKEY_END = 0x23,
|
||||
PKEY_A = 0x41,
|
||||
PKEY_C = 0x43,
|
||||
PKEY_V = 0x56,
|
||||
PKEY_X = 0x58,
|
||||
PKEY_0 = 0x30,
|
||||
PKEY_EQUAL = 0xBB, // '='/'+' (VK_OEM_PLUS)
|
||||
PKEY_MINUS = 0xBD, // '-'/'_' (VK_OEM_MINUS)
|
||||
};
|
||||
|
||||
struct PlatformMenuItem {
|
||||
const char *label; // nullptr = separator
|
||||
int32_t id; // command ID (ignored for separators)
|
||||
};
|
||||
typedef struct PlatformInput {
|
||||
// Typed characters (UTF-16 code units, printable only)
|
||||
U16 chars[PLATFORM_MAX_CHARS_PER_FRAME];
|
||||
S32 char_count;
|
||||
|
||||
struct PlatformMenu {
|
||||
// Key-down events (virtual key codes)
|
||||
U8 keys[PLATFORM_MAX_KEYS_PER_FRAME];
|
||||
S32 key_count;
|
||||
|
||||
// Modifier state at time of last key event
|
||||
B32 ctrl_held;
|
||||
B32 shift_held;
|
||||
|
||||
// Mouse state (polled per frame)
|
||||
Vec2F32 mouse_pos;
|
||||
Vec2F32 scroll_delta;
|
||||
B32 mouse_down;
|
||||
B32 was_mouse_down;
|
||||
} PlatformInput;
|
||||
|
||||
typedef struct PlatformWindow PlatformWindow;
|
||||
|
||||
typedef enum PlatformWindowStyle {
|
||||
PLATFORM_WINDOW_STYLE_NORMAL = 0,
|
||||
PLATFORM_WINDOW_STYLE_POPUP = 1, // utility panel, owned by parent, fixed size
|
||||
PLATFORM_WINDOW_STYLE_POPUP_RESIZABLE = 2, // utility panel, owned by parent, resizable
|
||||
} PlatformWindowStyle;
|
||||
|
||||
typedef struct PlatformWindowDesc {
|
||||
const char *title;
|
||||
S32 width;
|
||||
S32 height;
|
||||
PlatformWindowStyle style;
|
||||
PlatformWindow *parent;
|
||||
B32 independent; // if true, don't attach as child (independent top-level window)
|
||||
} PlatformWindowDesc;
|
||||
|
||||
// Helper to create a default PlatformWindowDesc
|
||||
static inline PlatformWindowDesc platform_window_desc_default(void) {
|
||||
PlatformWindowDesc d = {0};
|
||||
d.title = "autosample";
|
||||
d.width = 1280;
|
||||
d.height = 720;
|
||||
return d;
|
||||
}
|
||||
|
||||
typedef enum PlatformMsgBoxType {
|
||||
PLATFORM_MSGBOX_OK = 0,
|
||||
PLATFORM_MSGBOX_OK_CANCEL = 1,
|
||||
PLATFORM_MSGBOX_YES_NO = 2,
|
||||
} PlatformMsgBoxType;
|
||||
|
||||
typedef struct PlatformMenuItem {
|
||||
const char *label; // NULL = separator
|
||||
S32 id; // command ID (ignored for separators)
|
||||
} PlatformMenuItem;
|
||||
|
||||
typedef struct PlatformMenu {
|
||||
const char *label;
|
||||
PlatformMenuItem *items;
|
||||
int32_t item_count;
|
||||
};
|
||||
S32 item_count;
|
||||
} PlatformMenu;
|
||||
|
||||
// Called by the platform layer when the window needs a frame rendered
|
||||
// (e.g., during a live resize). user_data is the pointer passed to
|
||||
// platform_set_frame_callback.
|
||||
typedef void (*PlatformFrameCallback)(void *user_data);
|
||||
|
||||
PlatformWindow *platform_create_window(PlatformWindowDesc *desc);
|
||||
void platform_destroy_window(PlatformWindow *window);
|
||||
bool platform_poll_events(PlatformWindow *window);
|
||||
void platform_get_size(PlatformWindow *window, int32_t *w, int32_t *h);
|
||||
B32 platform_poll_events(PlatformWindow *window);
|
||||
void platform_get_size(PlatformWindow *window, S32 *w, S32 *h);
|
||||
void *platform_get_native_handle(PlatformWindow *window);
|
||||
|
||||
void platform_set_menu(PlatformWindow *window, PlatformMenu *menus, int32_t menu_count);
|
||||
int32_t platform_poll_menu_command(PlatformWindow *window);
|
||||
void platform_set_frame_callback(PlatformWindow *window, PlatformFrameCallback cb, void *user_data);
|
||||
void platform_set_menu(PlatformWindow *window, PlatformMenu *menus, S32 menu_count);
|
||||
S32 platform_poll_menu_command(PlatformWindow *window);
|
||||
|
||||
// Returns accumulated input since last call (keyboard events + polled mouse state), then clears the buffer.
|
||||
PlatformInput platform_get_input(PlatformWindow *window);
|
||||
|
||||
// Returns true if the window's close button was clicked (for popup windows).
|
||||
B32 platform_window_should_close(PlatformWindow *window);
|
||||
|
||||
// Bring a window to front and give it keyboard focus.
|
||||
void platform_focus_window(PlatformWindow *window);
|
||||
|
||||
// Blocks until user responds. Returns 0=first button, 1=second button, -1=dismissed.
|
||||
S32 platform_message_box(PlatformWindow *parent, const char *title,
|
||||
const char *message, PlatformMsgBoxType type);
|
||||
|
||||
// Cursor shapes for resize handles
|
||||
typedef enum PlatformCursor {
|
||||
PLATFORM_CURSOR_ARROW = 0,
|
||||
PLATFORM_CURSOR_SIZE_WE = 1, // horizontal resize
|
||||
PLATFORM_CURSOR_SIZE_NS = 2, // vertical resize
|
||||
} PlatformCursor;
|
||||
|
||||
void platform_set_cursor(PlatformCursor cursor);
|
||||
|
||||
// DPI scale factor for the window's current monitor.
|
||||
// Returns 1.0 at 96 DPI (100%), 1.5 at 144 DPI (150%), etc.
|
||||
F32 platform_get_dpi_scale(PlatformWindow *window);
|
||||
|
||||
// Clipboard operations (null-terminated UTF-8 strings).
|
||||
// platform_clipboard_set copies text to the system clipboard.
|
||||
// platform_clipboard_get returns a pointer to a static buffer (valid until next call), or NULL.
|
||||
void platform_clipboard_set(const char *text);
|
||||
const char *platform_clipboard_get(void);
|
||||
|
||||
529
src/platform/platform_macos.m
Normal file
529
src/platform/platform_macos.m
Normal file
@@ -0,0 +1,529 @@
|
||||
#include "platform/platform.h"
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
// macOS virtual key codes (avoids Carbon.h include)
|
||||
enum {
|
||||
kVK_ANSI_A = 0x00, kVK_ANSI_C = 0x08, kVK_ANSI_V = 0x09,
|
||||
kVK_ANSI_X = 0x07,
|
||||
kVK_Return = 0x24, kVK_Tab = 0x30, kVK_Delete = 0x33,
|
||||
kVK_Escape = 0x35, kVK_ForwardDelete = 0x75,
|
||||
kVK_LeftArrow = 0x7B, kVK_RightArrow = 0x7C,
|
||||
kVK_DownArrow = 0x7D, kVK_UpArrow = 0x7E,
|
||||
kVK_Home = 0x73, kVK_End = 0x77,
|
||||
kVK_Command = 0x37, kVK_Shift = 0x38,
|
||||
kVK_RightShift = 0x3C, kVK_RightCommand = 0x36,
|
||||
kVK_ANSI_Equal = 0x18, kVK_ANSI_Minus = 0x1B,
|
||||
kVK_ANSI_0 = 0x1D,
|
||||
kVK_ANSI_KeypadEnter = 0x4C,
|
||||
};
|
||||
|
||||
static U8 macos_keycode_to_pkey(U16 keycode) {
|
||||
switch (keycode) {
|
||||
case kVK_ANSI_A: return PKEY_A;
|
||||
case kVK_ANSI_C: return PKEY_C;
|
||||
case kVK_ANSI_V: return PKEY_V;
|
||||
case kVK_ANSI_X: return PKEY_X;
|
||||
case kVK_Return: return PKEY_RETURN;
|
||||
case kVK_ANSI_KeypadEnter: return PKEY_RETURN;
|
||||
case kVK_Tab: return PKEY_TAB;
|
||||
case kVK_Delete: return PKEY_BACKSPACE;
|
||||
case kVK_ForwardDelete:return PKEY_DELETE;
|
||||
case kVK_Escape: return PKEY_ESCAPE;
|
||||
case kVK_LeftArrow: return PKEY_LEFT;
|
||||
case kVK_RightArrow: return PKEY_RIGHT;
|
||||
case kVK_UpArrow: return PKEY_UP;
|
||||
case kVK_DownArrow: return PKEY_DOWN;
|
||||
case kVK_Home: return PKEY_HOME;
|
||||
case kVK_End: return PKEY_END;
|
||||
case kVK_ANSI_Equal: return PKEY_EQUAL;
|
||||
case kVK_ANSI_Minus: return PKEY_MINUS;
|
||||
case kVK_ANSI_0: return PKEY_0;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Forward declarations
|
||||
|
||||
// Main window receives menu commands
|
||||
static PlatformWindow *g_main_window = NULL;
|
||||
|
||||
////////////////////////////////
|
||||
// Objective-C helper classes
|
||||
|
||||
@interface ASmplAppDelegate : NSObject <NSApplicationDelegate>
|
||||
@end
|
||||
|
||||
@implementation ASmplAppDelegate
|
||||
- (void)applicationDidFinishLaunching:(NSNotification *)notification { (void)notification; }
|
||||
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender { (void)sender; return YES; }
|
||||
@end
|
||||
|
||||
@interface ASmplWindowDelegate : NSObject <NSWindowDelegate> {
|
||||
@public
|
||||
PlatformWindow *_platformWindow;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface ASmplView : NSView <NSTextInputClient> {
|
||||
@public
|
||||
PlatformWindow *_platformWindow;
|
||||
}
|
||||
@end
|
||||
|
||||
////////////////////////////////
|
||||
// PlatformWindow struct
|
||||
|
||||
typedef struct PlatformWindow {
|
||||
NSWindow *ns_window;
|
||||
ASmplView *view;
|
||||
ASmplWindowDelegate *delegate;
|
||||
B32 should_close;
|
||||
S32 width;
|
||||
S32 height;
|
||||
S32 pending_menu_cmd;
|
||||
PlatformFrameCallback frame_callback;
|
||||
void *frame_callback_user_data;
|
||||
PlatformInput input;
|
||||
B32 prev_mouse_down;
|
||||
B32 mouse_down_state;
|
||||
F32 backing_scale;
|
||||
} PlatformWindow;
|
||||
|
||||
////////////////////////////////
|
||||
// C callback helpers (called from ObjC via PlatformWindow pointer)
|
||||
|
||||
static void platform_macos_insert_text_pw(PlatformWindow *pw, const char *utf8) {
|
||||
if (!pw || !utf8) return;
|
||||
PlatformInput *ev = &pw->input;
|
||||
while (*utf8 && ev->char_count < PLATFORM_MAX_CHARS_PER_FRAME) {
|
||||
U8 c = (U8)*utf8;
|
||||
if (c < 32) { utf8++; continue; }
|
||||
// Handle ASCII printable range (single-byte UTF-8)
|
||||
if (c < 0x80) {
|
||||
ev->chars[ev->char_count++] = (U16)c;
|
||||
utf8++;
|
||||
} else {
|
||||
// Skip multi-byte UTF-8 sequences for now (UI only handles ASCII)
|
||||
if (c < 0xE0) utf8 += 2;
|
||||
else if (c < 0xF0) utf8 += 3;
|
||||
else utf8 += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void platform_macos_key_down_pw(PlatformWindow *pw, U16 keycode, NSEventModifierFlags mods) {
|
||||
if (!pw) return;
|
||||
PlatformInput *ev = &pw->input;
|
||||
|
||||
U8 pkey = macos_keycode_to_pkey(keycode);
|
||||
if (pkey && ev->key_count < PLATFORM_MAX_KEYS_PER_FRAME)
|
||||
ev->keys[ev->key_count++] = pkey;
|
||||
|
||||
// Command = ctrl_held (macOS convention: Cmd+C, Cmd+V, etc.)
|
||||
ev->ctrl_held = (mods & NSEventModifierFlagCommand) != 0;
|
||||
ev->shift_held = (mods & NSEventModifierFlagShift) != 0;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// ObjC class implementations
|
||||
|
||||
@implementation ASmplWindowDelegate
|
||||
- (BOOL)windowShouldClose:(id)sender {
|
||||
(void)sender;
|
||||
if (_platformWindow) {
|
||||
_platformWindow->should_close = true;
|
||||
}
|
||||
return NO; // We handle closing ourselves
|
||||
}
|
||||
|
||||
- (void)windowDidResize:(NSNotification *)notification {
|
||||
(void)notification;
|
||||
if (!_platformWindow) return;
|
||||
PlatformWindow *pw = _platformWindow;
|
||||
NSRect frame = [pw->view bounds];
|
||||
F32 scale = pw->backing_scale;
|
||||
pw->width = (S32)(frame.size.width * scale);
|
||||
pw->height = (S32)(frame.size.height * scale);
|
||||
if (pw->frame_callback)
|
||||
pw->frame_callback(pw->frame_callback_user_data);
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation ASmplView
|
||||
|
||||
- (BOOL)acceptsFirstResponder { return YES; }
|
||||
- (BOOL)canBecomeKeyView { return YES; }
|
||||
|
||||
// Needed for NSTextInputClient
|
||||
- (BOOL)hasMarkedText { return NO; }
|
||||
- (NSRange)markedRange { return NSMakeRange(NSNotFound, 0); }
|
||||
- (NSRange)selectedRange { return NSMakeRange(NSNotFound, 0); }
|
||||
- (void)setMarkedText:(id)string selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange {
|
||||
(void)string; (void)selectedRange; (void)replacementRange;
|
||||
}
|
||||
- (void)unmarkText {}
|
||||
- (NSArray<NSAttributedStringKey> *)validAttributesForMarkedText { return @[]; }
|
||||
- (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)range actualRange:(NSRangePointer)actualRange {
|
||||
(void)range; (void)actualRange;
|
||||
return nil;
|
||||
}
|
||||
- (NSUInteger)characterIndexForPoint:(NSPoint)point { (void)point; return NSNotFound; }
|
||||
- (NSRect)firstRectForCharacterRange:(NSRange)range actualRange:(NSRangePointer)actualRange {
|
||||
(void)range; (void)actualRange;
|
||||
return NSZeroRect;
|
||||
}
|
||||
|
||||
- (void)insertText:(id)string replacementRange:(NSRange)replacementRange {
|
||||
(void)replacementRange;
|
||||
NSString *str = nil;
|
||||
if ([string isKindOfClass:[NSAttributedString class]])
|
||||
str = [string string];
|
||||
else
|
||||
str = (NSString *)string;
|
||||
|
||||
platform_macos_insert_text_pw(_platformWindow, [str UTF8String]);
|
||||
}
|
||||
|
||||
- (void)keyDown:(NSEvent *)event {
|
||||
platform_macos_key_down_pw(_platformWindow, [event keyCode], [event modifierFlags]);
|
||||
|
||||
// Feed into text input system for character generation
|
||||
[self interpretKeyEvents:@[event]];
|
||||
}
|
||||
|
||||
- (void)flagsChanged:(NSEvent *)event {
|
||||
(void)event;
|
||||
// Modifiers are read at key-down time, nothing to accumulate here
|
||||
}
|
||||
|
||||
- (void)mouseDown:(NSEvent *)event {
|
||||
(void)event;
|
||||
if (_platformWindow) _platformWindow->mouse_down_state = 1;
|
||||
}
|
||||
|
||||
- (void)mouseUp:(NSEvent *)event {
|
||||
(void)event;
|
||||
if (_platformWindow) _platformWindow->mouse_down_state = 0;
|
||||
}
|
||||
|
||||
- (void)mouseMoved:(NSEvent *)event { (void)event; }
|
||||
- (void)mouseDragged:(NSEvent *)event { (void)event; }
|
||||
|
||||
- (void)scrollWheel:(NSEvent *)event {
|
||||
if (!_platformWindow) return;
|
||||
F32 dy = (F32)[event scrollingDeltaY];
|
||||
if ([event hasPreciseScrollingDeltas])
|
||||
dy /= 40.0f; // Normalize trackpad deltas to match discrete wheel steps
|
||||
_platformWindow->input.scroll_delta.y += dy;
|
||||
}
|
||||
|
||||
- (BOOL)acceptsFirstMouse:(NSEvent *)event { (void)event; return YES; }
|
||||
|
||||
@end
|
||||
|
||||
////////////////////////////////
|
||||
// Menu action handler
|
||||
|
||||
@interface ASmplMenuTarget : NSObject
|
||||
- (void)menuAction:(id)sender;
|
||||
@end
|
||||
|
||||
@implementation ASmplMenuTarget
|
||||
- (void)menuAction:(id)sender {
|
||||
if (!g_main_window) return;
|
||||
NSMenuItem *item = (NSMenuItem *)sender;
|
||||
g_main_window->pending_menu_cmd = (S32)[item tag];
|
||||
}
|
||||
@end
|
||||
|
||||
static ASmplMenuTarget *g_menu_target = nil;
|
||||
|
||||
////////////////////////////////
|
||||
// Public API
|
||||
|
||||
PlatformWindow *platform_create_window(PlatformWindowDesc *desc) {
|
||||
// Ensure NSApplication is initialized and properly launched
|
||||
[NSApplication sharedApplication];
|
||||
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
||||
|
||||
static ASmplAppDelegate *app_delegate = nil;
|
||||
if (!app_delegate) {
|
||||
app_delegate = [[ASmplAppDelegate alloc] init];
|
||||
[NSApp setDelegate:app_delegate];
|
||||
[NSApp finishLaunching];
|
||||
}
|
||||
|
||||
NSRect content_rect = NSMakeRect(0, 0, desc->width, desc->height);
|
||||
|
||||
NSWindowStyleMask style_mask;
|
||||
if (desc->style == PLATFORM_WINDOW_STYLE_POPUP) {
|
||||
style_mask = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable;
|
||||
} else if (desc->style == PLATFORM_WINDOW_STYLE_POPUP_RESIZABLE) {
|
||||
style_mask = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskResizable;
|
||||
} else {
|
||||
style_mask = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
|
||||
NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable;
|
||||
}
|
||||
|
||||
NSWindow *ns_window = [[NSWindow alloc]
|
||||
initWithContentRect:content_rect
|
||||
styleMask:style_mask
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:NO];
|
||||
|
||||
[ns_window setTitle:[NSString stringWithUTF8String:desc->title]];
|
||||
[ns_window center];
|
||||
|
||||
ASmplView *view = [[ASmplView alloc] initWithFrame:content_rect];
|
||||
[ns_window setContentView:view];
|
||||
[ns_window makeFirstResponder:view];
|
||||
|
||||
// Enable mouse moved events
|
||||
[ns_window setAcceptsMouseMovedEvents:YES];
|
||||
|
||||
ASmplWindowDelegate *delegate = [[ASmplWindowDelegate alloc] init];
|
||||
[ns_window setDelegate:delegate];
|
||||
|
||||
PlatformWindow *window = (PlatformWindow *)calloc(1, sizeof(PlatformWindow));
|
||||
window->ns_window = ns_window;
|
||||
window->view = view;
|
||||
window->delegate = delegate;
|
||||
window->should_close = false;
|
||||
window->backing_scale = (F32)[ns_window backingScaleFactor];
|
||||
window->width = (S32)(desc->width * window->backing_scale);
|
||||
window->height = (S32)(desc->height * window->backing_scale);
|
||||
|
||||
// Wire up per-window pointers
|
||||
view->_platformWindow = window;
|
||||
delegate->_platformWindow = window;
|
||||
|
||||
// Track main window for menu commands
|
||||
if (desc->style == PLATFORM_WINDOW_STYLE_NORMAL) {
|
||||
g_main_window = window;
|
||||
}
|
||||
|
||||
// If popup, add as child of parent (unless independent)
|
||||
if (!desc->independent && (desc->style == PLATFORM_WINDOW_STYLE_POPUP || desc->style == PLATFORM_WINDOW_STYLE_POPUP_RESIZABLE) && desc->parent) {
|
||||
[desc->parent->ns_window addChildWindow:ns_window ordered:NSWindowAbove];
|
||||
}
|
||||
|
||||
[ns_window makeKeyAndOrderFront:nil];
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
void platform_destroy_window(PlatformWindow *window) {
|
||||
if (!window) return;
|
||||
|
||||
// Remove from parent if it's a child window
|
||||
NSWindow *parent = [window->ns_window parentWindow];
|
||||
if (parent) {
|
||||
[parent removeChildWindow:window->ns_window];
|
||||
}
|
||||
|
||||
[window->ns_window close];
|
||||
if (g_main_window == window)
|
||||
g_main_window = NULL;
|
||||
free(window);
|
||||
}
|
||||
|
||||
B32 platform_poll_events(PlatformWindow *window) {
|
||||
@autoreleasepool {
|
||||
// When the app is not active (e.g. during Cmd+Tab away), block until
|
||||
// an event arrives instead of spinning. This keeps CPU near zero while
|
||||
// backgrounded and lets macOS handle the app-switch animation smoothly.
|
||||
BOOL is_active = [NSApp isActive];
|
||||
NSDate *deadline = is_active ? nil : [NSDate distantFuture];
|
||||
|
||||
NSEvent *event;
|
||||
while ((event = [NSApp nextEventMatchingMask:NSEventMaskAny
|
||||
untilDate:deadline
|
||||
inMode:NSDefaultRunLoopMode
|
||||
dequeue:YES])) {
|
||||
[NSApp sendEvent:event];
|
||||
// After processing one event while backgrounded, switch to
|
||||
// non-blocking drain so we handle any remaining queued events
|
||||
// (including the activation event that will flip isActive).
|
||||
deadline = nil;
|
||||
}
|
||||
}
|
||||
return !window->should_close;
|
||||
}
|
||||
|
||||
void platform_get_size(PlatformWindow *window, S32 *w, S32 *h) {
|
||||
if (w) *w = window->width;
|
||||
if (h) *h = window->height;
|
||||
}
|
||||
|
||||
void *platform_get_native_handle(PlatformWindow *window) {
|
||||
return (__bridge void *)window->view;
|
||||
}
|
||||
|
||||
void platform_set_frame_callback(PlatformWindow *window, PlatformFrameCallback cb, void *user_data) {
|
||||
window->frame_callback = cb;
|
||||
window->frame_callback_user_data = user_data;
|
||||
}
|
||||
|
||||
void platform_set_menu(PlatformWindow *window, PlatformMenu *menus, S32 menu_count) {
|
||||
(void)window;
|
||||
|
||||
if (!g_menu_target)
|
||||
g_menu_target = [[ASmplMenuTarget alloc] init];
|
||||
|
||||
NSMenu *menu_bar = [[NSMenu alloc] init];
|
||||
|
||||
// App menu (required on macOS)
|
||||
NSMenuItem *app_menu_item = [[NSMenuItem alloc] init];
|
||||
NSMenu *app_menu = [[NSMenu alloc] init];
|
||||
[app_menu addItemWithTitle:@"Quit autosample"
|
||||
action:@selector(terminate:)
|
||||
keyEquivalent:@"q"];
|
||||
[app_menu_item setSubmenu:app_menu];
|
||||
[menu_bar addItem:app_menu_item];
|
||||
|
||||
for (S32 i = 0; i < menu_count; i++) {
|
||||
NSMenuItem *top_item = [[NSMenuItem alloc] init];
|
||||
NSMenu *submenu = [[NSMenu alloc] initWithTitle:
|
||||
[NSString stringWithUTF8String:menus[i].label]];
|
||||
|
||||
for (S32 j = 0; j < menus[i].item_count; j++) {
|
||||
PlatformMenuItem *item = &menus[i].items[j];
|
||||
if (!item->label) {
|
||||
[submenu addItem:[NSMenuItem separatorItem]];
|
||||
} else {
|
||||
NSMenuItem *ns_item = [[NSMenuItem alloc]
|
||||
initWithTitle:[NSString stringWithUTF8String:item->label]
|
||||
action:@selector(menuAction:)
|
||||
keyEquivalent:@""];
|
||||
[ns_item setTag:item->id];
|
||||
[ns_item setTarget:g_menu_target];
|
||||
[submenu addItem:ns_item];
|
||||
}
|
||||
}
|
||||
|
||||
[top_item setSubmenu:submenu];
|
||||
[menu_bar addItem:top_item];
|
||||
}
|
||||
|
||||
[NSApp setMainMenu:menu_bar];
|
||||
}
|
||||
|
||||
S32 platform_poll_menu_command(PlatformWindow *window) {
|
||||
S32 cmd = window->pending_menu_cmd;
|
||||
window->pending_menu_cmd = 0;
|
||||
return cmd;
|
||||
}
|
||||
|
||||
PlatformInput platform_get_input(PlatformWindow *window) {
|
||||
PlatformInput result = window->input;
|
||||
|
||||
// Poll mouse position (Cocoa uses bottom-left origin, flip Y)
|
||||
NSPoint mouse_in_window = [window->ns_window mouseLocationOutsideOfEventStream];
|
||||
NSRect view_bounds = [window->view bounds];
|
||||
F32 scale = window->backing_scale;
|
||||
result.mouse_pos = v2f32(
|
||||
(F32)mouse_in_window.x * scale,
|
||||
(F32)(view_bounds.size.height - mouse_in_window.y) * scale);
|
||||
|
||||
// Mouse button state
|
||||
result.was_mouse_down = window->prev_mouse_down;
|
||||
result.mouse_down = window->mouse_down_state;
|
||||
window->prev_mouse_down = result.mouse_down;
|
||||
|
||||
// Poll current modifier state (so shift/ctrl are accurate even without key events)
|
||||
NSEventModifierFlags mods = [NSEvent modifierFlags];
|
||||
result.ctrl_held = (mods & NSEventModifierFlagCommand) != 0;
|
||||
result.shift_held = (mods & NSEventModifierFlagShift) != 0;
|
||||
|
||||
// Clear accumulated events for next frame
|
||||
memset(&window->input, 0, sizeof(window->input));
|
||||
return result;
|
||||
}
|
||||
|
||||
B32 platform_window_should_close(PlatformWindow *window) {
|
||||
return window ? window->should_close : 0;
|
||||
}
|
||||
|
||||
void platform_focus_window(PlatformWindow *window) {
|
||||
if (!window || !window->ns_window) return;
|
||||
[window->ns_window makeKeyAndOrderFront:nil];
|
||||
}
|
||||
|
||||
F32 platform_get_dpi_scale(PlatformWindow *window) {
|
||||
(void)window;
|
||||
return 1.0f; // macOS handles Retina via backing scale factor, not DPI
|
||||
}
|
||||
|
||||
void platform_set_cursor(PlatformCursor cursor) {
|
||||
switch (cursor) {
|
||||
case PLATFORM_CURSOR_SIZE_WE: [[NSCursor resizeLeftRightCursor] set]; break;
|
||||
case PLATFORM_CURSOR_SIZE_NS: [[NSCursor resizeUpDownCursor] set]; break;
|
||||
default: [[NSCursor arrowCursor] set]; break;
|
||||
}
|
||||
}
|
||||
|
||||
void platform_clipboard_set(const char *text) {
|
||||
if (!text) return;
|
||||
NSPasteboard *pb = [NSPasteboard generalPasteboard];
|
||||
[pb clearContents];
|
||||
[pb setString:[NSString stringWithUTF8String:text] forType:NSPasteboardTypeString];
|
||||
}
|
||||
|
||||
const char *platform_clipboard_get() {
|
||||
static char buf[4096];
|
||||
buf[0] = '\0';
|
||||
|
||||
NSPasteboard *pb = [NSPasteboard generalPasteboard];
|
||||
NSString *str = [pb stringForType:NSPasteboardTypeString];
|
||||
if (str) {
|
||||
const char *utf8 = [str UTF8String];
|
||||
if (utf8) {
|
||||
size_t len = strlen(utf8);
|
||||
if (len >= sizeof(buf)) len = sizeof(buf) - 1;
|
||||
memcpy(buf, utf8, len);
|
||||
buf[len] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
return buf[0] ? buf : NULL;
|
||||
}
|
||||
|
||||
S32 platform_message_box(PlatformWindow *parent, const char *title,
|
||||
const char *message, PlatformMsgBoxType type) {
|
||||
@autoreleasepool {
|
||||
NSAlert *alert = [[NSAlert alloc] init];
|
||||
[alert setMessageText:[NSString stringWithUTF8String:title]];
|
||||
[alert setInformativeText:[NSString stringWithUTF8String:message]];
|
||||
|
||||
switch (type) {
|
||||
case PLATFORM_MSGBOX_OK:
|
||||
[alert addButtonWithTitle:@"OK"];
|
||||
break;
|
||||
case PLATFORM_MSGBOX_OK_CANCEL:
|
||||
[alert addButtonWithTitle:@"OK"];
|
||||
[alert addButtonWithTitle:@"Cancel"];
|
||||
break;
|
||||
case PLATFORM_MSGBOX_YES_NO:
|
||||
[alert addButtonWithTitle:@"Yes"];
|
||||
[alert addButtonWithTitle:@"No"];
|
||||
break;
|
||||
}
|
||||
|
||||
NSModalResponse response;
|
||||
if (parent && parent->ns_window) {
|
||||
response = [alert runModal];
|
||||
} else {
|
||||
response = [alert runModal];
|
||||
}
|
||||
|
||||
// NSAlertFirstButtonReturn = 1000, Second = 1001
|
||||
if (response == NSAlertFirstButtonReturn) return 0;
|
||||
if (response == NSAlertSecondButtonReturn) return 1;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
372
src/platform/platform_win32.c
Normal file
372
src/platform/platform_win32.c
Normal file
@@ -0,0 +1,372 @@
|
||||
#include "platform/platform.h"
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#include <malloc.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct PlatformWindow {
|
||||
HWND hwnd;
|
||||
B32 should_close;
|
||||
S32 width;
|
||||
S32 height;
|
||||
S32 pending_menu_cmd;
|
||||
PlatformFrameCallback frame_callback;
|
||||
void *frame_callback_user_data;
|
||||
PlatformInput input;
|
||||
B32 prev_mouse_down;
|
||||
} PlatformWindow;
|
||||
|
||||
// Main window receives menu commands
|
||||
static PlatformWindow *g_main_window = NULL;
|
||||
static HCURSOR g_current_cursor = NULL;
|
||||
static B32 g_wndclass_registered = false;
|
||||
|
||||
static LRESULT CALLBACK win32_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
|
||||
PlatformWindow *pw = (PlatformWindow *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
||||
|
||||
switch (msg) {
|
||||
case WM_SIZE:
|
||||
if (pw && wparam != SIZE_MINIMIZED) {
|
||||
pw->width = (S32)LOWORD(lparam);
|
||||
pw->height = (S32)HIWORD(lparam);
|
||||
// Render a frame during the modal resize loop so the UI
|
||||
// stays responsive instead of showing a stretched image.
|
||||
if (pw->frame_callback) {
|
||||
pw->frame_callback(pw->frame_callback_user_data);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
case WM_CHAR:
|
||||
if (pw && wparam >= 32 && wparam < 0xFFFF) {
|
||||
PlatformInput *ev = &pw->input;
|
||||
if (ev->char_count < PLATFORM_MAX_CHARS_PER_FRAME)
|
||||
ev->chars[ev->char_count++] = (U16)wparam;
|
||||
}
|
||||
return 0;
|
||||
case WM_KEYDOWN:
|
||||
case WM_SYSKEYDOWN:
|
||||
if (pw) {
|
||||
PlatformInput *ev = &pw->input;
|
||||
if (ev->key_count < PLATFORM_MAX_KEYS_PER_FRAME)
|
||||
ev->keys[ev->key_count++] = (U8)wparam;
|
||||
ev->ctrl_held = (GetKeyState(VK_CONTROL) & 0x8000) != 0;
|
||||
ev->shift_held = (GetKeyState(VK_SHIFT) & 0x8000) != 0;
|
||||
}
|
||||
break; // fall through to DefWindowProc for system keys
|
||||
case WM_MOUSEWHEEL:
|
||||
if (pw) {
|
||||
S16 wheel_delta = (S16)HIWORD(wparam);
|
||||
pw->input.scroll_delta.y += (F32)wheel_delta / (F32)WHEEL_DELTA * 6.0f;
|
||||
}
|
||||
return 0;
|
||||
case WM_COMMAND:
|
||||
// Route menu commands to main window
|
||||
if (g_main_window && HIWORD(wparam) == 0)
|
||||
g_main_window->pending_menu_cmd = (S32)LOWORD(wparam);
|
||||
return 0;
|
||||
case WM_SETCURSOR:
|
||||
// When the cursor is in our client area, use the app-set cursor.
|
||||
if (LOWORD(lparam) == HTCLIENT) {
|
||||
SetCursor(g_current_cursor ? g_current_cursor : LoadCursor(NULL, IDC_ARROW));
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
case WM_DPICHANGED:
|
||||
if (pw) {
|
||||
RECT *suggested = (RECT *)lparam;
|
||||
SetWindowPos(hwnd, NULL, suggested->left, suggested->top,
|
||||
suggested->right - suggested->left, suggested->bottom - suggested->top,
|
||||
SWP_NOZORDER | SWP_NOACTIVATE);
|
||||
}
|
||||
return 0;
|
||||
case WM_CLOSE:
|
||||
if (pw)
|
||||
pw->should_close = true;
|
||||
return 0;
|
||||
case WM_DESTROY:
|
||||
if (pw == g_main_window)
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
case WM_SYSCOMMAND:
|
||||
if ((wparam & 0xfff0) == SC_KEYMENU)
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
return DefWindowProcW(hwnd, msg, wparam, lparam);
|
||||
}
|
||||
|
||||
PlatformWindow *platform_create_window(PlatformWindowDesc *desc) {
|
||||
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
|
||||
|
||||
if (!g_wndclass_registered) {
|
||||
WNDCLASSEXW wc = {0};
|
||||
wc.cbSize = sizeof(wc);
|
||||
wc.style = CS_CLASSDC;
|
||||
wc.lpfnWndProc = win32_wndproc;
|
||||
wc.hInstance = GetModuleHandleW(NULL);
|
||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wc.lpszClassName = L"autosample_wc";
|
||||
RegisterClassExW(&wc);
|
||||
g_wndclass_registered = true;
|
||||
}
|
||||
|
||||
UINT dpi = GetDpiForSystem();
|
||||
int screen_w = GetSystemMetrics(SM_CXSCREEN);
|
||||
int screen_h = GetSystemMetrics(SM_CYSCREEN);
|
||||
int x = (screen_w - desc->width) / 2;
|
||||
int y = (screen_h - desc->height) / 2;
|
||||
|
||||
DWORD style;
|
||||
HWND parent_hwnd = NULL;
|
||||
if (desc->style == PLATFORM_WINDOW_STYLE_POPUP) {
|
||||
style = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU;
|
||||
if (desc->parent && !desc->independent) parent_hwnd = desc->parent->hwnd;
|
||||
} else if (desc->style == PLATFORM_WINDOW_STYLE_POPUP_RESIZABLE) {
|
||||
style = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MAXIMIZEBOX;
|
||||
if (desc->parent && !desc->independent) parent_hwnd = desc->parent->hwnd;
|
||||
} else {
|
||||
style = WS_OVERLAPPEDWINDOW;
|
||||
}
|
||||
|
||||
RECT rect = { 0, 0, (LONG)desc->width, (LONG)desc->height };
|
||||
AdjustWindowRectExForDpi(&rect, style, FALSE, 0, dpi);
|
||||
|
||||
int wchar_count = MultiByteToWideChar(CP_UTF8, 0, desc->title, -1, NULL, 0);
|
||||
wchar_t *wtitle = (wchar_t *)_malloca(wchar_count * sizeof(wchar_t));
|
||||
MultiByteToWideChar(CP_UTF8, 0, desc->title, -1, wtitle, wchar_count);
|
||||
|
||||
HWND hwnd = CreateWindowExW(
|
||||
0, L"autosample_wc", wtitle,
|
||||
style,
|
||||
x, y,
|
||||
rect.right - rect.left,
|
||||
rect.bottom - rect.top,
|
||||
parent_hwnd, NULL, GetModuleHandleW(NULL), NULL
|
||||
);
|
||||
|
||||
_freea(wtitle);
|
||||
|
||||
if (!hwnd)
|
||||
return NULL;
|
||||
|
||||
PlatformWindow *window = (PlatformWindow *)calloc(1, sizeof(PlatformWindow));
|
||||
window->hwnd = hwnd;
|
||||
window->should_close = false;
|
||||
window->width = desc->width;
|
||||
window->height = desc->height;
|
||||
|
||||
// Store PlatformWindow* on the HWND so WndProc can find it
|
||||
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)window);
|
||||
|
||||
// Track main window for menu commands
|
||||
if (desc->style == PLATFORM_WINDOW_STYLE_NORMAL) {
|
||||
g_main_window = window;
|
||||
}
|
||||
|
||||
ShowWindow(hwnd, SW_SHOWDEFAULT);
|
||||
UpdateWindow(hwnd);
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
void platform_destroy_window(PlatformWindow *window) {
|
||||
if (!window) return;
|
||||
|
||||
if (window->hwnd) {
|
||||
DestroyWindow(window->hwnd);
|
||||
}
|
||||
|
||||
if (g_main_window == window)
|
||||
g_main_window = NULL;
|
||||
|
||||
free(window);
|
||||
}
|
||||
|
||||
B32 platform_poll_events(PlatformWindow *window) {
|
||||
MSG msg;
|
||||
while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessageW(&msg);
|
||||
if (msg.message == WM_QUIT) {
|
||||
window->should_close = true;
|
||||
}
|
||||
}
|
||||
return !window->should_close;
|
||||
}
|
||||
|
||||
void platform_get_size(PlatformWindow *window, S32 *w, S32 *h) {
|
||||
if (w) *w = window->width;
|
||||
if (h) *h = window->height;
|
||||
}
|
||||
|
||||
void *platform_get_native_handle(PlatformWindow *window) {
|
||||
return (void *)window->hwnd;
|
||||
}
|
||||
|
||||
void platform_set_frame_callback(PlatformWindow *window, PlatformFrameCallback cb, void *user_data) {
|
||||
window->frame_callback = cb;
|
||||
window->frame_callback_user_data = user_data;
|
||||
}
|
||||
|
||||
void platform_set_menu(PlatformWindow *window, PlatformMenu *menus, S32 menu_count) {
|
||||
HMENU menu_bar = CreateMenu();
|
||||
|
||||
for (S32 i = 0; i < menu_count; i++) {
|
||||
HMENU submenu = CreatePopupMenu();
|
||||
|
||||
for (S32 j = 0; j < menus[i].item_count; j++) {
|
||||
PlatformMenuItem *item = &menus[i].items[j];
|
||||
if (!item->label) {
|
||||
AppendMenuW(submenu, MF_SEPARATOR, 0, NULL);
|
||||
} else {
|
||||
int wchar_count = MultiByteToWideChar(CP_UTF8, 0, item->label, -1, NULL, 0);
|
||||
wchar_t *wlabel = (wchar_t *)_malloca(wchar_count * sizeof(wchar_t));
|
||||
MultiByteToWideChar(CP_UTF8, 0, item->label, -1, wlabel, wchar_count);
|
||||
AppendMenuW(submenu, MF_STRING, (UINT_PTR)item->id, wlabel);
|
||||
_freea(wlabel);
|
||||
}
|
||||
}
|
||||
|
||||
int wchar_count = MultiByteToWideChar(CP_UTF8, 0, menus[i].label, -1, NULL, 0);
|
||||
wchar_t *wlabel = (wchar_t *)_malloca(wchar_count * sizeof(wchar_t));
|
||||
MultiByteToWideChar(CP_UTF8, 0, menus[i].label, -1, wlabel, wchar_count);
|
||||
AppendMenuW(menu_bar, MF_POPUP, (UINT_PTR)submenu, wlabel);
|
||||
_freea(wlabel);
|
||||
}
|
||||
|
||||
SetMenu(window->hwnd, menu_bar);
|
||||
}
|
||||
|
||||
S32 platform_poll_menu_command(PlatformWindow *window) {
|
||||
S32 cmd = window->pending_menu_cmd;
|
||||
window->pending_menu_cmd = 0;
|
||||
return cmd;
|
||||
}
|
||||
|
||||
PlatformInput platform_get_input(PlatformWindow *window) {
|
||||
PlatformInput result = window->input;
|
||||
|
||||
// Poll mouse position
|
||||
POINT cursor;
|
||||
GetCursorPos(&cursor);
|
||||
ScreenToClient(window->hwnd, &cursor);
|
||||
result.mouse_pos = v2f32((F32)cursor.x, (F32)cursor.y);
|
||||
|
||||
// Poll mouse button
|
||||
result.was_mouse_down = window->prev_mouse_down;
|
||||
result.mouse_down = (GetAsyncKeyState(VK_LBUTTON) & 0x8000) != 0;
|
||||
window->prev_mouse_down = result.mouse_down;
|
||||
|
||||
// Clear accumulated events for next frame
|
||||
memset(&window->input, 0, sizeof(window->input));
|
||||
return result;
|
||||
}
|
||||
|
||||
B32 platform_window_should_close(PlatformWindow *window) {
|
||||
return window ? window->should_close : 0;
|
||||
}
|
||||
|
||||
void platform_focus_window(PlatformWindow *window) {
|
||||
if (!window || !window->hwnd) return;
|
||||
SetForegroundWindow(window->hwnd);
|
||||
SetFocus(window->hwnd);
|
||||
}
|
||||
|
||||
F32 platform_get_dpi_scale(PlatformWindow *window) {
|
||||
if (!window || !window->hwnd) return 1.0f;
|
||||
return (F32)GetDpiForWindow(window->hwnd) / 96.0f;
|
||||
}
|
||||
|
||||
void platform_set_cursor(PlatformCursor cursor) {
|
||||
switch (cursor) {
|
||||
case PLATFORM_CURSOR_SIZE_WE: g_current_cursor = LoadCursor(NULL, IDC_SIZEWE); break;
|
||||
case PLATFORM_CURSOR_SIZE_NS: g_current_cursor = LoadCursor(NULL, IDC_SIZENS); break;
|
||||
default: g_current_cursor = LoadCursor(NULL, IDC_ARROW); break;
|
||||
}
|
||||
}
|
||||
|
||||
void platform_clipboard_set(const char *text) {
|
||||
if (!text) return;
|
||||
int len = (S32)strlen(text);
|
||||
if (len == 0) return;
|
||||
|
||||
// Convert UTF-8 to wide string for Windows clipboard
|
||||
int wlen = MultiByteToWideChar(CP_UTF8, 0, text, len, NULL, 0);
|
||||
if (wlen == 0) return;
|
||||
|
||||
HGLOBAL hmem = GlobalAlloc(GMEM_MOVEABLE, (wlen + 1) * sizeof(wchar_t));
|
||||
if (!hmem) return;
|
||||
|
||||
wchar_t *wbuf = (wchar_t *)GlobalLock(hmem);
|
||||
MultiByteToWideChar(CP_UTF8, 0, text, len, wbuf, wlen);
|
||||
wbuf[wlen] = L'\0';
|
||||
GlobalUnlock(hmem);
|
||||
|
||||
HWND hwnd = g_main_window ? g_main_window->hwnd : NULL;
|
||||
if (OpenClipboard(hwnd)) {
|
||||
EmptyClipboard();
|
||||
SetClipboardData(CF_UNICODETEXT, hmem);
|
||||
CloseClipboard();
|
||||
} else {
|
||||
GlobalFree(hmem);
|
||||
}
|
||||
}
|
||||
|
||||
const char *platform_clipboard_get() {
|
||||
static char buf[4096];
|
||||
buf[0] = '\0';
|
||||
|
||||
HWND hwnd = g_main_window ? g_main_window->hwnd : NULL;
|
||||
if (!OpenClipboard(hwnd)) return NULL;
|
||||
|
||||
HGLOBAL hmem = GetClipboardData(CF_UNICODETEXT);
|
||||
if (hmem) {
|
||||
wchar_t *wbuf = (wchar_t *)GlobalLock(hmem);
|
||||
if (wbuf) {
|
||||
int len = WideCharToMultiByte(CP_UTF8, 0, wbuf, -1, buf, sizeof(buf) - 1, NULL, NULL);
|
||||
buf[len > 0 ? len - 1 : 0] = '\0'; // WideCharToMultiByte includes null in count
|
||||
GlobalUnlock(hmem);
|
||||
}
|
||||
}
|
||||
|
||||
CloseClipboard();
|
||||
return buf[0] ? buf : NULL;
|
||||
}
|
||||
|
||||
S32 platform_message_box(PlatformWindow *parent, const char *title,
|
||||
const char *message, PlatformMsgBoxType type) {
|
||||
UINT mb_type;
|
||||
switch (type) {
|
||||
case PLATFORM_MSGBOX_OK: mb_type = MB_OK; break;
|
||||
case PLATFORM_MSGBOX_OK_CANCEL: mb_type = MB_OKCANCEL; break;
|
||||
case PLATFORM_MSGBOX_YES_NO: mb_type = MB_YESNO; break;
|
||||
default: mb_type = MB_OK; break;
|
||||
}
|
||||
|
||||
// Convert UTF-8 to wide strings
|
||||
int title_wlen = MultiByteToWideChar(CP_UTF8, 0, title, -1, NULL, 0);
|
||||
wchar_t *wtitle = (wchar_t *)_malloca(title_wlen * sizeof(wchar_t));
|
||||
MultiByteToWideChar(CP_UTF8, 0, title, -1, wtitle, title_wlen);
|
||||
|
||||
int msg_wlen = MultiByteToWideChar(CP_UTF8, 0, message, -1, NULL, 0);
|
||||
wchar_t *wmsg = (wchar_t *)_malloca(msg_wlen * sizeof(wchar_t));
|
||||
MultiByteToWideChar(CP_UTF8, 0, message, -1, wmsg, msg_wlen);
|
||||
|
||||
HWND hwnd = parent ? parent->hwnd : NULL;
|
||||
int result = MessageBoxW(hwnd, wmsg, wtitle, mb_type);
|
||||
|
||||
_freea(wmsg);
|
||||
_freea(wtitle);
|
||||
|
||||
switch (result) {
|
||||
case IDOK: return 0;
|
||||
case IDYES: return 0;
|
||||
case IDCANCEL: return 1;
|
||||
case IDNO: return 1;
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
@@ -1,169 +0,0 @@
|
||||
#include "platform/platform.h"
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#include "imgui_impl_win32.h"
|
||||
|
||||
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
struct PlatformWindow {
|
||||
HWND hwnd;
|
||||
bool should_close;
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
int32_t pending_menu_cmd;
|
||||
};
|
||||
|
||||
static PlatformWindow *g_current_window = nullptr;
|
||||
|
||||
static LRESULT CALLBACK win32_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
|
||||
if (ImGui_ImplWin32_WndProcHandler(hwnd, msg, wparam, lparam))
|
||||
return true;
|
||||
|
||||
switch (msg) {
|
||||
case WM_SIZE:
|
||||
if (g_current_window && wparam != SIZE_MINIMIZED) {
|
||||
g_current_window->width = (int32_t)LOWORD(lparam);
|
||||
g_current_window->height = (int32_t)HIWORD(lparam);
|
||||
}
|
||||
return 0;
|
||||
case WM_COMMAND:
|
||||
if (g_current_window && HIWORD(wparam) == 0)
|
||||
g_current_window->pending_menu_cmd = (int32_t)LOWORD(wparam);
|
||||
return 0;
|
||||
case WM_CLOSE:
|
||||
if (g_current_window)
|
||||
g_current_window->should_close = true;
|
||||
return 0;
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
case WM_SYSCOMMAND:
|
||||
if ((wparam & 0xfff0) == SC_KEYMENU)
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
return DefWindowProcW(hwnd, msg, wparam, lparam);
|
||||
}
|
||||
|
||||
PlatformWindow *platform_create_window(PlatformWindowDesc *desc) {
|
||||
WNDCLASSEXW wc = {};
|
||||
wc.cbSize = sizeof(wc);
|
||||
wc.style = CS_CLASSDC;
|
||||
wc.lpfnWndProc = win32_wndproc;
|
||||
wc.hInstance = GetModuleHandleW(nullptr);
|
||||
wc.lpszClassName = L"autosample_wc";
|
||||
RegisterClassExW(&wc);
|
||||
|
||||
int screen_w = GetSystemMetrics(SM_CXSCREEN);
|
||||
int screen_h = GetSystemMetrics(SM_CYSCREEN);
|
||||
int x = (screen_w - desc->width) / 2;
|
||||
int y = (screen_h - desc->height) / 2;
|
||||
|
||||
RECT rect = { 0, 0, (LONG)desc->width, (LONG)desc->height };
|
||||
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);
|
||||
|
||||
int wchar_count = MultiByteToWideChar(CP_UTF8, 0, desc->title, -1, nullptr, 0);
|
||||
wchar_t *wtitle = (wchar_t *)_malloca(wchar_count * sizeof(wchar_t));
|
||||
MultiByteToWideChar(CP_UTF8, 0, desc->title, -1, wtitle, wchar_count);
|
||||
|
||||
HWND hwnd = CreateWindowExW(
|
||||
0, wc.lpszClassName, wtitle,
|
||||
WS_OVERLAPPEDWINDOW,
|
||||
x, y,
|
||||
rect.right - rect.left,
|
||||
rect.bottom - rect.top,
|
||||
nullptr, nullptr, wc.hInstance, nullptr
|
||||
);
|
||||
|
||||
_freea(wtitle);
|
||||
|
||||
if (!hwnd)
|
||||
return nullptr;
|
||||
|
||||
ShowWindow(hwnd, SW_SHOWDEFAULT);
|
||||
UpdateWindow(hwnd);
|
||||
|
||||
PlatformWindow *window = new PlatformWindow();
|
||||
window->hwnd = hwnd;
|
||||
window->should_close = false;
|
||||
window->width = desc->width;
|
||||
window->height = desc->height;
|
||||
|
||||
g_current_window = window;
|
||||
return window;
|
||||
}
|
||||
|
||||
void platform_destroy_window(PlatformWindow *window) {
|
||||
if (!window) return;
|
||||
|
||||
if (window->hwnd) {
|
||||
DestroyWindow(window->hwnd);
|
||||
UnregisterClassW(L"autosample_wc", GetModuleHandleW(nullptr));
|
||||
}
|
||||
|
||||
if (g_current_window == window)
|
||||
g_current_window = nullptr;
|
||||
|
||||
delete window;
|
||||
}
|
||||
|
||||
bool platform_poll_events(PlatformWindow *window) {
|
||||
MSG msg;
|
||||
while (PeekMessageW(&msg, nullptr, 0, 0, PM_REMOVE)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessageW(&msg);
|
||||
if (msg.message == WM_QUIT) {
|
||||
window->should_close = true;
|
||||
}
|
||||
}
|
||||
return !window->should_close;
|
||||
}
|
||||
|
||||
void platform_get_size(PlatformWindow *window, int32_t *w, int32_t *h) {
|
||||
if (w) *w = window->width;
|
||||
if (h) *h = window->height;
|
||||
}
|
||||
|
||||
void *platform_get_native_handle(PlatformWindow *window) {
|
||||
return (void *)window->hwnd;
|
||||
}
|
||||
|
||||
void platform_set_menu(PlatformWindow *window, PlatformMenu *menus, int32_t menu_count) {
|
||||
HMENU menu_bar = CreateMenu();
|
||||
|
||||
for (int32_t i = 0; i < menu_count; i++) {
|
||||
HMENU submenu = CreatePopupMenu();
|
||||
|
||||
for (int32_t j = 0; j < menus[i].item_count; j++) {
|
||||
PlatformMenuItem *item = &menus[i].items[j];
|
||||
if (!item->label) {
|
||||
AppendMenuW(submenu, MF_SEPARATOR, 0, nullptr);
|
||||
} else {
|
||||
int wchar_count = MultiByteToWideChar(CP_UTF8, 0, item->label, -1, nullptr, 0);
|
||||
wchar_t *wlabel = (wchar_t *)_malloca(wchar_count * sizeof(wchar_t));
|
||||
MultiByteToWideChar(CP_UTF8, 0, item->label, -1, wlabel, wchar_count);
|
||||
AppendMenuW(submenu, MF_STRING, (UINT_PTR)item->id, wlabel);
|
||||
_freea(wlabel);
|
||||
}
|
||||
}
|
||||
|
||||
int wchar_count = MultiByteToWideChar(CP_UTF8, 0, menus[i].label, -1, nullptr, 0);
|
||||
wchar_t *wlabel = (wchar_t *)_malloca(wchar_count * sizeof(wchar_t));
|
||||
MultiByteToWideChar(CP_UTF8, 0, menus[i].label, -1, wlabel, wchar_count);
|
||||
AppendMenuW(menu_bar, MF_POPUP, (UINT_PTR)submenu, wlabel);
|
||||
_freea(wlabel);
|
||||
}
|
||||
|
||||
SetMenu(window->hwnd, menu_bar);
|
||||
}
|
||||
|
||||
int32_t platform_poll_menu_command(PlatformWindow *window) {
|
||||
int32_t cmd = window->pending_menu_cmd;
|
||||
window->pending_menu_cmd = 0;
|
||||
return cmd;
|
||||
}
|
||||
@@ -1,19 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "base/base_core.h"
|
||||
#include "base/base_math.h"
|
||||
#include "clay.h"
|
||||
|
||||
struct Renderer;
|
||||
typedef struct Renderer Renderer;
|
||||
|
||||
struct RendererDesc {
|
||||
void *window_handle = nullptr;
|
||||
int32_t width = 1280;
|
||||
int32_t height = 720;
|
||||
int32_t frame_count = 2;
|
||||
};
|
||||
typedef struct RendererDesc {
|
||||
void *window_handle;
|
||||
S32 width;
|
||||
S32 height;
|
||||
S32 frame_count;
|
||||
} RendererDesc;
|
||||
|
||||
Renderer *renderer_create(RendererDesc *desc);
|
||||
|
||||
// creates a lightweight renderer that shares the GPU device, pipeline, shaders, font atlas, and icon textures from a
|
||||
// parent renderer, but creates its own drawable surface (CAMetalLayer / swap chain), vertex/index buffers, and frame synchronization
|
||||
// primitives. On each renderer_begin_frame(), shared renderers sync font atlas updates from the parent so Cmd+/- zoom works across all
|
||||
// windows.
|
||||
Renderer *renderer_create_shared(Renderer *parent, RendererDesc *desc);
|
||||
|
||||
void renderer_destroy(Renderer *renderer);
|
||||
bool renderer_begin_frame(Renderer *renderer);
|
||||
void renderer_end_frame(Renderer *renderer);
|
||||
void renderer_resize(Renderer *renderer, int32_t width, int32_t height);
|
||||
B32 renderer_begin_frame(Renderer *renderer);
|
||||
void renderer_end_frame(Renderer *renderer, Clay_RenderCommandArray *render_commands);
|
||||
void renderer_resize(Renderer *renderer, S32 width, S32 height);
|
||||
void renderer_set_font_scale(Renderer *renderer, F32 scale);
|
||||
void renderer_sync_from_parent(Renderer *renderer); // sync shared font atlas from parent
|
||||
void renderer_set_clear_color(Renderer *renderer, F32 r, F32 g, F32 b);
|
||||
|
||||
// Text measurement callback compatible with UI_MeasureTextFn
|
||||
// Measures text of given length (NOT necessarily null-terminated) at font_size pixels.
|
||||
// user_data should be the Renderer pointer.
|
||||
Vec2F32 renderer_measure_text(const char *text, S32 length, F32 font_size, void *user_data);
|
||||
|
||||
// Upload an RGBA8 icon atlas texture for icon rendering (4 bytes per pixel)
|
||||
void renderer_create_icon_atlas(Renderer *renderer, const U8 *data, S32 w, S32 h);
|
||||
|
||||
@@ -1,418 +0,0 @@
|
||||
#include "renderer/renderer.h"
|
||||
|
||||
#include <d3d12.h>
|
||||
#include <dxgi1_5.h>
|
||||
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_win32.h"
|
||||
#include "imgui_impl_dx12.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define DX12_ENABLE_DEBUG_LAYER
|
||||
#endif
|
||||
|
||||
#ifdef DX12_ENABLE_DEBUG_LAYER
|
||||
#include <dxgidebug.h>
|
||||
#pragma comment(lib, "dxguid.lib")
|
||||
#endif
|
||||
|
||||
#define NUM_BACK_BUFFERS 2
|
||||
#define SRV_HEAP_SIZE 64
|
||||
|
||||
struct FrameContext {
|
||||
ID3D12CommandAllocator *command_allocator;
|
||||
UINT64 fence_value;
|
||||
};
|
||||
|
||||
struct SrvHeapAllocator {
|
||||
ID3D12DescriptorHeap *heap;
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE heap_type;
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE start_cpu;
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE start_gpu;
|
||||
UINT increment;
|
||||
int free_indices[SRV_HEAP_SIZE];
|
||||
int free_count;
|
||||
};
|
||||
|
||||
static void srv_alloc_init(SrvHeapAllocator *a, ID3D12Device *device, ID3D12DescriptorHeap *heap) {
|
||||
a->heap = heap;
|
||||
a->heap_type = heap->GetDesc().Type;
|
||||
a->start_cpu = heap->GetCPUDescriptorHandleForHeapStart();
|
||||
a->start_gpu = heap->GetGPUDescriptorHandleForHeapStart();
|
||||
a->increment = device->GetDescriptorHandleIncrementSize(a->heap_type);
|
||||
|
||||
D3D12_DESCRIPTOR_HEAP_DESC desc = heap->GetDesc();
|
||||
a->free_count = (int)desc.NumDescriptors;
|
||||
for (int i = 0; i < a->free_count; i++)
|
||||
a->free_indices[i] = a->free_count - 1 - i;
|
||||
}
|
||||
|
||||
static void srv_alloc_alloc(SrvHeapAllocator *a, D3D12_CPU_DESCRIPTOR_HANDLE *out_cpu, D3D12_GPU_DESCRIPTOR_HANDLE *out_gpu) {
|
||||
int idx = a->free_indices[--a->free_count];
|
||||
out_cpu->ptr = a->start_cpu.ptr + (idx * a->increment);
|
||||
out_gpu->ptr = a->start_gpu.ptr + (idx * a->increment);
|
||||
}
|
||||
|
||||
static void srv_alloc_free(SrvHeapAllocator *a, D3D12_CPU_DESCRIPTOR_HANDLE cpu, D3D12_GPU_DESCRIPTOR_HANDLE gpu) {
|
||||
(void)gpu;
|
||||
int idx = (int)((cpu.ptr - a->start_cpu.ptr) / a->increment);
|
||||
a->free_indices[a->free_count++] = idx;
|
||||
}
|
||||
|
||||
struct Renderer {
|
||||
HWND hwnd;
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
int32_t frame_count;
|
||||
UINT frame_index;
|
||||
|
||||
ID3D12Device *device;
|
||||
ID3D12CommandQueue *command_queue;
|
||||
IDXGISwapChain3 *swap_chain;
|
||||
HANDLE swap_chain_waitable;
|
||||
bool swap_chain_occluded;
|
||||
bool tearing_support;
|
||||
|
||||
ID3D12DescriptorHeap *rtv_heap;
|
||||
ID3D12DescriptorHeap *srv_heap;
|
||||
SrvHeapAllocator srv_alloc;
|
||||
|
||||
FrameContext frames[NUM_BACK_BUFFERS];
|
||||
ID3D12Resource *render_targets[NUM_BACK_BUFFERS];
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE rtv_descriptors[NUM_BACK_BUFFERS];
|
||||
|
||||
ID3D12GraphicsCommandList *command_list;
|
||||
ID3D12Fence *fence;
|
||||
HANDLE fence_event;
|
||||
UINT64 fence_last_signaled;
|
||||
};
|
||||
|
||||
static bool create_device(Renderer *r) {
|
||||
#ifdef DX12_ENABLE_DEBUG_LAYER
|
||||
ID3D12Debug *debug = nullptr;
|
||||
if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debug)))) {
|
||||
debug->EnableDebugLayer();
|
||||
debug->Release();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&r->device)) != S_OK)
|
||||
return false;
|
||||
|
||||
#ifdef DX12_ENABLE_DEBUG_LAYER
|
||||
{
|
||||
ID3D12InfoQueue *info_queue = nullptr;
|
||||
if (SUCCEEDED(r->device->QueryInterface(IID_PPV_ARGS(&info_queue)))) {
|
||||
info_queue->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY_ERROR, true);
|
||||
info_queue->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY_CORRUPTION, true);
|
||||
info_queue->Release();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool create_command_queue(Renderer *r) {
|
||||
D3D12_COMMAND_QUEUE_DESC desc = {};
|
||||
desc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
|
||||
desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
|
||||
desc.NodeMask = 1;
|
||||
return r->device->CreateCommandQueue(&desc, IID_PPV_ARGS(&r->command_queue)) == S_OK;
|
||||
}
|
||||
|
||||
static bool create_descriptor_heaps(Renderer *r) {
|
||||
{
|
||||
D3D12_DESCRIPTOR_HEAP_DESC desc = {};
|
||||
desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
|
||||
desc.NumDescriptors = NUM_BACK_BUFFERS;
|
||||
desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
|
||||
desc.NodeMask = 1;
|
||||
if (r->device->CreateDescriptorHeap(&desc, IID_PPV_ARGS(&r->rtv_heap)) != S_OK)
|
||||
return false;
|
||||
|
||||
SIZE_T rtv_size = r->device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE handle = r->rtv_heap->GetCPUDescriptorHandleForHeapStart();
|
||||
for (int i = 0; i < NUM_BACK_BUFFERS; i++) {
|
||||
r->rtv_descriptors[i] = handle;
|
||||
handle.ptr += rtv_size;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
D3D12_DESCRIPTOR_HEAP_DESC desc = {};
|
||||
desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
|
||||
desc.NumDescriptors = SRV_HEAP_SIZE;
|
||||
desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
|
||||
if (r->device->CreateDescriptorHeap(&desc, IID_PPV_ARGS(&r->srv_heap)) != S_OK)
|
||||
return false;
|
||||
|
||||
srv_alloc_init(&r->srv_alloc, r->device, r->srv_heap);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool create_frame_resources(Renderer *r) {
|
||||
for (int i = 0; i < r->frame_count; i++) {
|
||||
if (r->device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
|
||||
IID_PPV_ARGS(&r->frames[i].command_allocator)) != S_OK)
|
||||
return false;
|
||||
r->frames[i].fence_value = 0;
|
||||
}
|
||||
|
||||
if (r->device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT,
|
||||
r->frames[0].command_allocator, nullptr, IID_PPV_ARGS(&r->command_list)) != S_OK)
|
||||
return false;
|
||||
if (r->command_list->Close() != S_OK)
|
||||
return false;
|
||||
|
||||
if (r->device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&r->fence)) != S_OK)
|
||||
return false;
|
||||
|
||||
r->fence_event = CreateEventW(nullptr, FALSE, FALSE, nullptr);
|
||||
return r->fence_event != nullptr;
|
||||
}
|
||||
|
||||
static bool create_swap_chain(Renderer *r) {
|
||||
DXGI_SWAP_CHAIN_DESC1 sd = {};
|
||||
sd.BufferCount = NUM_BACK_BUFFERS;
|
||||
sd.Width = 0;
|
||||
sd.Height = 0;
|
||||
sd.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
sd.Flags = DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT;
|
||||
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
sd.SampleDesc.Count = 1;
|
||||
sd.SampleDesc.Quality = 0;
|
||||
sd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
|
||||
sd.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
|
||||
sd.Scaling = DXGI_SCALING_STRETCH;
|
||||
sd.Stereo = FALSE;
|
||||
|
||||
IDXGIFactory5 *factory = nullptr;
|
||||
if (CreateDXGIFactory1(IID_PPV_ARGS(&factory)) != S_OK)
|
||||
return false;
|
||||
|
||||
BOOL allow_tearing = FALSE;
|
||||
factory->CheckFeatureSupport(DXGI_FEATURE_PRESENT_ALLOW_TEARING, &allow_tearing, sizeof(allow_tearing));
|
||||
r->tearing_support = (allow_tearing == TRUE);
|
||||
if (r->tearing_support)
|
||||
sd.Flags |= DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING;
|
||||
|
||||
IDXGISwapChain1 *swap_chain1 = nullptr;
|
||||
if (factory->CreateSwapChainForHwnd(r->command_queue, r->hwnd, &sd, nullptr, nullptr, &swap_chain1) != S_OK) {
|
||||
factory->Release();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (swap_chain1->QueryInterface(IID_PPV_ARGS(&r->swap_chain)) != S_OK) {
|
||||
swap_chain1->Release();
|
||||
factory->Release();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (r->tearing_support)
|
||||
factory->MakeWindowAssociation(r->hwnd, DXGI_MWA_NO_ALT_ENTER);
|
||||
|
||||
swap_chain1->Release();
|
||||
factory->Release();
|
||||
|
||||
r->swap_chain->SetMaximumFrameLatency(NUM_BACK_BUFFERS);
|
||||
r->swap_chain_waitable = r->swap_chain->GetFrameLatencyWaitableObject();
|
||||
return true;
|
||||
}
|
||||
|
||||
static void create_render_targets(Renderer *r) {
|
||||
for (UINT i = 0; i < NUM_BACK_BUFFERS; i++) {
|
||||
ID3D12Resource *back_buffer = nullptr;
|
||||
r->swap_chain->GetBuffer(i, IID_PPV_ARGS(&back_buffer));
|
||||
r->device->CreateRenderTargetView(back_buffer, nullptr, r->rtv_descriptors[i]);
|
||||
r->render_targets[i] = back_buffer;
|
||||
}
|
||||
}
|
||||
|
||||
static void cleanup_render_targets(Renderer *r) {
|
||||
for (UINT i = 0; i < NUM_BACK_BUFFERS; i++) {
|
||||
if (r->render_targets[i]) {
|
||||
r->render_targets[i]->Release();
|
||||
r->render_targets[i] = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void wait_for_pending(Renderer *r) {
|
||||
r->command_queue->Signal(r->fence, ++r->fence_last_signaled);
|
||||
r->fence->SetEventOnCompletion(r->fence_last_signaled, r->fence_event);
|
||||
WaitForSingleObject(r->fence_event, INFINITE);
|
||||
}
|
||||
|
||||
static FrameContext *wait_for_next_frame(Renderer *r) {
|
||||
FrameContext *fc = &r->frames[r->frame_index % r->frame_count];
|
||||
if (r->fence->GetCompletedValue() < fc->fence_value) {
|
||||
r->fence->SetEventOnCompletion(fc->fence_value, r->fence_event);
|
||||
HANDLE waitables[] = { r->swap_chain_waitable, r->fence_event };
|
||||
WaitForMultipleObjects(2, waitables, TRUE, INFINITE);
|
||||
} else {
|
||||
WaitForSingleObject(r->swap_chain_waitable, INFINITE);
|
||||
}
|
||||
return fc;
|
||||
}
|
||||
|
||||
static void init_imgui(Renderer *r) {
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||
|
||||
ImGui::StyleColorsDark();
|
||||
|
||||
ImGui_ImplWin32_Init(r->hwnd);
|
||||
|
||||
ImGui_ImplDX12_InitInfo init_info = {};
|
||||
init_info.Device = r->device;
|
||||
init_info.CommandQueue = r->command_queue;
|
||||
init_info.NumFramesInFlight = r->frame_count;
|
||||
init_info.RTVFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
init_info.DSVFormat = DXGI_FORMAT_UNKNOWN;
|
||||
init_info.SrvDescriptorHeap = r->srv_heap;
|
||||
init_info.SrvDescriptorAllocFn = [](ImGui_ImplDX12_InitInfo *info, D3D12_CPU_DESCRIPTOR_HANDLE *out_cpu, D3D12_GPU_DESCRIPTOR_HANDLE *out_gpu) {
|
||||
Renderer *r = (Renderer *)info->UserData;
|
||||
srv_alloc_alloc(&r->srv_alloc, out_cpu, out_gpu);
|
||||
};
|
||||
init_info.SrvDescriptorFreeFn = [](ImGui_ImplDX12_InitInfo *info, D3D12_CPU_DESCRIPTOR_HANDLE cpu, D3D12_GPU_DESCRIPTOR_HANDLE gpu) {
|
||||
Renderer *r = (Renderer *)info->UserData;
|
||||
srv_alloc_free(&r->srv_alloc, cpu, gpu);
|
||||
};
|
||||
init_info.UserData = r;
|
||||
ImGui_ImplDX12_Init(&init_info);
|
||||
}
|
||||
|
||||
Renderer *renderer_create(RendererDesc *desc) {
|
||||
Renderer *r = new Renderer();
|
||||
memset(r, 0, sizeof(*r));
|
||||
|
||||
r->hwnd = (HWND)desc->window_handle;
|
||||
r->width = desc->width;
|
||||
r->height = desc->height;
|
||||
r->frame_count = desc->frame_count;
|
||||
if (r->frame_count > NUM_BACK_BUFFERS) r->frame_count = NUM_BACK_BUFFERS;
|
||||
|
||||
if (!create_device(r)) goto fail;
|
||||
if (!create_command_queue(r)) goto fail;
|
||||
if (!create_descriptor_heaps(r)) goto fail;
|
||||
if (!create_frame_resources(r)) goto fail;
|
||||
if (!create_swap_chain(r)) goto fail;
|
||||
create_render_targets(r);
|
||||
|
||||
init_imgui(r);
|
||||
return r;
|
||||
|
||||
fail:
|
||||
renderer_destroy(r);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void renderer_destroy(Renderer *r) {
|
||||
if (!r) return;
|
||||
|
||||
wait_for_pending(r);
|
||||
|
||||
ImGui_ImplDX12_Shutdown();
|
||||
ImGui_ImplWin32_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
||||
cleanup_render_targets(r);
|
||||
|
||||
if (r->swap_chain) { r->swap_chain->SetFullscreenState(false, nullptr); r->swap_chain->Release(); }
|
||||
if (r->swap_chain_waitable) CloseHandle(r->swap_chain_waitable);
|
||||
for (int i = 0; i < r->frame_count; i++)
|
||||
if (r->frames[i].command_allocator) r->frames[i].command_allocator->Release();
|
||||
if (r->command_queue) r->command_queue->Release();
|
||||
if (r->command_list) r->command_list->Release();
|
||||
if (r->rtv_heap) r->rtv_heap->Release();
|
||||
if (r->srv_heap) r->srv_heap->Release();
|
||||
if (r->fence) r->fence->Release();
|
||||
if (r->fence_event) CloseHandle(r->fence_event);
|
||||
if (r->device) r->device->Release();
|
||||
|
||||
#ifdef DX12_ENABLE_DEBUG_LAYER
|
||||
IDXGIDebug1 *dxgi_debug = nullptr;
|
||||
if (SUCCEEDED(DXGIGetDebugInterface1(0, IID_PPV_ARGS(&dxgi_debug)))) {
|
||||
dxgi_debug->ReportLiveObjects(DXGI_DEBUG_ALL, DXGI_DEBUG_RLO_SUMMARY);
|
||||
dxgi_debug->Release();
|
||||
}
|
||||
#endif
|
||||
|
||||
delete r;
|
||||
}
|
||||
|
||||
bool renderer_begin_frame(Renderer *r) {
|
||||
if ((r->swap_chain_occluded && r->swap_chain->Present(0, DXGI_PRESENT_TEST) == DXGI_STATUS_OCCLUDED)
|
||||
|| IsIconic(r->hwnd))
|
||||
{
|
||||
Sleep(10);
|
||||
return false;
|
||||
}
|
||||
r->swap_chain_occluded = false;
|
||||
|
||||
ImGui_ImplDX12_NewFrame();
|
||||
ImGui_ImplWin32_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
return true;
|
||||
}
|
||||
|
||||
void renderer_end_frame(Renderer *r) {
|
||||
ImGui::Render();
|
||||
|
||||
FrameContext *fc = wait_for_next_frame(r);
|
||||
UINT back_buffer_idx = r->swap_chain->GetCurrentBackBufferIndex();
|
||||
|
||||
fc->command_allocator->Reset();
|
||||
r->command_list->Reset(fc->command_allocator, nullptr);
|
||||
|
||||
D3D12_RESOURCE_BARRIER barrier = {};
|
||||
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
||||
barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
|
||||
barrier.Transition.pResource = r->render_targets[back_buffer_idx];
|
||||
barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
|
||||
barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_PRESENT;
|
||||
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET;
|
||||
r->command_list->ResourceBarrier(1, &barrier);
|
||||
|
||||
const float clear_color[4] = { 0.1f, 0.1f, 0.1f, 1.0f };
|
||||
r->command_list->ClearRenderTargetView(r->rtv_descriptors[back_buffer_idx], clear_color, 0, nullptr);
|
||||
r->command_list->OMSetRenderTargets(1, &r->rtv_descriptors[back_buffer_idx], FALSE, nullptr);
|
||||
r->command_list->SetDescriptorHeaps(1, &r->srv_heap);
|
||||
|
||||
ImGui_ImplDX12_RenderDrawData(ImGui::GetDrawData(), r->command_list);
|
||||
|
||||
barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_RENDER_TARGET;
|
||||
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_PRESENT;
|
||||
r->command_list->ResourceBarrier(1, &barrier);
|
||||
r->command_list->Close();
|
||||
|
||||
r->command_queue->ExecuteCommandLists(1, (ID3D12CommandList *const *)&r->command_list);
|
||||
r->command_queue->Signal(r->fence, ++r->fence_last_signaled);
|
||||
fc->fence_value = r->fence_last_signaled;
|
||||
|
||||
HRESULT hr = r->swap_chain->Present(1, 0);
|
||||
r->swap_chain_occluded = (hr == DXGI_STATUS_OCCLUDED);
|
||||
r->frame_index++;
|
||||
}
|
||||
|
||||
void renderer_resize(Renderer *r, int32_t width, int32_t height) {
|
||||
if (width <= 0 || height <= 0) return;
|
||||
|
||||
wait_for_pending(r);
|
||||
cleanup_render_targets(r);
|
||||
|
||||
DXGI_SWAP_CHAIN_DESC1 desc = {};
|
||||
r->swap_chain->GetDesc1(&desc);
|
||||
r->swap_chain->ResizeBuffers(0, (UINT)width, (UINT)height, desc.Format, desc.Flags);
|
||||
|
||||
create_render_targets(r);
|
||||
|
||||
r->width = width;
|
||||
r->height = height;
|
||||
}
|
||||
1044
src/renderer/renderer_metal.m
Normal file
1044
src/renderer/renderer_metal.m
Normal file
File diff suppressed because it is too large
Load Diff
1823
src/renderer/renderer_vulkan.c
Normal file
1823
src/renderer/renderer_vulkan.c
Normal file
File diff suppressed because it is too large
Load Diff
61
src/renderer/ui.f.glsl
Normal file
61
src/renderer/ui.f.glsl
Normal file
@@ -0,0 +1,61 @@
|
||||
#version 450
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D tex;
|
||||
|
||||
layout(location = 0) in vec2 frag_uv;
|
||||
layout(location = 1) in vec4 frag_col;
|
||||
layout(location = 2) in vec2 frag_rect_min;
|
||||
layout(location = 3) in vec2 frag_rect_max;
|
||||
layout(location = 4) in vec4 frag_corner_radii;
|
||||
layout(location = 5) in float frag_border_thickness;
|
||||
layout(location = 6) in float frag_softness;
|
||||
layout(location = 7) in float frag_mode;
|
||||
layout(location = 8) in vec2 frag_pixel_pos;
|
||||
|
||||
layout(location = 0) out vec4 out_color;
|
||||
|
||||
float rounded_rect_sdf(vec2 sample_pos, vec2 rect_center, vec2 rect_half_size, float radius) {
|
||||
vec2 d = abs(sample_pos - rect_center) - rect_half_size + vec2(radius, radius);
|
||||
return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0) - radius;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec4 col = frag_col;
|
||||
|
||||
if (frag_mode > 1.5) {
|
||||
// RGBA textured mode: sample all channels, multiply by vertex color
|
||||
vec4 tex_sample = texture(tex, frag_uv);
|
||||
col *= tex_sample;
|
||||
} else if (frag_mode > 0.5) {
|
||||
// Alpha-only textured mode: sample R channel as alpha (font atlas)
|
||||
float alpha = texture(tex, frag_uv).r;
|
||||
col.a *= alpha;
|
||||
} else {
|
||||
// SDF rounded rect mode
|
||||
vec2 pixel_pos = frag_pixel_pos;
|
||||
vec2 rect_center = (frag_rect_min + frag_rect_max) * 0.5;
|
||||
vec2 rect_half_size = (frag_rect_max - frag_rect_min) * 0.5;
|
||||
// corner_radii = (TL, TR, BR, BL) - select radius by quadrant
|
||||
float radius = (pixel_pos.x < rect_center.x)
|
||||
? ((pixel_pos.y < rect_center.y) ? frag_corner_radii.x : frag_corner_radii.w)
|
||||
: ((pixel_pos.y < rect_center.y) ? frag_corner_radii.y : frag_corner_radii.z);
|
||||
float softness = max(frag_softness, 0.5);
|
||||
float dist = rounded_rect_sdf(pixel_pos, rect_center, rect_half_size, radius);
|
||||
|
||||
if (frag_border_thickness > 0) {
|
||||
float inner_dist = dist + frag_border_thickness;
|
||||
float outer_alpha = 1.0 - smoothstep(-softness, softness, dist);
|
||||
float inner_alpha = smoothstep(-softness, softness, inner_dist);
|
||||
col.a *= outer_alpha * inner_alpha;
|
||||
} else {
|
||||
col.a *= 1.0 - smoothstep(-softness, softness, dist);
|
||||
}
|
||||
}
|
||||
|
||||
// Dither to reduce gradient banding (interleaved gradient noise)
|
||||
float dither = fract(52.9829189 * fract(dot(frag_pixel_pos, vec2(0.06711056, 0.00583715)))) - 0.5;
|
||||
col.rgb += dither / 255.0;
|
||||
|
||||
if (col.a < 0.002) discard;
|
||||
out_color = col;
|
||||
}
|
||||
43
src/renderer/ui.v.glsl
Normal file
43
src/renderer/ui.v.glsl
Normal file
@@ -0,0 +1,43 @@
|
||||
#version 450
|
||||
|
||||
layout(push_constant) uniform PushConstants {
|
||||
vec2 viewport_size;
|
||||
vec2 _padding;
|
||||
} pc;
|
||||
|
||||
layout(location = 0) in vec2 in_pos;
|
||||
layout(location = 1) in vec2 in_uv;
|
||||
layout(location = 2) in vec4 in_col;
|
||||
layout(location = 3) in vec2 in_rect_min;
|
||||
layout(location = 4) in vec2 in_rect_max;
|
||||
layout(location = 5) in vec4 in_corner_radii;
|
||||
layout(location = 6) in float in_border_thickness;
|
||||
layout(location = 7) in float in_softness;
|
||||
layout(location = 8) in float in_mode;
|
||||
|
||||
layout(location = 0) out vec2 frag_uv;
|
||||
layout(location = 1) out vec4 frag_col;
|
||||
layout(location = 2) out vec2 frag_rect_min;
|
||||
layout(location = 3) out vec2 frag_rect_max;
|
||||
layout(location = 4) out vec4 frag_corner_radii;
|
||||
layout(location = 5) out float frag_border_thickness;
|
||||
layout(location = 6) out float frag_softness;
|
||||
layout(location = 7) out float frag_mode;
|
||||
layout(location = 8) out vec2 frag_pixel_pos;
|
||||
|
||||
void main() {
|
||||
vec2 ndc;
|
||||
ndc.x = (in_pos.x / pc.viewport_size.x) * 2.0 - 1.0;
|
||||
ndc.y = (in_pos.y / pc.viewport_size.y) * 2.0 - 1.0; // Vulkan Y is top-down already
|
||||
gl_Position = vec4(ndc, 0.0, 1.0);
|
||||
|
||||
frag_uv = in_uv;
|
||||
frag_col = in_col;
|
||||
frag_rect_min = in_rect_min;
|
||||
frag_rect_max = in_rect_max;
|
||||
frag_corner_radii = in_corner_radii;
|
||||
frag_border_thickness = in_border_thickness;
|
||||
frag_softness = in_softness;
|
||||
frag_mode = in_mode;
|
||||
frag_pixel_pos = in_pos;
|
||||
}
|
||||
104
src/theme.cpp
104
src/theme.cpp
@@ -1,104 +0,0 @@
|
||||
#include "imgui.h"
|
||||
|
||||
static void setup_theme() {
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
|
||||
// Load Segoe UI from Windows system fonts
|
||||
ImFontConfig font_cfg = {};
|
||||
font_cfg.OversampleH = 2;
|
||||
font_cfg.OversampleV = 1;
|
||||
font_cfg.PixelSnapH = true;
|
||||
io.Fonts->AddFontFromFileTTF("C:\\Windows\\Fonts\\segoeui.ttf", 15.0f, &font_cfg);
|
||||
|
||||
// DAW-style dark theme
|
||||
ImGuiStyle &s = ImGui::GetStyle();
|
||||
|
||||
// Geometry
|
||||
s.WindowPadding = ImVec2(8, 8);
|
||||
s.FramePadding = ImVec2(6, 4);
|
||||
s.ItemSpacing = ImVec2(8, 4);
|
||||
s.ItemInnerSpacing = ImVec2(4, 4);
|
||||
s.ScrollbarSize = 12.0f;
|
||||
s.GrabMinSize = 8.0f;
|
||||
s.WindowBorderSize = 1.0f;
|
||||
s.FrameBorderSize = 0.0f;
|
||||
s.TabBorderSize = 0.0f;
|
||||
s.WindowRounding = 2.0f;
|
||||
s.FrameRounding = 2.0f;
|
||||
s.GrabRounding = 2.0f;
|
||||
s.TabRounding = 2.0f;
|
||||
s.ScrollbarRounding = 2.0f;
|
||||
|
||||
ImVec4 *c = s.Colors;
|
||||
|
||||
// Backgrounds
|
||||
c[ImGuiCol_WindowBg] = ImVec4(0.12f, 0.12f, 0.13f, 1.00f);
|
||||
c[ImGuiCol_ChildBg] = ImVec4(0.12f, 0.12f, 0.13f, 1.00f);
|
||||
c[ImGuiCol_PopupBg] = ImVec4(0.15f, 0.15f, 0.16f, 1.00f);
|
||||
|
||||
// Borders
|
||||
c[ImGuiCol_Border] = ImVec4(0.22f, 0.22f, 0.24f, 1.00f);
|
||||
c[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
|
||||
// Text
|
||||
c[ImGuiCol_Text] = ImVec4(0.88f, 0.88f, 0.88f, 1.00f);
|
||||
c[ImGuiCol_TextDisabled] = ImVec4(0.44f, 0.44f, 0.44f, 1.00f);
|
||||
|
||||
// Headers (collapsing headers, menu bar items)
|
||||
c[ImGuiCol_Header] = ImVec4(0.20f, 0.20f, 0.22f, 1.00f);
|
||||
c[ImGuiCol_HeaderHovered] = ImVec4(0.28f, 0.28f, 0.30f, 1.00f);
|
||||
c[ImGuiCol_HeaderActive] = ImVec4(0.24f, 0.24f, 0.26f, 1.00f);
|
||||
|
||||
// Buttons
|
||||
c[ImGuiCol_Button] = ImVec4(0.22f, 0.22f, 0.24f, 1.00f);
|
||||
c[ImGuiCol_ButtonHovered] = ImVec4(0.30f, 0.30f, 0.33f, 1.00f);
|
||||
c[ImGuiCol_ButtonActive] = ImVec4(0.26f, 0.26f, 0.28f, 1.00f);
|
||||
|
||||
// Frame backgrounds (inputs, checkboxes, sliders)
|
||||
c[ImGuiCol_FrameBg] = ImVec4(0.16f, 0.16f, 0.17f, 1.00f);
|
||||
c[ImGuiCol_FrameBgHovered] = ImVec4(0.20f, 0.20f, 0.22f, 1.00f);
|
||||
c[ImGuiCol_FrameBgActive] = ImVec4(0.18f, 0.18f, 0.20f, 1.00f);
|
||||
|
||||
// Tabs
|
||||
c[ImGuiCol_Tab] = ImVec4(0.16f, 0.16f, 0.17f, 1.00f);
|
||||
c[ImGuiCol_TabHovered] = ImVec4(0.28f, 0.28f, 0.30f, 1.00f);
|
||||
c[ImGuiCol_TabSelected] = ImVec4(0.20f, 0.20f, 0.22f, 1.00f);
|
||||
c[ImGuiCol_TabSelectedOverline] = ImVec4(0.34f, 0.54f, 0.69f, 1.00f);
|
||||
c[ImGuiCol_TabDimmed] = ImVec4(0.12f, 0.12f, 0.13f, 1.00f);
|
||||
c[ImGuiCol_TabDimmedSelected] = ImVec4(0.16f, 0.16f, 0.17f, 1.00f);
|
||||
|
||||
// Title bar
|
||||
c[ImGuiCol_TitleBg] = ImVec4(0.10f, 0.10f, 0.11f, 1.00f);
|
||||
c[ImGuiCol_TitleBgActive] = ImVec4(0.13f, 0.13f, 0.14f, 1.00f);
|
||||
c[ImGuiCol_TitleBgCollapsed] = ImVec4(0.10f, 0.10f, 0.11f, 1.00f);
|
||||
|
||||
// Scrollbar
|
||||
c[ImGuiCol_ScrollbarBg] = ImVec4(0.10f, 0.10f, 0.11f, 1.00f);
|
||||
c[ImGuiCol_ScrollbarGrab] = ImVec4(0.24f, 0.24f, 0.26f, 1.00f);
|
||||
c[ImGuiCol_ScrollbarGrabHovered]= ImVec4(0.30f, 0.30f, 0.33f, 1.00f);
|
||||
c[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.34f, 0.34f, 0.37f, 1.00f);
|
||||
|
||||
// Slider grab
|
||||
c[ImGuiCol_SliderGrab] = ImVec4(0.34f, 0.54f, 0.69f, 1.00f);
|
||||
c[ImGuiCol_SliderGrabActive] = ImVec4(0.40f, 0.60f, 0.75f, 1.00f);
|
||||
|
||||
// Checkmark, accent
|
||||
c[ImGuiCol_CheckMark] = ImVec4(0.34f, 0.54f, 0.69f, 1.00f);
|
||||
|
||||
// Separator
|
||||
c[ImGuiCol_Separator] = ImVec4(0.22f, 0.22f, 0.24f, 1.00f);
|
||||
c[ImGuiCol_SeparatorHovered] = ImVec4(0.34f, 0.54f, 0.69f, 1.00f);
|
||||
c[ImGuiCol_SeparatorActive] = ImVec4(0.34f, 0.54f, 0.69f, 1.00f);
|
||||
|
||||
// Resize grip
|
||||
c[ImGuiCol_ResizeGrip] = ImVec4(0.22f, 0.22f, 0.24f, 0.50f);
|
||||
c[ImGuiCol_ResizeGripHovered] = ImVec4(0.34f, 0.54f, 0.69f, 0.67f);
|
||||
c[ImGuiCol_ResizeGripActive] = ImVec4(0.34f, 0.54f, 0.69f, 0.95f);
|
||||
|
||||
// Docking
|
||||
c[ImGuiCol_DockingPreview] = ImVec4(0.34f, 0.54f, 0.69f, 0.70f);
|
||||
c[ImGuiCol_DockingEmptyBg] = ImVec4(0.10f, 0.10f, 0.11f, 1.00f);
|
||||
|
||||
// Menu bar
|
||||
c[ImGuiCol_MenuBarBg] = ImVec4(0.14f, 0.14f, 0.15f, 1.00f);
|
||||
}
|
||||
239
src/ui/ui_core.c
Normal file
239
src/ui/ui_core.c
Normal file
@@ -0,0 +1,239 @@
|
||||
// ui_core.c - Clay wrapper implementation
|
||||
// CLAY_IMPLEMENTATION must be defined exactly once before including clay.h.
|
||||
// In the unity build, ui_core.h (which includes clay.h) has #pragma once,
|
||||
// so we include clay.h directly here first to get the implementation compiled.
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
// MSVC: stub out Clay's debug view (uses CLAY() macros MSVC can't compile in C)
|
||||
#ifdef _MSC_VER
|
||||
#define CLAY_DISABLE_DEBUG_VIEW
|
||||
#endif
|
||||
|
||||
#define CLAY_IMPLEMENTATION
|
||||
#include "clay.h"
|
||||
|
||||
// MSVC C mode: bypass Clay's wrapper struct pattern for designated initializers.
|
||||
// Must come after clay.h so CLAY__CONFIG_WRAPPER is defined, then we override it.
|
||||
#ifdef _MSC_VER
|
||||
#undef CLAY__CONFIG_WRAPPER
|
||||
#define CLAY__CONFIG_WRAPPER(type, ...) ((type) { __VA_ARGS__ })
|
||||
#endif
|
||||
|
||||
#include "ui/ui_core.h"
|
||||
|
||||
////////////////////////////////
|
||||
// UI scale global
|
||||
|
||||
F32 g_ui_scale = 1.0f;
|
||||
|
||||
////////////////////////////////
|
||||
// Theme global
|
||||
|
||||
UI_Theme g_theme = {0};
|
||||
S32 g_theme_id = 0;
|
||||
|
||||
void ui_set_theme(S32 theme_id) {
|
||||
g_theme_id = theme_id;
|
||||
|
||||
switch (theme_id) {
|
||||
default:
|
||||
case 0: // Dark
|
||||
g_theme.bg_dark = (Clay_Color){ 26, 26, 26, 255};
|
||||
g_theme.bg_medium = (Clay_Color){ 36, 36, 36, 255};
|
||||
g_theme.bg_light = (Clay_Color){ 46, 46, 46, 255};
|
||||
g_theme.bg_lighter = (Clay_Color){ 54, 54, 54, 255};
|
||||
g_theme.border = (Clay_Color){ 52, 52, 52, 255};
|
||||
g_theme.text = (Clay_Color){220, 220, 220, 255};
|
||||
g_theme.text_dim = (Clay_Color){105, 105, 105, 255};
|
||||
g_theme.accent = (Clay_Color){ 87, 138, 176, 255};
|
||||
g_theme.accent_hover = (Clay_Color){102, 153, 191, 255};
|
||||
g_theme.button_text = (Clay_Color){224, 224, 224, 255};
|
||||
g_theme.disabled_bg = (Clay_Color){ 44, 44, 44, 255};
|
||||
g_theme.disabled_text = (Clay_Color){ 90, 90, 90, 255};
|
||||
g_theme.header_bg = (Clay_Color){ 46, 46, 46, 255};
|
||||
g_theme.title_bar = (Clay_Color){ 22, 22, 22, 255};
|
||||
g_theme.scrollbar_bg = (Clay_Color){ 22, 22, 22, 255};
|
||||
g_theme.scrollbar_grab = (Clay_Color){ 58, 58, 58, 255};
|
||||
g_theme.shadow = (Clay_Color){ 0, 0, 0, 30};
|
||||
g_theme.tab_active_top = (Clay_Color){ 70, 120, 160, 255};
|
||||
g_theme.tab_active_bottom= (Clay_Color){ 30, 55, 80, 255};
|
||||
g_theme.tab_inactive = (Clay_Color){ 40, 40, 40, 255};
|
||||
g_theme.tab_inactive_hover= (Clay_Color){ 50, 50, 50, 255};
|
||||
g_theme.tab_text = (Clay_Color){240, 240, 240, 255};
|
||||
g_theme.corner_radius = 4.0f;
|
||||
break;
|
||||
|
||||
case 1: // Light
|
||||
g_theme.bg_dark = (Clay_Color){195, 193, 190, 255};
|
||||
g_theme.bg_medium = (Clay_Color){212, 210, 207, 255};
|
||||
g_theme.bg_light = (Clay_Color){225, 223, 220, 255};
|
||||
g_theme.bg_lighter = (Clay_Color){232, 230, 227, 255};
|
||||
g_theme.border = (Clay_Color){178, 176, 173, 255};
|
||||
g_theme.text = (Clay_Color){ 35, 33, 30, 255};
|
||||
g_theme.text_dim = (Clay_Color){115, 113, 108, 255};
|
||||
g_theme.accent = (Clay_Color){ 50, 110, 170, 255};
|
||||
g_theme.accent_hover = (Clay_Color){ 65, 125, 185, 255};
|
||||
g_theme.button_text = (Clay_Color){255, 255, 255, 255};
|
||||
g_theme.disabled_bg = (Clay_Color){185, 183, 180, 255};
|
||||
g_theme.disabled_text = (Clay_Color){145, 143, 140, 255};
|
||||
g_theme.header_bg = (Clay_Color){202, 200, 197, 255};
|
||||
g_theme.title_bar = (Clay_Color){202, 200, 197, 255};
|
||||
g_theme.scrollbar_bg = (Clay_Color){202, 200, 197, 255};
|
||||
g_theme.scrollbar_grab = (Clay_Color){168, 166, 163, 255};
|
||||
g_theme.shadow = (Clay_Color){ 0, 0, 0, 18};
|
||||
g_theme.tab_active_top = (Clay_Color){ 70, 130, 180, 255};
|
||||
g_theme.tab_active_bottom= (Clay_Color){ 50, 100, 150, 255};
|
||||
g_theme.tab_inactive = (Clay_Color){205, 203, 200, 255};
|
||||
g_theme.tab_inactive_hover= (Clay_Color){195, 193, 190, 255};
|
||||
g_theme.tab_text = (Clay_Color){255, 255, 255, 255};
|
||||
g_theme.corner_radius = 4.0f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Accent palette
|
||||
|
||||
S32 g_accent_id = 0;
|
||||
|
||||
void ui_set_accent(S32 accent_id) {
|
||||
g_accent_id = accent_id;
|
||||
B32 dark = (g_theme_id == 0);
|
||||
|
||||
// Each palette: accent, accent_hover, tab_top, tab_bottom, button_text, tab_text
|
||||
typedef struct AccentColors {
|
||||
Clay_Color accent, accent_hover, tab_top, tab_bottom, button_text, tab_text;
|
||||
} AccentColors;
|
||||
|
||||
// Dark-mode palettes
|
||||
static const AccentColors dark_palettes[] = {
|
||||
// 0: Blue
|
||||
{ {87,138,176,255}, {102,153,191,255}, {70,120,160,255}, {30,55,80,255}, {224,224,224,255}, {240,240,240,255} },
|
||||
// 1: Turquoise
|
||||
{ {60,160,155,255}, {75,175,170,255}, {50,140,135,255}, {25,70,68,255}, {224,224,224,255}, {240,240,240,255} },
|
||||
// 2: Orange
|
||||
{ {200,130,50,255}, {215,145,65,255}, {190,120,40,255}, {100,60,20,255}, {240,240,240,255}, {240,240,240,255} },
|
||||
// 3: Purple
|
||||
{ {130,100,180,255}, {145,115,195,255}, {120,90,170,255}, {60,45,85,255}, {224,224,224,255}, {240,240,240,255} },
|
||||
// 4: Pink
|
||||
{ {185,95,140,255}, {200,110,155,255}, {175,85,130,255}, {88,42,65,255}, {240,240,240,255}, {240,240,240,255} },
|
||||
// 5: Red
|
||||
{ {190,75,75,255}, {205,90,90,255}, {180,65,65,255}, {90,32,32,255}, {240,240,240,255}, {240,240,240,255} },
|
||||
// 6: Green
|
||||
{ {80,155,80,255}, {95,170,95,255}, {70,140,70,255}, {35,70,35,255}, {240,240,240,255}, {240,240,240,255} },
|
||||
};
|
||||
|
||||
// Light-mode palettes (slightly more saturated for contrast on light bg)
|
||||
static const AccentColors light_palettes[] = {
|
||||
// 0: Blue
|
||||
{ {50,110,170,255}, {65,125,185,255}, {70,130,180,255}, {50,100,150,255}, {255,255,255,255}, {255,255,255,255} },
|
||||
// 1: Turquoise
|
||||
{ {30,140,135,255}, {45,155,150,255}, {40,150,145,255}, {25,115,110,255}, {255,255,255,255}, {255,255,255,255} },
|
||||
// 2: Orange
|
||||
{ {190,115,25,255}, {205,130,40,255}, {195,120,30,255}, {155,90,15,255}, {255,255,255,255}, {255,255,255,255} },
|
||||
// 3: Purple
|
||||
{ {110,75,170,255}, {125,90,185,255}, {115,80,175,255}, {85,55,140,255}, {255,255,255,255}, {255,255,255,255} },
|
||||
// 4: Pink
|
||||
{ {175,70,125,255}, {190,85,140,255}, {180,75,130,255}, {140,50,100,255}, {255,255,255,255}, {255,255,255,255} },
|
||||
// 5: Red
|
||||
{ {185,55,55,255}, {200,70,70,255}, {190,60,60,255}, {150,40,40,255}, {255,255,255,255}, {255,255,255,255} },
|
||||
// 6: Green
|
||||
{ {55,140,55,255}, {70,155,70,255}, {60,145,60,255}, {40,110,40,255}, {255,255,255,255}, {255,255,255,255} },
|
||||
};
|
||||
|
||||
S32 idx = accent_id;
|
||||
if (idx < 0) idx = 0;
|
||||
if (idx > 6) idx = 6;
|
||||
|
||||
const AccentColors *c = dark ? &dark_palettes[idx] : &light_palettes[idx];
|
||||
g_theme.accent = c->accent;
|
||||
g_theme.accent_hover = c->accent_hover;
|
||||
g_theme.tab_active_top = c->tab_top;
|
||||
g_theme.tab_active_bottom = c->tab_bottom;
|
||||
g_theme.button_text = c->button_text;
|
||||
g_theme.tab_text = c->tab_text;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Clay error handler
|
||||
|
||||
static void clay_error_handler(Clay_ErrorData error) {
|
||||
char buf[512];
|
||||
S32 len = error.errorText.length < 511 ? error.errorText.length : 511;
|
||||
memcpy(buf, error.errorText.chars, len);
|
||||
buf[len] = '\0';
|
||||
fprintf(stderr, "[Clay Error] %s\n", buf);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Clay text measurement bridge
|
||||
// Clay calls this; we forward to the app's UI_MeasureTextFn
|
||||
|
||||
static UI_Context *g_measure_ctx = NULL;
|
||||
|
||||
static Clay_Dimensions clay_measure_text(Clay_StringSlice text, Clay_TextElementConfig *config, void *user_data) {
|
||||
UI_Context *ctx = (UI_Context *)user_data;
|
||||
if (!ctx || !ctx->measure_text_fn || text.length == 0) {
|
||||
return (Clay_Dimensions){0, (F32)config->fontSize};
|
||||
}
|
||||
Vec2F32 result = ctx->measure_text_fn(text.chars, text.length, (F32)config->fontSize, ctx->measure_text_user_data);
|
||||
return (Clay_Dimensions){result.x, result.y};
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Lifecycle
|
||||
|
||||
UI_Context *ui_create(F32 viewport_w, F32 viewport_h) {
|
||||
UI_Context *ctx = (UI_Context *)calloc(1, sizeof(UI_Context));
|
||||
|
||||
U32 min_memory = Clay_MinMemorySize();
|
||||
ctx->clay_memory = malloc(min_memory);
|
||||
Clay_Arena clay_arena = Clay_CreateArenaWithCapacityAndMemory(min_memory, ctx->clay_memory);
|
||||
|
||||
Clay_ErrorHandler err_handler = {0};
|
||||
err_handler.errorHandlerFunction = clay_error_handler;
|
||||
err_handler.userData = ctx;
|
||||
|
||||
ctx->clay_ctx = Clay_Initialize(clay_arena,
|
||||
(Clay_Dimensions){viewport_w, viewport_h},
|
||||
err_handler);
|
||||
|
||||
Clay_SetMeasureTextFunction(clay_measure_text, ctx);
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void ui_destroy(UI_Context *ctx) {
|
||||
if (!ctx) return;
|
||||
free(ctx->clay_memory);
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
void ui_begin_frame(UI_Context *ctx, F32 viewport_w, F32 viewport_h,
|
||||
Vec2F32 mouse_pos, B32 mouse_down,
|
||||
Vec2F32 scroll_delta, F32 dt)
|
||||
{
|
||||
g_measure_ctx = ctx;
|
||||
Clay_SetCurrentContext(ctx->clay_ctx);
|
||||
Clay_SetLayoutDimensions((Clay_Dimensions){viewport_w, viewport_h});
|
||||
Clay_SetPointerState((Clay_Vector2){mouse_pos.x, mouse_pos.y}, mouse_down != 0);
|
||||
Clay_UpdateScrollContainers(false, (Clay_Vector2){scroll_delta.x, scroll_delta.y}, dt);
|
||||
Clay_BeginLayout();
|
||||
}
|
||||
|
||||
Clay_RenderCommandArray ui_end_frame(UI_Context *ctx) {
|
||||
(void)ctx;
|
||||
return Clay_EndLayout();
|
||||
}
|
||||
|
||||
void ui_set_measure_text_fn(UI_Context *ctx, UI_MeasureTextFn fn, void *user_data) {
|
||||
ctx->measure_text_fn = fn;
|
||||
ctx->measure_text_user_data = user_data;
|
||||
}
|
||||
|
||||
Vec2F32 ui_measure_text(const char *text, S32 length, F32 font_size) {
|
||||
if (!g_measure_ctx || !g_measure_ctx->measure_text_fn || length == 0)
|
||||
return v2f32(0, font_size);
|
||||
return g_measure_ctx->measure_text_fn(text, length, font_size, g_measure_ctx->measure_text_user_data);
|
||||
}
|
||||
191
src/ui/ui_core.h
Normal file
191
src/ui/ui_core.h
Normal file
@@ -0,0 +1,191 @@
|
||||
#pragma once
|
||||
// ui_core.h - Thin wrapper around Clay (https://github.com/nicbarker/clay)
|
||||
// Provides Clay initialization, per-frame lifecycle, and text measurement bridging.
|
||||
|
||||
#include "base/base_inc.h"
|
||||
#include "clay.h"
|
||||
|
||||
////////////////////////////////
|
||||
// Text measurement callback (provided by renderer)
|
||||
// This is our app-level callback; we adapt it to Clay's signature internally.
|
||||
|
||||
typedef Vec2F32 (*UI_MeasureTextFn)(const char *text, S32 length, F32 font_size, void *user_data);
|
||||
|
||||
////////////////////////////////
|
||||
// UI Context
|
||||
|
||||
typedef struct UI_Context {
|
||||
Clay_Context *clay_ctx;
|
||||
void *clay_memory;
|
||||
|
||||
// Text measurement
|
||||
UI_MeasureTextFn measure_text_fn;
|
||||
void *measure_text_user_data;
|
||||
} UI_Context;
|
||||
|
||||
////////////////////////////////
|
||||
// Lifecycle
|
||||
|
||||
UI_Context *ui_create(F32 viewport_w, F32 viewport_h);
|
||||
void ui_destroy(UI_Context *ctx);
|
||||
|
||||
// Call each frame before declaring layout
|
||||
void ui_begin_frame(UI_Context *ctx, F32 viewport_w, F32 viewport_h,
|
||||
Vec2F32 mouse_pos, B32 mouse_down,
|
||||
Vec2F32 scroll_delta, F32 dt);
|
||||
|
||||
// Call after layout is declared; returns Clay's render command array
|
||||
Clay_RenderCommandArray ui_end_frame(UI_Context *ctx);
|
||||
|
||||
////////////////////////////////
|
||||
// Text measurement
|
||||
|
||||
void ui_set_measure_text_fn(UI_Context *ctx, UI_MeasureTextFn fn, void *user_data);
|
||||
|
||||
// Measure text using the registered callback (available after ui_begin_frame)
|
||||
Vec2F32 ui_measure_text(const char *text, S32 length, F32 font_size);
|
||||
|
||||
////////////////////////////////
|
||||
// Theme colors (convenience - 0-255 Clay_Color)
|
||||
|
||||
typedef struct UI_Theme {
|
||||
Clay_Color bg_dark;
|
||||
Clay_Color bg_medium;
|
||||
Clay_Color bg_light;
|
||||
Clay_Color bg_lighter;
|
||||
Clay_Color border;
|
||||
Clay_Color text;
|
||||
Clay_Color text_dim;
|
||||
Clay_Color accent;
|
||||
Clay_Color accent_hover;
|
||||
Clay_Color button_text;
|
||||
Clay_Color disabled_bg;
|
||||
Clay_Color disabled_text;
|
||||
Clay_Color header_bg;
|
||||
Clay_Color title_bar;
|
||||
Clay_Color scrollbar_bg;
|
||||
Clay_Color scrollbar_grab;
|
||||
Clay_Color shadow; // Semi-transparent black for drop shadows
|
||||
|
||||
// Tab bar colors
|
||||
Clay_Color tab_active_top;
|
||||
Clay_Color tab_active_bottom;
|
||||
Clay_Color tab_inactive;
|
||||
Clay_Color tab_inactive_hover;
|
||||
Clay_Color tab_text; // Always light — readable on colored tab gradient
|
||||
|
||||
// Corner radius (unscaled pixels, applied via uis())
|
||||
F32 corner_radius;
|
||||
} UI_Theme;
|
||||
|
||||
extern UI_Theme g_theme;
|
||||
extern S32 g_theme_id;
|
||||
|
||||
// Set theme by index: 0 = Dark, 1 = Light
|
||||
void ui_set_theme(S32 theme_id);
|
||||
|
||||
// Accent color palette: 0=Blue, 1=Turquoise, 2=Orange, 3=Purple, 4=Pink, 5=Red, 6=Green
|
||||
extern S32 g_accent_id;
|
||||
void ui_set_accent(S32 accent_id);
|
||||
|
||||
////////////////////////////////
|
||||
// UI scale (Cmd+/Cmd- zoom)
|
||||
|
||||
extern F32 g_ui_scale;
|
||||
|
||||
// Scale a F32 value (for CLAY_SIZING_FIXED, corner radii, etc.)
|
||||
static inline F32 uis(F32 x) { return x * g_ui_scale; }
|
||||
|
||||
// Scale to U16 (for Clay_Padding, childGap, etc.)
|
||||
static inline U16 uip(F32 x) { return (U16)(x * g_ui_scale + 0.5f); }
|
||||
|
||||
// Scale to U16 font size
|
||||
static inline U16 uifs(F32 x) { return (U16)(x * g_ui_scale + 0.5f); }
|
||||
|
||||
////////////////////////////////
|
||||
// Tab styling
|
||||
|
||||
#define TAB_ACTIVE_TOP g_theme.tab_active_top
|
||||
#define TAB_ACTIVE_BOTTOM g_theme.tab_active_bottom
|
||||
#define TAB_INACTIVE_BG g_theme.tab_inactive
|
||||
#define TAB_INACTIVE_HOVER g_theme.tab_inactive_hover
|
||||
#define TAB_HEIGHT uis(26)
|
||||
#define TAB_CORNER_RADIUS CORNER_RADIUS
|
||||
#define TAB_PADDING_H uip(10)
|
||||
|
||||
////////////////////////////////
|
||||
// Custom render types (for gradient rects via CLAY_RENDER_COMMAND_TYPE_CUSTOM)
|
||||
|
||||
typedef enum CustomRenderType {
|
||||
CUSTOM_RENDER_VGRADIENT = 1,
|
||||
CUSTOM_RENDER_ICON = 2,
|
||||
CUSTOM_RENDER_ROTATED_ICON = 3,
|
||||
} CustomRenderType;
|
||||
|
||||
typedef struct CustomGradientData {
|
||||
CustomRenderType type;
|
||||
Clay_Color top_color;
|
||||
Clay_Color bottom_color;
|
||||
} CustomGradientData;
|
||||
|
||||
typedef struct CustomIconData {
|
||||
CustomRenderType type; // CUSTOM_RENDER_ICON
|
||||
S32 icon_id;
|
||||
Clay_Color color;
|
||||
} CustomIconData;
|
||||
|
||||
typedef struct CustomRotatedIconData {
|
||||
CustomRenderType type; // CUSTOM_RENDER_ROTATED_ICON
|
||||
S32 icon_id;
|
||||
Clay_Color color;
|
||||
F32 angle_rad;
|
||||
} CustomRotatedIconData;
|
||||
|
||||
////////////////////////////////
|
||||
// Font sizes
|
||||
|
||||
#define FONT_SIZE_NORMAL uifs(15)
|
||||
#define FONT_SIZE_SMALL uifs(12)
|
||||
#define FONT_SIZE_TAB uifs(13)
|
||||
|
||||
////////////////////////////////
|
||||
// Widget sizing
|
||||
|
||||
#define WIDGET_BUTTON_HEIGHT uis(30)
|
||||
#define WIDGET_CHECKBOX_HEIGHT uis(28)
|
||||
#define WIDGET_CHECKBOX_SIZE uis(18)
|
||||
#define WIDGET_RADIO_OUTER uis(16)
|
||||
#define WIDGET_RADIO_INNER uis(8)
|
||||
#define WIDGET_INPUT_HEIGHT uis(30)
|
||||
#define WIDGET_DROPDOWN_HEIGHT uis(30)
|
||||
#define WIDGET_DROPDOWN_ITEM_H uis(28)
|
||||
#define WIDGET_KNOB_SIZE uis(48)
|
||||
#define WIDGET_KNOB_LABEL_GAP uip(4)
|
||||
|
||||
#define WIDGET_SLIDER_H_WIDTH uis(160)
|
||||
#define WIDGET_SLIDER_H_TRACK_H uis(6)
|
||||
#define WIDGET_SLIDER_H_THUMB_W uis(14)
|
||||
#define WIDGET_SLIDER_H_THUMB_H uis(20)
|
||||
#define WIDGET_SLIDER_V_HEIGHT uis(100)
|
||||
#define WIDGET_SLIDER_V_TRACK_W uis(6)
|
||||
#define WIDGET_SLIDER_V_THUMB_W uis(20)
|
||||
#define WIDGET_SLIDER_V_THUMB_H uis(14)
|
||||
#define WIDGET_FADER_HEIGHT uis(160)
|
||||
#define WIDGET_FADER_TRACK_W uis(4)
|
||||
#define WIDGET_FADER_CAP_W uis(25)
|
||||
#define WIDGET_FADER_CAP_H uis(52)
|
||||
#define WIDGET_FADER_TICK_MAJOR_W uis(8)
|
||||
#define WIDGET_FADER_TICK_MINOR_W uis(4)
|
||||
#define WIDGET_FADER_TICK_H uis(1)
|
||||
|
||||
////////////////////////////////
|
||||
// Corner radius (from theme)
|
||||
|
||||
#define CORNER_RADIUS uis(g_theme.corner_radius)
|
||||
|
||||
////////////////////////////////
|
||||
// Panel sizing
|
||||
|
||||
#define PANEL_BROWSER_WIDTH uis(200)
|
||||
#define PANEL_RIGHT_COL_WIDTH uis(250)
|
||||
#define PANEL_LOG_HEIGHT uis(180)
|
||||
219
src/ui/ui_icons.c
Normal file
219
src/ui/ui_icons.c
Normal file
@@ -0,0 +1,219 @@
|
||||
// ui_icons.cpp - SVG icon rasterization via nanosvg
|
||||
|
||||
#include "ui/ui_icons.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define NANOSVG_IMPLEMENTATION
|
||||
#include "nanosvg.h"
|
||||
#define NANOSVGRAST_IMPLEMENTATION
|
||||
#include "nanosvgrast.h"
|
||||
|
||||
UI_IconInfo g_icons[UI_ICON_COUNT] = {0};
|
||||
|
||||
// Simple SVG icon sources (24x24 viewBox)
|
||||
static const char *g_icon_svgs[UI_ICON_COUNT] = {
|
||||
// UI_ICON_CLOSE - X mark
|
||||
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\">"
|
||||
"<path d=\"M6 6 L18 18 M18 6 L6 18\" stroke=\"white\" stroke-width=\"2.5\" stroke-linecap=\"round\"/>"
|
||||
"</svg>",
|
||||
|
||||
// UI_ICON_CHECK - checkmark
|
||||
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\">"
|
||||
"<path d=\"M5 12 L10 17 L19 7\" stroke=\"white\" stroke-width=\"2.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\" fill=\"none\"/>"
|
||||
"</svg>",
|
||||
|
||||
// UI_ICON_CHEVRON_DOWN - downward arrow
|
||||
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\">"
|
||||
"<path d=\"M7 10 L12 15 L17 10\" stroke=\"white\" stroke-width=\"2.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\" fill=\"none\"/>"
|
||||
"</svg>",
|
||||
|
||||
// UI_ICON_KNOB - filled circle with indicator line pointing up (12 o'clock)
|
||||
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\">"
|
||||
"<circle cx=\"12\" cy=\"12\" r=\"10\" fill=\"white\" opacity=\"0.25\"/>"
|
||||
"<line x1=\"12\" y1=\"12\" x2=\"12\" y2=\"3\" stroke=\"white\" stroke-width=\"2.5\" stroke-linecap=\"round\"/>"
|
||||
"</svg>",
|
||||
|
||||
// UI_ICON_SLIDER_THUMB - solid body with grip ridges
|
||||
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\">"
|
||||
"<rect x=\"2\" y=\"1\" width=\"20\" height=\"22\" rx=\"4\" fill=\"white\"/>"
|
||||
"<line x1=\"6\" y1=\"8\" x2=\"18\" y2=\"8\" stroke=\"black\" stroke-width=\"1.2\" opacity=\"0.3\"/>"
|
||||
"<line x1=\"6\" y1=\"11\" x2=\"18\" y2=\"11\" stroke=\"black\" stroke-width=\"1.2\" opacity=\"0.3\"/>"
|
||||
"<line x1=\"6\" y1=\"14\" x2=\"18\" y2=\"14\" stroke=\"black\" stroke-width=\"1.2\" opacity=\"0.3\"/>"
|
||||
"<line x1=\"6\" y1=\"17\" x2=\"18\" y2=\"17\" stroke=\"black\" stroke-width=\"1.2\" opacity=\"0.3\"/>"
|
||||
"</svg>",
|
||||
|
||||
// UI_ICON_FADER - exact asset fader cap from assets/fader.svg
|
||||
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"847 488 62.2 129.3\">"
|
||||
" <defs>"
|
||||
" <linearGradient id=\"linearGradient7718\" y2=\"528.75\" gradientUnits=\"userSpaceOnUse\" x2=\"87.866\" gradientTransform=\"matrix(1.0278,0,0,1,787.52,-27.904)\" y1=\"516.83\" x1=\"87.866\">"
|
||||
" <stop style=\"stop-color:#999999\" offset=\"0\"/>"
|
||||
" <stop style=\"stop-color:#999999;stop-opacity:0\" offset=\"1\"/>"
|
||||
" </linearGradient>"
|
||||
" <linearGradient id=\"linearGradient7720\" y2=\"499.1\" gradientUnits=\"userSpaceOnUse\" x2=\"618.49\" gradientTransform=\"matrix(1.0235,0,0,1,242.38,-1008.6)\" y1=\"496.57\" x1=\"618.49\">"
|
||||
" <stop style=\"stop-color:#cccccc\" offset=\"0\"/>"
|
||||
" <stop style=\"stop-color:#cccccc;stop-opacity:0\" offset=\"1\"/>"
|
||||
" </linearGradient>"
|
||||
" <linearGradient id=\"linearGradient7722\" y2=\"499.1\" gradientUnits=\"userSpaceOnUse\" x2=\"618.49\" gradientTransform=\"matrix(1,0,0,0.50643,256.46,265.42)\" y1=\"496.57\" x1=\"618.49\">"
|
||||
" <stop style=\"stop-color:#cccccc\" offset=\"0\"/>"
|
||||
" <stop style=\"stop-color:#cccccc;stop-opacity:0\" offset=\"1\"/>"
|
||||
" </linearGradient>"
|
||||
" <linearGradient id=\"linearGradient7724\" y2=\"499.1\" gradientUnits=\"userSpaceOnUse\" x2=\"618.49\" gradientTransform=\"matrix(1,0,0,0.42746,256.46,317.38)\" y1=\"496.57\" x1=\"618.49\">"
|
||||
" <stop style=\"stop-color:#cccccc\" offset=\"0\"/>"
|
||||
" <stop style=\"stop-color:#cccccc;stop-opacity:0\" offset=\"1\"/>"
|
||||
" </linearGradient>"
|
||||
" <linearGradient id=\"linearGradient7726\" y2=\"499.1\" gradientUnits=\"userSpaceOnUse\" x2=\"618.49\" gradientTransform=\"matrix(1,0,0,0.26952,256.46,405.1)\" y1=\"496.57\" x1=\"618.49\">"
|
||||
" <stop style=\"stop-color:#cccccc\" offset=\"0\"/>"
|
||||
" <stop style=\"stop-color:#cccccc;stop-opacity:0\" offset=\"1\"/>"
|
||||
" </linearGradient>"
|
||||
" <linearGradient id=\"linearGradient7728\" y2=\"521.42\" gradientUnits=\"userSpaceOnUse\" x2=\"87.866\" gradientTransform=\"matrix(1.0364,0,0,0.96441,786.64,-1114.5)\" y1=\"516.83\" x1=\"87.866\">"
|
||||
" <stop style=\"stop-color:#999999\" offset=\"0\"/>"
|
||||
" <stop style=\"stop-color:#333333\" offset=\"1\"/>"
|
||||
" </linearGradient>"
|
||||
" <linearGradient id=\"linearGradient7730\" y2=\"499.1\" gradientUnits=\"userSpaceOnUse\" x2=\"618.49\" gradientTransform=\"matrix(1.0364,0,0,0.96441,234.39,-1076.7)\" y1=\"496.57\" x1=\"618.49\">"
|
||||
" <stop style=\"stop-color:#cccccc\" offset=\"0\"/>"
|
||||
" <stop style=\"stop-color:#cccccc;stop-opacity:0\" offset=\"1\"/>"
|
||||
" </linearGradient>"
|
||||
" <linearGradient id=\"linearGradient7732\" y2=\"499.1\" gradientUnits=\"userSpaceOnUse\" x2=\"618.49\" gradientTransform=\"matrix(1.0274,0,0,0.48841,240.25,-833.5)\" y1=\"496.57\" x1=\"618.49\">"
|
||||
" <stop style=\"stop-color:#cccccc\" offset=\"0\"/>"
|
||||
" <stop style=\"stop-color:#cccccc;stop-opacity:0\" offset=\"1\"/>"
|
||||
" </linearGradient>"
|
||||
" <linearGradient id=\"linearGradient7734\" y2=\"499.1\" gradientUnits=\"userSpaceOnUse\" x2=\"618.49\" gradientTransform=\"matrix(1.0213,0,0,0.41225,243.85,-783.64)\" y1=\"496.57\" x1=\"618.49\">"
|
||||
" <stop style=\"stop-color:#cccccc\" offset=\"0\"/>"
|
||||
" <stop style=\"stop-color:#cccccc;stop-opacity:0\" offset=\"1\"/>"
|
||||
" </linearGradient>"
|
||||
" <linearGradient id=\"linearGradient7736\" y2=\"499.1\" gradientUnits=\"userSpaceOnUse\" x2=\"618.49\" gradientTransform=\"matrix(1.0122,0,0,0.25993,249.26,-698.66)\" y1=\"496.57\" x1=\"618.49\">"
|
||||
" <stop style=\"stop-color:#cccccc\" offset=\"0\"/>"
|
||||
" <stop style=\"stop-color:#cccccc;stop-opacity:0\" offset=\"1\"/>"
|
||||
" </linearGradient>"
|
||||
" </defs>"
|
||||
" <rect style=\"fill:#4d4d4d\" rx=\"3\" ry=\"3\" height=\"129.29\" width=\"62.143\" y=\"488.03\" x=\"847.03\"/>"
|
||||
" <rect style=\"fill:#e6e6e6\" height=\"3.5355\" width=\"60.419\" y=\"552.42\" x=\"847.97\"/>"
|
||||
" <rect style=\"fill:url(#linearGradient7718)\" rx=\"2.148\" ry=\"2\" height=\"21.071\" width=\"60.613\" y=\"488.74\" x=\"847.72\"/>"
|
||||
" <rect style=\"fill:#333333\" height=\"10.119\" width=\"58.811\" y=\"540.26\" x=\"847.92\"/>"
|
||||
" <rect style=\"fill:#333333\" height=\"8.793\" width=\"61.133\" y=\"530.89\" x=\"847.03\"/>"
|
||||
" <rect style=\"fill:#1a1a1a\" height=\"4.546\" width=\"61.133\" y=\"512.48\" x=\"847.03\"/>"
|
||||
" <rect style=\"fill:#1a1a1a\" height=\"11.364\" width=\"61.133\" y=\"518.25\" x=\"847.03\"/>"
|
||||
" <rect style=\"fill:url(#linearGradient7720)\" rx=\"1.024\" ry=\"0.64\" transform=\"scale(1,-1)\" height=\"2.261\" width=\"60.012\" y=\"-511.76\" x=\"847.72\"/>"
|
||||
" <rect style=\"fill:url(#linearGradient7722)\" rx=\"1\" ry=\"0.324\" height=\"1.145\" width=\"58.633\" y=\"517.03\" x=\"847.89\"/>"
|
||||
" <rect style=\"fill:url(#linearGradient7724)\" rx=\"1\" ry=\"0.273\" height=\"0.967\" width=\"58.633\" y=\"529.76\" x=\"847.89\"/>"
|
||||
" <rect style=\"fill:url(#linearGradient7726)\" rx=\"1\" ry=\"0.172\" height=\"0.609\" width=\"58.633\" y=\"539.01\" x=\"847.89\"/>"
|
||||
" <rect style=\"fill:url(#linearGradient7728)\" transform=\"scale(1,-1)\" rx=\"2.166\" ry=\"1.929\" height=\"20.321\" width=\"61.118\" y=\"-616.24\" x=\"847.34\"/>"
|
||||
" <rect style=\"fill:#333333\" transform=\"scale(1,-1)\" height=\"9.759\" width=\"58.811\" y=\"-567.93\" x=\"847.92\"/>"
|
||||
" <rect style=\"fill:#666666\" transform=\"scale(1,-1)\" height=\"8.48\" width=\"61.133\" y=\"-576.96\" x=\"847.03\"/>"
|
||||
" <rect style=\"fill:#808080\" transform=\"scale(1,-1)\" height=\"4.384\" width=\"61.133\" y=\"-594.72\" x=\"847.03\"/>"
|
||||
" <rect style=\"fill:#808080\" transform=\"scale(1,-1)\" height=\"10.96\" width=\"61.133\" y=\"-589.16\" x=\"847.03\"/>"
|
||||
" <rect style=\"fill:url(#linearGradient7730)\" transform=\"scale(1,-1)\" rx=\"1.036\" ry=\"0.617\" height=\"2.181\" width=\"60.767\" y=\"-597.6\" x=\"847.34\"/>"
|
||||
" <rect style=\"fill:url(#linearGradient7732)\" transform=\"scale(1,-1)\" rx=\"1.027\" ry=\"0.312\" height=\"1.104\" width=\"60.24\" y=\"-590.84\" x=\"847.89\"/>"
|
||||
" <rect style=\"fill:url(#linearGradient7734)\" transform=\"scale(1,-1)\" rx=\"1.021\" ry=\"0.264\" height=\"0.932\" width=\"59.883\" y=\"-578.82\" x=\"847.89\"/>"
|
||||
" <rect style=\"fill:url(#linearGradient7736)\" transform=\"scale(1,-1)\" rx=\"1.012\" ry=\"0.166\" height=\"0.588\" width=\"59.347\" y=\"-569.52\" x=\"847.89\"/>"
|
||||
"</svg>",
|
||||
|
||||
// UI_ICON_TRANSPORT_REWIND - skip to start (|<<)
|
||||
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\">"
|
||||
"<rect x=\"3\" y=\"5\" width=\"2.5\" height=\"14\" rx=\"0.5\" fill=\"white\"/>"
|
||||
"<path d=\"M11 5 L11 19 L4 12 Z\" fill=\"white\"/>"
|
||||
"<path d=\"M20 5 L20 19 L13 12 Z\" fill=\"white\"/>"
|
||||
"</svg>",
|
||||
|
||||
// UI_ICON_TRANSPORT_STOP - filled square
|
||||
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\">"
|
||||
"<rect x=\"5\" y=\"5\" width=\"14\" height=\"14\" rx=\"1.5\" fill=\"white\"/>"
|
||||
"</svg>",
|
||||
|
||||
// UI_ICON_TRANSPORT_PLAY - right-pointing triangle
|
||||
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\">"
|
||||
"<path d=\"M6 4 L6 20 L20 12 Z\" fill=\"white\"/>"
|
||||
"</svg>",
|
||||
|
||||
// UI_ICON_TRANSPORT_RECORD - filled circle
|
||||
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\">"
|
||||
"<circle cx=\"12\" cy=\"12\" r=\"8\" fill=\"white\"/>"
|
||||
"</svg>",
|
||||
|
||||
// UI_ICON_POP_OUT - box with arrow pointing out (top-right)
|
||||
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\">"
|
||||
"<rect x=\"3\" y=\"6\" width=\"14\" height=\"14\" rx=\"2\" stroke=\"white\" stroke-width=\"2\" fill=\"none\"/>"
|
||||
"<path d=\"M14 3 L21 3 L21 10\" stroke=\"white\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" fill=\"none\"/>"
|
||||
"<path d=\"M21 3 L12 12\" stroke=\"white\" stroke-width=\"2\" stroke-linecap=\"round\"/>"
|
||||
"</svg>",
|
||||
|
||||
// UI_ICON_POP_IN - arrow pointing into a box (bottom-left)
|
||||
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\">"
|
||||
"<rect x=\"3\" y=\"6\" width=\"14\" height=\"14\" rx=\"2\" stroke=\"white\" stroke-width=\"2\" fill=\"none\"/>"
|
||||
"<path d=\"M21 3 L12 12\" stroke=\"white\" stroke-width=\"2\" stroke-linecap=\"round\"/>"
|
||||
"<path d=\"M12 5 L12 12 L19 12\" stroke=\"white\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" fill=\"none\"/>"
|
||||
"</svg>",
|
||||
};
|
||||
|
||||
U8 *ui_icons_rasterize_atlas(S32 *out_w, S32 *out_h, S32 icon_size) {
|
||||
// Pack icons in a row
|
||||
S32 atlas_w = icon_size * UI_ICON_COUNT;
|
||||
S32 atlas_h = icon_size;
|
||||
|
||||
// Pad to power of 2 isn't necessary for correctness, but ensure minimum size
|
||||
if (atlas_w < 64) atlas_w = 64;
|
||||
if (atlas_h < 64) atlas_h = 64;
|
||||
|
||||
U8 *atlas = (U8 *)calloc(atlas_w * atlas_h * 4, 1);
|
||||
if (!atlas) return NULL;
|
||||
|
||||
NSVGrasterizer *rast = nsvgCreateRasterizer();
|
||||
if (!rast) { free(atlas); return NULL; }
|
||||
|
||||
S32 pen_x = 0;
|
||||
for (S32 i = 0; i < UI_ICON_COUNT; i++) {
|
||||
// nanosvg modifies the input string, so we need a mutable copy
|
||||
U64 svg_len = strlen(g_icon_svgs[i]);
|
||||
char *svg_copy = (char *)malloc(svg_len + 1);
|
||||
memcpy(svg_copy, g_icon_svgs[i], svg_len + 1);
|
||||
|
||||
NSVGimage *image = nsvgParse(svg_copy, "px", 96.0f);
|
||||
free(svg_copy);
|
||||
if (!image) continue;
|
||||
|
||||
// Calculate scale to fit icon_size
|
||||
F32 scale_x = (F32)icon_size / image->width;
|
||||
F32 scale_y = (F32)icon_size / image->height;
|
||||
F32 scale = scale_x < scale_y ? scale_x : scale_y;
|
||||
|
||||
// Rasterize to a temporary RGBA buffer
|
||||
U8 *tmp = (U8 *)calloc(icon_size * icon_size * 4, 1);
|
||||
if (tmp) {
|
||||
nsvgRasterize(rast, image, 0, 0, scale, tmp, icon_size, icon_size, icon_size * 4);
|
||||
|
||||
// Copy into atlas (nanosvg outputs RGBA, which is what we want)
|
||||
for (S32 y = 0; y < icon_size && y < atlas_h; y++) {
|
||||
for (S32 x = 0; x < icon_size && (pen_x + x) < atlas_w; x++) {
|
||||
S32 src_idx = (y * icon_size + x) * 4;
|
||||
S32 dst_idx = (y * atlas_w + pen_x + x) * 4;
|
||||
atlas[dst_idx + 0] = tmp[src_idx + 0];
|
||||
atlas[dst_idx + 1] = tmp[src_idx + 1];
|
||||
atlas[dst_idx + 2] = tmp[src_idx + 2];
|
||||
atlas[dst_idx + 3] = tmp[src_idx + 3];
|
||||
}
|
||||
}
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
S32 bmp_w = icon_size;
|
||||
S32 bmp_h = icon_size;
|
||||
|
||||
// Store UV and pixel info
|
||||
g_icons[i].u0 = (F32)pen_x / (F32)atlas_w;
|
||||
g_icons[i].v0 = 0.0f;
|
||||
g_icons[i].u1 = (F32)(pen_x + bmp_w) / (F32)atlas_w;
|
||||
g_icons[i].v1 = (F32)bmp_h / (F32)atlas_h;
|
||||
g_icons[i].w = (F32)bmp_w;
|
||||
g_icons[i].h = (F32)bmp_h;
|
||||
|
||||
pen_x += icon_size;
|
||||
nsvgDelete(image);
|
||||
}
|
||||
|
||||
nsvgDeleteRasterizer(rast);
|
||||
|
||||
*out_w = atlas_w;
|
||||
*out_h = atlas_h;
|
||||
return atlas;
|
||||
}
|
||||
32
src/ui/ui_icons.h
Normal file
32
src/ui/ui_icons.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
// ui_icons.h - SVG icon definitions and atlas rasterization via nanosvg
|
||||
|
||||
#include "base/base_inc.h"
|
||||
|
||||
typedef enum UI_IconID {
|
||||
UI_ICON_CLOSE,
|
||||
UI_ICON_CHECK,
|
||||
UI_ICON_CHEVRON_DOWN,
|
||||
UI_ICON_KNOB,
|
||||
UI_ICON_SLIDER_THUMB,
|
||||
UI_ICON_FADER,
|
||||
UI_ICON_TRANSPORT_REWIND,
|
||||
UI_ICON_TRANSPORT_STOP,
|
||||
UI_ICON_TRANSPORT_PLAY,
|
||||
UI_ICON_TRANSPORT_RECORD,
|
||||
UI_ICON_POP_OUT,
|
||||
UI_ICON_POP_IN,
|
||||
UI_ICON_COUNT
|
||||
} UI_IconID;
|
||||
|
||||
typedef struct UI_IconInfo {
|
||||
F32 u0, v0, u1, v1; // UV coordinates in icon atlas
|
||||
F32 w, h; // pixel dimensions at rasterized size
|
||||
} UI_IconInfo;
|
||||
|
||||
extern UI_IconInfo g_icons[UI_ICON_COUNT];
|
||||
|
||||
// Rasterizes all icons into an RGBA8 atlas bitmap (4 bytes per pixel).
|
||||
// Returns malloc'd data (caller frees). Sets *out_w, *out_h to atlas dimensions.
|
||||
// icon_size is the pixel height to rasterize each icon at.
|
||||
U8 *ui_icons_rasterize_atlas(S32 *out_w, S32 *out_h, S32 icon_size);
|
||||
136
src/ui/ui_piano.c
Normal file
136
src/ui/ui_piano.c
Normal file
@@ -0,0 +1,136 @@
|
||||
#include "ui/ui_piano.h"
|
||||
|
||||
#define PIANO_BLACK_W 11.0f
|
||||
#define PIANO_BLACK_H_PCT 0.6f
|
||||
|
||||
B32 piano_is_black_key(S32 note) {
|
||||
S32 n = note % 12;
|
||||
return n == 1 || n == 3 || n == 6 || n == 8 || n == 10;
|
||||
}
|
||||
|
||||
// Velocity-based color: blue (vel 0) → green (mid) → red (vel 127)
|
||||
Clay_Color piano_velocity_color(S32 velocity) {
|
||||
F32 t = (F32)velocity / 127.0f;
|
||||
F32 r, g, b;
|
||||
if (t < 0.5f) {
|
||||
F32 s = t * 2.0f;
|
||||
r = 40.0f + s * (76.0f - 40.0f);
|
||||
g = 120.0f + s * (175.0f - 120.0f);
|
||||
b = 220.0f + s * (80.0f - 220.0f);
|
||||
} else {
|
||||
F32 s = (t - 0.5f) * 2.0f;
|
||||
r = 76.0f + s * (220.0f - 76.0f);
|
||||
g = 175.0f + s * (50.0f - 175.0f);
|
||||
b = 80.0f + s * (40.0f - 80.0f);
|
||||
}
|
||||
return (Clay_Color){r, g, b, 255};
|
||||
}
|
||||
|
||||
void ui_piano(UI_PianoState *state, MidiEngine *midi, F32 avail_w, F32 avail_h) {
|
||||
Clay_ElementId piano_id = CLAY_ID("PianoContainer");
|
||||
CLAY(piano_id,
|
||||
.layout = {
|
||||
.sizing = { .width = CLAY_SIZING_GROW(), .height = CLAY_SIZING_GROW() },
|
||||
.layoutDirection = CLAY_LEFT_TO_RIGHT,
|
||||
}
|
||||
) {
|
||||
// Compute black key size proportional to white keys
|
||||
F32 black_key_h = avail_h * PIANO_BLACK_H_PCT;
|
||||
if (black_key_h < uis(20)) black_key_h = uis(20);
|
||||
|
||||
F32 white_key_w = avail_w / 52.0f;
|
||||
F32 black_key_w = white_key_w * 0.6f;
|
||||
if (black_key_w < uis(8)) black_key_w = uis(8);
|
||||
|
||||
// White keys (grow to fill width and height)
|
||||
for (S32 note = PIANO_FIRST_NOTE; note <= PIANO_LAST_NOTE; note++) {
|
||||
if (piano_is_black_key(note)) continue;
|
||||
|
||||
B32 midi_held = midi_is_note_held(midi, note);
|
||||
B32 mouse_held = state->mouse_note == note;
|
||||
Clay_Color bg;
|
||||
if (midi_held) {
|
||||
bg = piano_velocity_color(midi_get_note_velocity(midi, note));
|
||||
} else if (mouse_held) {
|
||||
bg = g_theme.accent;
|
||||
} else {
|
||||
bg = (Clay_Color){240, 240, 240, 255};
|
||||
}
|
||||
|
||||
CLAY(CLAY_IDI("PKey", note),
|
||||
.layout = {
|
||||
.sizing = { .width = CLAY_SIZING_GROW(), .height = CLAY_SIZING_GROW() },
|
||||
},
|
||||
.backgroundColor = bg,
|
||||
.border = { .color = {190, 190, 190, 255}, .width = { .right = 1 } },
|
||||
) {}
|
||||
}
|
||||
|
||||
// Black keys (floating, attached to left white key)
|
||||
for (S32 note = PIANO_FIRST_NOTE; note <= PIANO_LAST_NOTE; note++) {
|
||||
if (!piano_is_black_key(note)) continue;
|
||||
|
||||
Clay_ElementId parent_wkey = CLAY_IDI("PKey", note - 1);
|
||||
B32 midi_held = midi_is_note_held(midi, note);
|
||||
B32 mouse_held = state->mouse_note == note;
|
||||
Clay_Color bg;
|
||||
if (midi_held) {
|
||||
bg = piano_velocity_color(midi_get_note_velocity(midi, note));
|
||||
} else if (mouse_held) {
|
||||
bg = g_theme.accent;
|
||||
} else {
|
||||
bg = (Clay_Color){25, 25, 30, 255};
|
||||
}
|
||||
|
||||
CLAY(CLAY_IDI("PKey", note),
|
||||
.layout = {
|
||||
.sizing = {
|
||||
.width = CLAY_SIZING_FIXED(black_key_w),
|
||||
.height = CLAY_SIZING_FIXED(black_key_h),
|
||||
},
|
||||
},
|
||||
.backgroundColor = bg,
|
||||
.cornerRadius = { .topLeft = 0, .topRight = 0, .bottomLeft = uis(2), .bottomRight = uis(2) },
|
||||
.floating = {
|
||||
.parentId = parent_wkey.id,
|
||||
.zIndex = 100,
|
||||
.attachPoints = {
|
||||
.element = CLAY_ATTACH_POINT_CENTER_TOP,
|
||||
.parent = CLAY_ATTACH_POINT_RIGHT_TOP,
|
||||
},
|
||||
.attachTo = CLAY_ATTACH_TO_ELEMENT_WITH_ID,
|
||||
},
|
||||
) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ui_piano_update_input(UI_PianoState *state) {
|
||||
PlatformInput input = g_wstate.input;
|
||||
|
||||
if (!input.mouse_down) {
|
||||
state->mouse_note = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
// Find hovered piano key — check black keys first (they're on top)
|
||||
S32 hovered_note = -1;
|
||||
for (S32 note = PIANO_FIRST_NOTE; note <= PIANO_LAST_NOTE; note++) {
|
||||
if (piano_is_black_key(note) && Clay_PointerOver(CLAY_IDI("PKey", note))) {
|
||||
hovered_note = note;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hovered_note == -1) {
|
||||
for (S32 note = PIANO_FIRST_NOTE; note <= PIANO_LAST_NOTE; note++) {
|
||||
if (!piano_is_black_key(note) && Clay_PointerOver(CLAY_IDI("PKey", note))) {
|
||||
hovered_note = note;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hovered_note != -1) {
|
||||
state->mouse_note = hovered_note;
|
||||
}
|
||||
}
|
||||
20
src/ui/ui_piano.h
Normal file
20
src/ui/ui_piano.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include "ui/ui_core.h"
|
||||
#include "midi/midi.h"
|
||||
|
||||
#define PIANO_FIRST_NOTE 21 // A0
|
||||
#define PIANO_LAST_NOTE 108 // C8
|
||||
|
||||
typedef struct UI_PianoState {
|
||||
S32 mouse_note; // MIDI note held by mouse click (-1 = none)
|
||||
} UI_PianoState;
|
||||
|
||||
B32 piano_is_black_key(S32 note);
|
||||
Clay_Color piano_velocity_color(S32 velocity);
|
||||
|
||||
// Render the 88-key piano widget.
|
||||
// avail_w: total width for key layout, avail_h: total height for keys
|
||||
void ui_piano(UI_PianoState *state, MidiEngine *midi, F32 avail_w, F32 avail_h);
|
||||
|
||||
// Update piano mouse input (call after Clay layout is computed)
|
||||
void ui_piano_update_input(UI_PianoState *state);
|
||||
167
src/ui/ui_popups.c
Normal file
167
src/ui/ui_popups.c
Normal file
@@ -0,0 +1,167 @@
|
||||
#include "ui/ui_popups.h"
|
||||
|
||||
static PopupWindow g_popups[MAX_POPUP_WINDOWS];
|
||||
|
||||
static void popup_frame_callback(void *user_data) {
|
||||
PopupWindow *popup = (PopupWindow *)user_data;
|
||||
if (popup && popup->alive)
|
||||
popup_do_frame(popup, 1.0f / 60.0f);
|
||||
}
|
||||
|
||||
PopupWindow *popup_find_by_flag(B32 *flag) {
|
||||
for (S32 i = 0; i < MAX_POPUP_WINDOWS; i++)
|
||||
if (g_popups[i].alive && g_popups[i].open_flag == flag)
|
||||
return &g_popups[i];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PopupWindow *popup_open(PlatformWindow *parent_window, Renderer *parent_renderer,
|
||||
const char *title, B32 *open_flag,
|
||||
S32 width, S32 height,
|
||||
UI_WindowContentFn content_fn, void *user_data,
|
||||
PlatformWindowStyle style, B32 independent) {
|
||||
// Find free slot
|
||||
PopupWindow *popup = NULL;
|
||||
for (S32 i = 0; i < MAX_POPUP_WINDOWS; i++) {
|
||||
if (!g_popups[i].alive) { popup = &g_popups[i]; break; }
|
||||
}
|
||||
if (!popup) return NULL;
|
||||
|
||||
memset(popup, 0, sizeof(*popup));
|
||||
|
||||
// Create native popup window
|
||||
PlatformWindowDesc desc = {0};
|
||||
desc.title = title;
|
||||
desc.width = width;
|
||||
desc.height = height;
|
||||
desc.style = style;
|
||||
desc.parent = parent_window;
|
||||
desc.independent = independent;
|
||||
popup->platform_window = platform_create_window(&desc);
|
||||
if (!popup->platform_window) return NULL;
|
||||
|
||||
// Create shared renderer
|
||||
S32 pw, ph;
|
||||
platform_get_size(popup->platform_window, &pw, &ph);
|
||||
|
||||
RendererDesc rdesc = {0};
|
||||
rdesc.window_handle = platform_get_native_handle(popup->platform_window);
|
||||
rdesc.width = pw;
|
||||
rdesc.height = ph;
|
||||
popup->renderer = renderer_create_shared(parent_renderer, &rdesc);
|
||||
if (!popup->renderer) {
|
||||
platform_destroy_window(popup->platform_window);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Create UI context
|
||||
popup->ui_ctx = ui_create((F32)pw, (F32)ph);
|
||||
ui_set_measure_text_fn(popup->ui_ctx, renderer_measure_text, popup->renderer);
|
||||
|
||||
popup->alive = 1;
|
||||
popup->open_flag = open_flag;
|
||||
popup->content_fn = content_fn;
|
||||
popup->content_user_data = user_data;
|
||||
popup->width = width;
|
||||
popup->height = height;
|
||||
popup->last_w = pw;
|
||||
popup->last_h = ph;
|
||||
popup->title = title;
|
||||
memset(&popup->wstate, 0, sizeof(popup->wstate));
|
||||
|
||||
platform_set_frame_callback(popup->platform_window, popup_frame_callback, popup);
|
||||
|
||||
return popup;
|
||||
}
|
||||
|
||||
void popup_close(PopupWindow *popup) {
|
||||
if (!popup || !popup->alive) return;
|
||||
|
||||
if (popup->open_flag)
|
||||
*popup->open_flag = 0;
|
||||
|
||||
popup->alive = 0;
|
||||
platform_set_frame_callback(popup->platform_window, NULL, NULL);
|
||||
|
||||
ui_destroy(popup->ui_ctx);
|
||||
renderer_destroy(popup->renderer);
|
||||
platform_destroy_window(popup->platform_window);
|
||||
}
|
||||
|
||||
void popup_do_frame(PopupWindow *popup, F32 dt) {
|
||||
if (!popup->alive) return;
|
||||
|
||||
// Check window size
|
||||
S32 w, h;
|
||||
platform_get_size(popup->platform_window, &w, &h);
|
||||
if (w != popup->last_w || h != popup->last_h) {
|
||||
renderer_resize(popup->renderer, w, h);
|
||||
popup->last_w = w;
|
||||
popup->last_h = h;
|
||||
}
|
||||
|
||||
if (!renderer_begin_frame(popup->renderer))
|
||||
return;
|
||||
|
||||
// Gather input from popup window
|
||||
PlatformInput input = platform_get_input(popup->platform_window);
|
||||
|
||||
// Handle Cmd+/- zoom (propagate to global scale)
|
||||
for (S32 k = 0; k < input.key_count; k++) {
|
||||
if (input.ctrl_held) {
|
||||
if (input.keys[k] == PKEY_EQUAL) g_ui_scale *= 1.1f;
|
||||
if (input.keys[k] == PKEY_MINUS) g_ui_scale /= 1.1f;
|
||||
if (input.keys[k] == PKEY_0) g_ui_scale = 1.0f;
|
||||
}
|
||||
}
|
||||
g_ui_scale = Clamp(0.5f, g_ui_scale, 3.0f);
|
||||
|
||||
// Sync shared font atlas from parent renderer (picks up zoom changes)
|
||||
renderer_sync_from_parent(popup->renderer);
|
||||
|
||||
// Swap widget state
|
||||
UI_WidgetState saved_wstate = g_wstate;
|
||||
g_wstate = popup->wstate;
|
||||
|
||||
ui_widgets_begin_frame(input);
|
||||
|
||||
// Build UI
|
||||
ui_begin_frame(popup->ui_ctx, (F32)w, (F32)h, input.mouse_pos, input.mouse_down,
|
||||
input.scroll_delta, dt);
|
||||
|
||||
// Background fill
|
||||
CLAY(CLAY_ID("PopupBg"),
|
||||
.layout = {
|
||||
.sizing = { .width = CLAY_SIZING_GROW(), .height = CLAY_SIZING_GROW() },
|
||||
.padding = { uip(12), uip(12), uip(10), uip(10) },
|
||||
.childGap = uip(8),
|
||||
.layoutDirection = CLAY_TOP_TO_BOTTOM,
|
||||
},
|
||||
.backgroundColor = g_theme.bg_medium,
|
||||
) {
|
||||
if (popup->content_fn) {
|
||||
popup->content_fn(popup->content_user_data);
|
||||
}
|
||||
}
|
||||
|
||||
Clay_RenderCommandArray render_commands = ui_end_frame(popup->ui_ctx);
|
||||
|
||||
// Save widget state back
|
||||
popup->wstate = g_wstate;
|
||||
g_wstate = saved_wstate;
|
||||
|
||||
// Render
|
||||
renderer_end_frame(popup->renderer, &render_commands);
|
||||
}
|
||||
|
||||
void popup_close_all(void) {
|
||||
for (S32 i = 0; i < MAX_POPUP_WINDOWS; i++)
|
||||
if (g_popups[i].alive) popup_close(&g_popups[i]);
|
||||
}
|
||||
|
||||
void popup_close_check(void) {
|
||||
for (S32 i = 0; i < MAX_POPUP_WINDOWS; i++) {
|
||||
if (g_popups[i].alive && platform_window_should_close(g_popups[i].platform_window))
|
||||
popup_close(&g_popups[i]);
|
||||
}
|
||||
}
|
||||
33
src/ui/ui_popups.h
Normal file
33
src/ui/ui_popups.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
#include "ui/ui_core.h"
|
||||
#include "ui/ui_widgets.h"
|
||||
#include "platform/platform.h"
|
||||
#include "renderer/renderer.h"
|
||||
|
||||
#define MAX_POPUP_WINDOWS 4
|
||||
|
||||
typedef struct PopupWindow {
|
||||
B32 alive;
|
||||
B32 *open_flag; // e.g. &app->show_settings_window
|
||||
PlatformWindow *platform_window;
|
||||
Renderer *renderer;
|
||||
UI_Context *ui_ctx;
|
||||
UI_WidgetState wstate;
|
||||
UI_WindowContentFn content_fn;
|
||||
void *content_user_data;
|
||||
S32 width, height;
|
||||
S32 last_w, last_h;
|
||||
const char *title;
|
||||
} PopupWindow;
|
||||
|
||||
PopupWindow *popup_open(PlatformWindow *parent_window, Renderer *parent_renderer,
|
||||
const char *title, B32 *open_flag,
|
||||
S32 width, S32 height,
|
||||
UI_WindowContentFn content_fn, void *user_data,
|
||||
PlatformWindowStyle style,
|
||||
B32 independent);
|
||||
void popup_close(PopupWindow *popup);
|
||||
PopupWindow *popup_find_by_flag(B32 *flag);
|
||||
void popup_do_frame(PopupWindow *popup, F32 dt);
|
||||
void popup_close_all(void);
|
||||
void popup_close_check(void);
|
||||
2194
src/ui/ui_widgets.c
Normal file
2194
src/ui/ui_widgets.c
Normal file
File diff suppressed because it is too large
Load Diff
152
src/ui/ui_widgets.h
Normal file
152
src/ui/ui_widgets.h
Normal file
@@ -0,0 +1,152 @@
|
||||
#pragma once
|
||||
// ui_widgets.h - Immediate-mode widgets built on top of Clay.
|
||||
//
|
||||
// Each widget function takes a unique string ID, the value to display/edit,
|
||||
// and returns whether the value was changed (or the widget was activated).
|
||||
// The caller owns all data — the widget layer only stores transient UI state
|
||||
// like which text field is focused or which dropdown is open.
|
||||
|
||||
#include "ui/ui_core.h"
|
||||
#include "ui/ui_icons.h"
|
||||
#include "platform/platform.h"
|
||||
|
||||
////////////////////////////////
|
||||
// Widget state (global, managed by widget layer)
|
||||
|
||||
#define UI_WIDGET_MAX_DROPDOWN_ITEMS 32
|
||||
#define UI_WIDGET_MAX_TEXT_INPUTS 16
|
||||
|
||||
typedef struct UI_KnobDragState {
|
||||
U32 dragging_id; // Hash of the knob being dragged (0 = none)
|
||||
F32 drag_start_y; // Mouse Y when drag started
|
||||
F32 drag_start_x; // Mouse X when drag started (for h-slider)
|
||||
F32 value_at_start; // Value when drag started
|
||||
B32 was_shift; // Shift state last frame (to re-anchor on change)
|
||||
U32 last_click_id; // Knob hash of last click (for F64-click detection)
|
||||
S32 last_click_frame; // Frame number of last click
|
||||
} UI_KnobDragState;
|
||||
|
||||
typedef struct UI_WidgetState {
|
||||
// Text input focus
|
||||
U32 focused_id; // Clay element ID hash of the focused text input (0 = none)
|
||||
S32 cursor_pos; // Cursor position in focused text input
|
||||
F32 cursor_blink; // Blink timer (seconds)
|
||||
|
||||
// Text selection (sel_start == sel_end means no selection)
|
||||
S32 sel_start; // Selection anchor (where selection began)
|
||||
S32 sel_end; // Selection extent (moves with cursor)
|
||||
|
||||
// Tab cycling: registered text input IDs in order of declaration
|
||||
U32 text_input_ids[UI_WIDGET_MAX_TEXT_INPUTS];
|
||||
S32 text_input_count;
|
||||
B32 tab_pressed; // True on the frame Tab was pressed
|
||||
|
||||
// Dropdown
|
||||
U32 open_dropdown_id; // Clay element ID hash of the open dropdown (0 = none)
|
||||
|
||||
// Input for this frame
|
||||
PlatformInput input;
|
||||
|
||||
// Click detection
|
||||
B32 mouse_clicked; // true on the frame mouse transitions from up->down
|
||||
|
||||
// Knob drag state
|
||||
UI_KnobDragState knob_drag;
|
||||
|
||||
// Knob text edit state
|
||||
U32 knob_edit_id; // Hash of knob in text edit mode (0 = none)
|
||||
char knob_edit_buf[32]; // Text buffer for numeric entry
|
||||
S32 knob_edit_cursor; // Cursor position in edit buffer
|
||||
S32 knob_edit_sel_start; // Selection anchor
|
||||
S32 knob_edit_sel_end; // Selection extent
|
||||
} UI_WidgetState;
|
||||
|
||||
extern UI_WidgetState g_wstate;
|
||||
|
||||
// Call once at startup
|
||||
void ui_widgets_init();
|
||||
|
||||
// Call each frame before building widgets. Pass in the frame's input.
|
||||
void ui_widgets_begin_frame(PlatformInput input);
|
||||
|
||||
// Call after changing theme to force text config refresh
|
||||
void ui_widgets_theme_changed();
|
||||
|
||||
// Reset per-frame text input display buffer allocator (called by begin_frame, but
|
||||
// can also be called manually if needed)
|
||||
void ui_text_input_reset_display_bufs();
|
||||
|
||||
////////////////////////////////
|
||||
// Widgets
|
||||
// All IDs must be unique string literals (passed to CLAY_ID internally).
|
||||
|
||||
// Icon element (rendered via icon atlas)
|
||||
void ui_icon(UI_IconID icon, F32 size, Clay_Color color);
|
||||
|
||||
// Simple label
|
||||
void ui_label(const char *id, const char *text);
|
||||
|
||||
// Clickable button. Returns true on the frame it was clicked.
|
||||
B32 ui_button(const char *id, const char *text);
|
||||
|
||||
// Checkbox. Toggles *value on click. Returns true if value changed.
|
||||
B32 ui_checkbox(const char *id, const char *label, B32 *value);
|
||||
|
||||
// Radio button group. Sets *selected to the clicked index. Returns true if changed.
|
||||
// options is an array of label strings, count is the number of options.
|
||||
B32 ui_radio_group(const char *id, const char **options, S32 count, S32 *selected);
|
||||
|
||||
// Single-line text input. Edits buf in-place (null-terminated, max buf_size-1 chars).
|
||||
// Returns true if the text changed this frame.
|
||||
B32 ui_text_input(const char *id, char *buf, S32 buf_size);
|
||||
|
||||
// Dropdown / combo box. Sets *selected to chosen index. Returns true if changed.
|
||||
// options is an array of label strings, count is the number of options.
|
||||
B32 ui_dropdown(const char *id, const char **options, S32 count, S32 *selected);
|
||||
|
||||
// Tab bar. Renders a row of tabs with active/inactive states.
|
||||
// Returns the currently selected index. Clicking an inactive tab updates *selected.
|
||||
S32 ui_tab_bar(const char *id, const char **labels, S32 count, S32 *selected);
|
||||
|
||||
// Content function type (used by popup windows)
|
||||
typedef void (*UI_WindowContentFn)(void *user_data);
|
||||
|
||||
// Knob / potentiometer. Vertical drag to change value.
|
||||
// unsigned (is_signed=0): value in [0, max_val]
|
||||
// signed (is_signed=1): value in [-max_val, +max_val]
|
||||
// default_val: value restored on F64-click.
|
||||
// editable: if true, clicking the value text opens a text input for direct entry.
|
||||
// Hold Shift while dragging for fine control.
|
||||
// Returns true if value changed this frame.
|
||||
B32 ui_knob(const char *id, const char *label, F32 *value, F32 max_val, B32 is_signed, F32 default_val, B32 editable);
|
||||
|
||||
// Horizontal slider. Drag left/right to change value.
|
||||
B32 ui_slider_h(const char *id, const char *label, F32 *value, F32 max_val, B32 is_signed, F32 default_val, B32 editable);
|
||||
|
||||
// Vertical slider. Drag up/down to change value.
|
||||
B32 ui_slider_v(const char *id, const char *label, F32 *value, F32 max_val, B32 is_signed, F32 default_val, B32 editable);
|
||||
|
||||
// DAW-style fader (vertical slider with fader cap icon).
|
||||
B32 ui_fader(const char *id, const char *label, F32 *value, F32 max_val, B32 is_signed, F32 default_val, B32 editable);
|
||||
|
||||
////////////////////////////////
|
||||
// Scrollable area with custom scrollbar
|
||||
//
|
||||
// Usage:
|
||||
// UI_ScrollState scroll = {0}; // persist across frames
|
||||
// ui_scroll_begin("MyScroll", &scroll);
|
||||
// /* ... scrollable content ... */
|
||||
// ui_scroll_end("MyScroll", &scroll);
|
||||
|
||||
typedef struct UI_ScrollState {
|
||||
B32 dragging;
|
||||
F32 drag_start_y;
|
||||
F32 drag_start_scroll;
|
||||
} UI_ScrollState;
|
||||
|
||||
// Opens a horizontal row containing a vertical-scroll content area.
|
||||
// The content area clips vertically and uses Clay_GetScrollOffset().
|
||||
void ui_scroll_begin(const char *id, UI_ScrollState *state);
|
||||
|
||||
// Closes the content area and draws the scrollbar thumb/track.
|
||||
void ui_scroll_end(const char *id, UI_ScrollState *state);
|
||||
4461
vendor/clay/clay.h
vendored
Normal file
4461
vendor/clay/clay.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
290
vendor/freetype/include/dlg/dlg.h
vendored
Normal file
290
vendor/freetype/include/dlg/dlg.h
vendored
Normal file
@@ -0,0 +1,290 @@
|
||||
// Copyright (c) 2019 nyorain
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#ifndef INC_DLG_DLG_H_
|
||||
#define INC_DLG_DLG_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// Hosted at https://github.com/nyorain/dlg.
|
||||
// There are examples and documentation.
|
||||
// Issue reports and contributions appreciated.
|
||||
|
||||
// - CONFIG -
|
||||
// Define this macro to make all dlg macros have no effect at all
|
||||
// #define DLG_DISABLE
|
||||
|
||||
// the log/assertion levels below which logs/assertions are ignored
|
||||
// defaulted depending on the NDEBUG macro
|
||||
#ifndef DLG_LOG_LEVEL
|
||||
#ifdef NDEBUG
|
||||
#define DLG_LOG_LEVEL dlg_level_warn
|
||||
#else
|
||||
#define DLG_LOG_LEVEL dlg_level_trace
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef DLG_ASSERT_LEVEL
|
||||
#ifdef NDEBUG
|
||||
#define DLG_ASSERT_LEVEL dlg_level_warn
|
||||
#else
|
||||
#define DLG_ASSERT_LEVEL dlg_level_trace
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// the assert level of dlg_assert
|
||||
#ifndef DLG_DEFAULT_ASSERT
|
||||
#define DLG_DEFAULT_ASSERT dlg_level_error
|
||||
#endif
|
||||
|
||||
// evaluated to the 'file' member in dlg_origin
|
||||
#ifndef DLG_FILE
|
||||
#define DLG_FILE dlg__strip_root_path(__FILE__, DLG_BASE_PATH)
|
||||
|
||||
// the base path stripped from __FILE__. If you don't override DLG_FILE set this to
|
||||
// the project root to make 'main.c' from '/some/bullshit/main.c'
|
||||
#ifndef DLG_BASE_PATH
|
||||
#define DLG_BASE_PATH ""
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Default tags applied to all logs/assertions (in the defining file).
|
||||
// Must be in format ```#define DLG_DEFAULT_TAGS "tag1", "tag2"```
|
||||
// or just nothing (as defaulted here)
|
||||
#ifndef DLG_DEFAULT_TAGS
|
||||
#define DLG_DEFAULT_TAGS_TERM NULL
|
||||
#else
|
||||
#define DLG_DEFAULT_TAGS_TERM DLG_DEFAULT_TAGS, NULL
|
||||
#endif
|
||||
|
||||
// The function used for formatting. Can have any signature, but must be callable with
|
||||
// the arguments the log/assertions macros are called with. Must return a const char*
|
||||
// that will not be freed by dlg, the formatting function must keep track of it.
|
||||
// The formatting function might use dlg_thread_buffer or a custom owned buffer.
|
||||
// The returned const char* has to be valid until the dlg log/assertion ends.
|
||||
// Usually a c function with ... (i.e. using va_list) or a variadic c++ template do
|
||||
// allow formatting.
|
||||
#ifndef DLG_FMT_FUNC
|
||||
#define DLG_FMT_FUNC dlg__printf_format
|
||||
#endif
|
||||
|
||||
// Only overwrite (i.e. predefine) this if you know what you are doing.
|
||||
// On windows this is used to add the dllimport specified.
|
||||
// If you are using the static version of dlg (on windows) define
|
||||
// DLG_STATIC before including dlg.h
|
||||
#ifndef DLG_API
|
||||
#if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(DLG_STATIC)
|
||||
#define DLG_API __declspec(dllimport)
|
||||
#else
|
||||
#define DLG_API
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// This macro is used when an assertion fails. It gets the source expression
|
||||
// and can return an alternative (that must stay alive).
|
||||
// Mainly useful to execute something on failed assertion.
|
||||
#ifndef DLG_FAILED_ASSERTION_TEXT
|
||||
#define DLG_FAILED_ASSERTION_TEXT(x) x
|
||||
#endif
|
||||
|
||||
// - utility -
|
||||
// two methods needed since cplusplus does not support compound literals
|
||||
// and c does not support uniform initialization/initializer lists
|
||||
#ifdef __cplusplus
|
||||
#include <initializer_list>
|
||||
#define DLG_CREATE_TAGS(...) std::initializer_list<const char*> \
|
||||
{DLG_DEFAULT_TAGS_TERM, __VA_ARGS__, NULL}.begin()
|
||||
#else
|
||||
#define DLG_CREATE_TAGS(...) (const char* const[]) {DLG_DEFAULT_TAGS_TERM, __VA_ARGS__, NULL}
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define DLG_PRINTF_ATTRIB(a, b) __attribute__ ((format (printf, a, b)))
|
||||
#else
|
||||
#define DLG_PRINTF_ATTRIB(a, b)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
// Represents the importance of a log/assertion call.
|
||||
enum dlg_level {
|
||||
dlg_level_trace = 0, // temporary used debug, e.g. to check if control reaches function
|
||||
dlg_level_debug, // general debugging, prints e.g. all major events
|
||||
dlg_level_info, // general useful information
|
||||
dlg_level_warn, // warning, something went wrong but might have no (really bad) side effect
|
||||
dlg_level_error, // something really went wrong; expect serious issues
|
||||
dlg_level_fatal // critical error; application is likely to crash/exit
|
||||
};
|
||||
|
||||
// Holds various information associated with a log/assertion call.
|
||||
// Forwarded to the output handler.
|
||||
struct dlg_origin {
|
||||
const char* file;
|
||||
unsigned int line;
|
||||
const char* func;
|
||||
enum dlg_level level;
|
||||
const char** tags; // null-terminated
|
||||
const char* expr; // assertion expression, otherwise null
|
||||
};
|
||||
|
||||
// Type of the output handler, see dlg_set_handler.
|
||||
typedef void(*dlg_handler)(const struct dlg_origin* origin, const char* string, void* data);
|
||||
|
||||
#ifndef DLG_DISABLE
|
||||
// Tagged/Untagged logging with variable level
|
||||
// Tags must always be in the format `("tag1", "tag2")` (including brackets)
|
||||
// Example usages:
|
||||
// dlg_log(dlg_level_warning, "test 1")
|
||||
// dlg_logt(("tag1, "tag2"), dlg_level_debug, "test %d", 2)
|
||||
#define dlg_log(level, ...) if(level >= DLG_LOG_LEVEL) \
|
||||
dlg__do_log(level, DLG_CREATE_TAGS(NULL), DLG_FILE, __LINE__, __func__, \
|
||||
DLG_FMT_FUNC(__VA_ARGS__), NULL)
|
||||
#define dlg_logt(level, tags, ...) if(level >= DLG_LOG_LEVEL) \
|
||||
dlg__do_log(level, DLG_CREATE_TAGS tags, DLG_FILE, __LINE__, __func__, \
|
||||
DLG_FMT_FUNC(__VA_ARGS__), NULL)
|
||||
|
||||
// Dynamic level assert macros in various versions for additional arguments
|
||||
// Example usages:
|
||||
// dlg_assertl(dlg_level_warning, data != nullptr);
|
||||
// dlg_assertlt(("tag1, "tag2"), dlg_level_trace, data != nullptr);
|
||||
// dlg_asserttlm(("tag1), dlg_level_warning, data != nullptr, "Data must not be null");
|
||||
// dlg_assertlm(dlg_level_error, data != nullptr, "Data must not be null");
|
||||
#define dlg_assertl(level, expr) if(level >= DLG_ASSERT_LEVEL && !(expr)) \
|
||||
dlg__do_log(level, DLG_CREATE_TAGS(NULL), DLG_FILE, __LINE__, __func__, NULL, \
|
||||
DLG_FAILED_ASSERTION_TEXT(#expr))
|
||||
#define dlg_assertlt(level, tags, expr) if(level >= DLG_ASSERT_LEVEL && !(expr)) \
|
||||
dlg__do_log(level, DLG_CREATE_TAGS tags, DLG_FILE, __LINE__, __func__, NULL, \
|
||||
DLG_FAILED_ASSERTION_TEXT(#expr))
|
||||
#define dlg_assertlm(level, expr, ...) if(level >= DLG_ASSERT_LEVEL && !(expr)) \
|
||||
dlg__do_log(level, DLG_CREATE_TAGS(NULL), DLG_FILE, __LINE__, __func__, \
|
||||
DLG_FMT_FUNC(__VA_ARGS__), DLG_FAILED_ASSERTION_TEXT(#expr))
|
||||
#define dlg_assertltm(level, tags, expr, ...) if(level >= DLG_ASSERT_LEVEL && !(expr)) \
|
||||
dlg__do_log(level, DLG_CREATE_TAGS tags, DLG_FILE, __LINE__, \
|
||||
__func__, DLG_FMT_FUNC(__VA_ARGS__), DLG_FAILED_ASSERTION_TEXT(#expr))
|
||||
|
||||
#define dlg__assert_or(level, tags, expr, code, msg) if(!(expr)) {\
|
||||
if(level >= DLG_ASSERT_LEVEL) \
|
||||
dlg__do_log(level, tags, DLG_FILE, __LINE__, __func__, msg, \
|
||||
DLG_FAILED_ASSERTION_TEXT(#expr)); \
|
||||
code; \
|
||||
} (void) NULL
|
||||
|
||||
// - Private interface: not part of the abi/api but needed in macros -
|
||||
// Formats the given format string and arguments as printf would, uses the thread buffer.
|
||||
DLG_API const char* dlg__printf_format(const char* format, ...) DLG_PRINTF_ATTRIB(1, 2);
|
||||
DLG_API void dlg__do_log(enum dlg_level lvl, const char* const*, const char*, int,
|
||||
const char*, const char*, const char*);
|
||||
DLG_API const char* dlg__strip_root_path(const char* file, const char* base);
|
||||
|
||||
#else // DLG_DISABLE
|
||||
|
||||
#define dlg_log(level, ...)
|
||||
#define dlg_logt(level, tags, ...)
|
||||
|
||||
#define dlg_assertl(level, expr) // assert without tags/message
|
||||
#define dlg_assertlt(level, tags, expr) // assert with tags
|
||||
#define dlg_assertlm(level, expr, ...) // assert with message
|
||||
#define dlg_assertltm(level, tags, expr, ...) // assert with tags & message
|
||||
|
||||
#define dlg__assert_or(level, tags, expr, code, msg) if(!(expr)) { code; } (void) NULL
|
||||
#endif // DLG_DISABLE
|
||||
|
||||
// The API below is independent from DLG_DISABLE
|
||||
|
||||
// Sets the handler that is responsible for formatting and outputting log calls.
|
||||
// This function is not thread safe and the handler is set globally.
|
||||
// The handler itself must not change dlg tags or call a dlg macro (if it
|
||||
// does so, the provided string or tags array in 'origin' might get invalid).
|
||||
// The handler can also be used for various other things such as dealing
|
||||
// with failed assertions or filtering calls based on the passed tags.
|
||||
// The default handler is dlg_default_output (see its doc for more info).
|
||||
// If using c++ make sure the registered handler cannot throw e.g. by
|
||||
// wrapping everything into a try-catch blog.
|
||||
DLG_API void dlg_set_handler(dlg_handler handler, void* data);
|
||||
|
||||
// The default output handler.
|
||||
// Only use this to reset the output handler, prefer to use
|
||||
// dlg_generic_output (from output.h) which this function simply calls.
|
||||
// It also flushes the stream used and correctly outputs even from multiple threads.
|
||||
DLG_API void dlg_default_output(const struct dlg_origin*, const char* string, void*);
|
||||
|
||||
// Returns the currently active dlg handler and sets `data` to
|
||||
// its user data pointer. `data` must not be NULL.
|
||||
// Useful to create handler chains.
|
||||
// This function is not threadsafe, i.e. retrieving the handler while
|
||||
// changing it from another thread is unsafe.
|
||||
// See `dlg_set_handler`.
|
||||
DLG_API dlg_handler dlg_get_handler(void** data);
|
||||
|
||||
// Adds the given tag associated with the given function to the thread specific list.
|
||||
// If func is not NULL the tag will only applied to calls from the same function.
|
||||
// Remove the tag again calling dlg_remove_tag (with exactly the same pointers!).
|
||||
// Does not check if the tag is already present.
|
||||
DLG_API void dlg_add_tag(const char* tag, const char* func);
|
||||
|
||||
// Removes a tag added with dlg_add_tag (has no effect for tags no present).
|
||||
// The pointers must be exactly the same pointers that were supplied to dlg_add_tag,
|
||||
// this function will not check using strcmp. When the same tag/func combination
|
||||
// is added multiple times, this function remove exactly one candidate, it is
|
||||
// undefined which. Returns whether a tag was found (and removed).
|
||||
DLG_API bool dlg_remove_tag(const char* tag, const char* func);
|
||||
|
||||
// Returns the thread-specific buffer and its size for dlg.
|
||||
// The buffer should only be used by formatting functions.
|
||||
// The buffer can be reallocated and the size changed, just make sure
|
||||
// to update both values correctly.
|
||||
DLG_API char** dlg_thread_buffer(size_t** size);
|
||||
|
||||
// Untagged leveled logging
|
||||
#define dlg_trace(...) dlg_log(dlg_level_trace, __VA_ARGS__)
|
||||
#define dlg_debug(...) dlg_log(dlg_level_debug, __VA_ARGS__)
|
||||
#define dlg_info(...) dlg_log(dlg_level_info, __VA_ARGS__)
|
||||
#define dlg_warn(...) dlg_log(dlg_level_warn, __VA_ARGS__)
|
||||
#define dlg_error(...) dlg_log(dlg_level_error, __VA_ARGS__)
|
||||
#define dlg_fatal(...) dlg_log(dlg_level_fatal, __VA_ARGS__)
|
||||
|
||||
// Tagged leveled logging
|
||||
#define dlg_tracet(tags, ...) dlg_logt(dlg_level_trace, tags, __VA_ARGS__)
|
||||
#define dlg_debugt(tags, ...) dlg_logt(dlg_level_debug, tags, __VA_ARGS__)
|
||||
#define dlg_infot(tags, ...) dlg_logt(dlg_level_info, tags, __VA_ARGS__)
|
||||
#define dlg_warnt(tags, ...) dlg_logt(dlg_level_warn, tags, __VA_ARGS__)
|
||||
#define dlg_errort(tags, ...) dlg_logt(dlg_level_error, tags, __VA_ARGS__)
|
||||
#define dlg_fatalt(tags, ...) dlg_logt(dlg_level_fatal, tags, __VA_ARGS__)
|
||||
|
||||
// Assert macros useing DLG_DEFAULT_ASSERT as level
|
||||
#define dlg_assert(expr) dlg_assertl(DLG_DEFAULT_ASSERT, expr)
|
||||
#define dlg_assertt(tags, expr) dlg_assertlt(DLG_DEFAULT_ASSERT, tags, expr)
|
||||
#define dlg_assertm(expr, ...) dlg_assertlm(DLG_DEFAULT_ASSERT, expr, __VA_ARGS__)
|
||||
#define dlg_asserttm(tags, expr, ...) dlg_assertltm(DLG_DEFAULT_ASSERT, tags, expr, __VA_ARGS__)
|
||||
|
||||
// If (expr) does not evaluate to true, always executes 'code' (no matter what
|
||||
// DLG_ASSERT_LEVEL is or if dlg is disabled or not).
|
||||
// When dlg is enabled and the level is greater or equal to DLG_ASSERT_LEVEL,
|
||||
// logs the failed assertion.
|
||||
// Example usages:
|
||||
// dlg_assertl_or(dlg_level_warn, data != nullptr, return);
|
||||
// dlg_assertlm_or(dlg_level_fatal, data != nullptr, return, "Data must not be null");
|
||||
// dlg_assert_or(data != nullptr, logError(); return false);
|
||||
#define dlg_assertltm_or(level, tags, expr, code, ...) dlg__assert_or(level, \
|
||||
DLG_CREATE_TAGS tags, expr, code, DLG_FMT_FUNC(__VA_ARGS__))
|
||||
#define dlg_assertlm_or(level, expr, code, ...) dlg__assert_or(level, \
|
||||
DLG_CREATE_TAGS(NULL), expr, code, DLG_FMT_FUNC(__VA_ARGS__))
|
||||
#define dlg_assertl_or(level, expr, code) dlg__assert_or(level, \
|
||||
DLG_CREATE_TAGS(NULL), expr, code, NULL)
|
||||
|
||||
#define dlg_assert_or(expr, code) dlg_assertl_or(DLG_DEFAULT_ASSERT, expr, code)
|
||||
#define dlg_assertm_or(expr, code, ...) dlg_assertlm_or(DLG_DEFAULT_ASSERT, expr, code, __VA_ARGS__)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // header guard
|
||||
172
vendor/freetype/include/dlg/output.h
vendored
Normal file
172
vendor/freetype/include/dlg/output.h
vendored
Normal file
@@ -0,0 +1,172 @@
|
||||
// Copyright (c) 2019 nyorain
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#ifndef INC_DLG_OUTPUT_H_
|
||||
#define INC_DLG_OUTPUT_H_
|
||||
|
||||
#include <dlg/dlg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Text style
|
||||
enum dlg_text_style {
|
||||
dlg_text_style_reset = 0,
|
||||
dlg_text_style_bold = 1,
|
||||
dlg_text_style_dim = 2,
|
||||
dlg_text_style_italic = 3,
|
||||
dlg_text_style_underline = 4,
|
||||
dlg_text_style_blink = 5,
|
||||
dlg_text_style_rblink = 6,
|
||||
dlg_text_style_reversed = 7,
|
||||
dlg_text_style_conceal = 8,
|
||||
dlg_text_style_crossed = 9,
|
||||
dlg_text_style_none,
|
||||
};
|
||||
|
||||
// Text color
|
||||
enum dlg_color {
|
||||
dlg_color_black = 0,
|
||||
dlg_color_red,
|
||||
dlg_color_green,
|
||||
dlg_color_yellow,
|
||||
dlg_color_blue,
|
||||
dlg_color_magenta,
|
||||
dlg_color_cyan,
|
||||
dlg_color_gray,
|
||||
dlg_color_reset = 9,
|
||||
|
||||
dlg_color_black2 = 60,
|
||||
dlg_color_red2,
|
||||
dlg_color_green2,
|
||||
dlg_color_yellow2,
|
||||
dlg_color_blue2,
|
||||
dlg_color_magenta2,
|
||||
dlg_color_cyan2,
|
||||
dlg_color_gray2,
|
||||
|
||||
dlg_color_none = 69,
|
||||
};
|
||||
|
||||
struct dlg_style {
|
||||
enum dlg_text_style style;
|
||||
enum dlg_color fg;
|
||||
enum dlg_color bg;
|
||||
};
|
||||
|
||||
// Like fprintf but fixes utf-8 output to console on windows.
|
||||
// On non-windows sytems just uses the corresponding standard library
|
||||
// functions. On windows, if dlg was compiled with the win_console option,
|
||||
// will first try to output it in a way that allows the default console
|
||||
// to display utf-8. If that fails, will fall back to the standard
|
||||
// library functions.
|
||||
DLG_API int dlg_fprintf(FILE* stream, const char* format, ...) DLG_PRINTF_ATTRIB(2, 3);
|
||||
DLG_API int dlg_vfprintf(FILE* stream, const char* format, va_list list);
|
||||
|
||||
// Like dlg_printf, but also applies the given style to this output.
|
||||
// The style will always be applied (using escape sequences), independent of the given stream.
|
||||
// On windows escape sequences don't work out of the box, see dlg_win_init_ansi().
|
||||
DLG_API int dlg_styled_fprintf(FILE* stream, struct dlg_style style,
|
||||
const char* format, ...) DLG_PRINTF_ATTRIB(3, 4);
|
||||
|
||||
// Features to output from the generic output handler.
|
||||
// Some features might have only an effect in the specializations.
|
||||
enum dlg_output_feature {
|
||||
dlg_output_tags = 1, // output tags list
|
||||
dlg_output_time = 2, // output time of log call (hour:minute:second)
|
||||
dlg_output_style = 4, // whether to use the supplied styles
|
||||
dlg_output_func = 8, // output function
|
||||
dlg_output_file_line = 16, // output file:line,
|
||||
dlg_output_newline = 32, // output a newline at the end
|
||||
dlg_output_threadsafe = 64, // locks stream before printing
|
||||
dlg_output_time_msecs = 128 // output micro seconds (ms on windows)
|
||||
};
|
||||
|
||||
// The default level-dependent output styles. The array values represent the styles
|
||||
// to be used for the associated level (i.e. [0] for trace level).
|
||||
DLG_API extern const struct dlg_style dlg_default_output_styles[6];
|
||||
|
||||
// Generic output function. Used by the default output handler and might be useful
|
||||
// for custom output handlers (that don't want to manually format the output).
|
||||
// Will call the given output func with the given data (and format + args to print)
|
||||
// for everything it has to print in printf format.
|
||||
// See also the *_stream and *_buf specializations for common usage.
|
||||
// The given output function must not be NULL.
|
||||
typedef void(*dlg_generic_output_handler)(void* data, const char* format, ...);
|
||||
DLG_API void dlg_generic_output(dlg_generic_output_handler output, void* data,
|
||||
unsigned int features, const struct dlg_origin* origin, const char* string,
|
||||
const struct dlg_style styles[6]);
|
||||
|
||||
// Generic output function, using a format string instead of feature flags.
|
||||
// Use following conversion characters:
|
||||
// %h - output the time in H:M:S format
|
||||
// %m - output the time in milliseconds
|
||||
// %t - output the full list of tags, comma separated
|
||||
// %f - output the function name noted in the origin
|
||||
// %o - output the file:line of the origin
|
||||
// %s - print the appropriate style escape sequence.
|
||||
// %r - print the escape sequence to reset the style.
|
||||
// %c - The content of the log/assert
|
||||
// %% - print the '%' character
|
||||
// Only the above specified conversion characters are valid, the rest are
|
||||
// written as it is.
|
||||
DLG_API void dlg_generic_outputf(dlg_generic_output_handler output, void* data,
|
||||
const char* format_string, const struct dlg_origin* origin,
|
||||
const char* string, const struct dlg_style styles[6]);
|
||||
|
||||
// Generic output function. Used by the default output handler and might be useful
|
||||
// for custom output handlers (that don't want to manually format the output).
|
||||
// If stream is NULL uses stdout.
|
||||
// Automatically uses dlg_fprintf to assure correct utf-8 even on windows consoles.
|
||||
// Locks the stream (i.e. assures threadsafe access) when the associated feature
|
||||
// is passed (note that stdout/stderr might still mix from multiple threads).
|
||||
DLG_API void dlg_generic_output_stream(FILE* stream, unsigned int features,
|
||||
const struct dlg_origin* origin, const char* string,
|
||||
const struct dlg_style styles[6]);
|
||||
DLG_API void dlg_generic_outputf_stream(FILE* stream, const char* format_string,
|
||||
const struct dlg_origin* origin, const char* string,
|
||||
const struct dlg_style styles[6], bool lock_stream);
|
||||
|
||||
// Generic output function (see dlg_generic_output) that uses a buffer instead of
|
||||
// a stream. buf must at least point to *size bytes. Will set *size to the number
|
||||
// of bytes written (capped to the given size), if buf == NULL will set *size
|
||||
// to the needed size. The size parameter must not be NULL.
|
||||
DLG_API void dlg_generic_output_buf(char* buf, size_t* size, unsigned int features,
|
||||
const struct dlg_origin* origin, const char* string,
|
||||
const struct dlg_style styles[6]);
|
||||
DLG_API void dlg_generic_outputf_buf(char* buf, size_t* size, const char* format_string,
|
||||
const struct dlg_origin* origin, const char* string,
|
||||
const struct dlg_style styles[6]);
|
||||
|
||||
// Returns if the given stream is a tty. Useful for custom output handlers
|
||||
// e.g. to determine whether to use color.
|
||||
// NOTE: Due to windows limitations currently returns false for wsl ttys.
|
||||
DLG_API bool dlg_is_tty(FILE* stream);
|
||||
|
||||
// Returns the null-terminated escape sequence for the given style into buf.
|
||||
// Undefined behvaiour if any member of style has a value outside its enum range (will
|
||||
// probably result in a buffer overflow or garbage being printed).
|
||||
// If all member of style are 'none' will simply nullterminate the first buf char.
|
||||
DLG_API void dlg_escape_sequence(struct dlg_style style, char buf[12]);
|
||||
|
||||
// The reset style escape sequence.
|
||||
DLG_API extern const char* const dlg_reset_sequence;
|
||||
|
||||
// Just returns true without other effect on non-windows systems or if dlg
|
||||
// was compiled without the win_console option.
|
||||
// On windows tries to set the console mode to ansi to make escape sequences work.
|
||||
// This works only on newer windows 10 versions. Returns false on error.
|
||||
// Only the first call to it will have an effect, following calls just return the result.
|
||||
// The function is threadsafe. Automatically called by the default output handler.
|
||||
// This will only be able to set the mode for the stdout and stderr consoles, so
|
||||
// other streams to consoles will still not work.
|
||||
DLG_API bool dlg_win_init_ansi(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // header guard
|
||||
51
vendor/freetype/include/freetype/config/ftconfig.h
vendored
Normal file
51
vendor/freetype/include/freetype/config/ftconfig.h
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftconfig.h
|
||||
*
|
||||
* ANSI-specific configuration file (specification only).
|
||||
*
|
||||
* Copyright (C) 1996-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* This header file contains a number of macro definitions that are used by
|
||||
* the rest of the engine. Most of the macros here are automatically
|
||||
* determined at compile time, and you should not need to change it to port
|
||||
* FreeType, except to compile the library with a non-ANSI compiler.
|
||||
*
|
||||
* Note however that if some specific modifications are needed, we advise
|
||||
* you to place a modified copy in your build directory.
|
||||
*
|
||||
* The build directory is usually `builds/<system>`, and contains
|
||||
* system-specific files that are always included first when building the
|
||||
* library.
|
||||
*
|
||||
* This ANSI version should stay in `include/config/`.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FTCONFIG_H_
|
||||
#define FTCONFIG_H_
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_CONFIG_OPTIONS_H
|
||||
#include FT_CONFIG_STANDARD_LIBRARY_H
|
||||
|
||||
#include <freetype/config/integer-types.h>
|
||||
#include <freetype/config/public-macros.h>
|
||||
#include <freetype/config/mac-support.h>
|
||||
|
||||
#endif /* FTCONFIG_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
836
vendor/freetype/include/freetype/config/ftheader.h
vendored
Normal file
836
vendor/freetype/include/freetype/config/ftheader.h
vendored
Normal file
@@ -0,0 +1,836 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftheader.h
|
||||
*
|
||||
* Build macros of the FreeType 2 library.
|
||||
*
|
||||
* Copyright (C) 1996-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FTHEADER_H_
|
||||
#define FTHEADER_H_
|
||||
|
||||
|
||||
/*@***********************************************************************/
|
||||
/* */
|
||||
/* <Macro> */
|
||||
/* FT_BEGIN_HEADER */
|
||||
/* */
|
||||
/* <Description> */
|
||||
/* This macro is used in association with @FT_END_HEADER in header */
|
||||
/* files to ensure that the declarations within are properly */
|
||||
/* encapsulated in an `extern "C" { .. }` block when included from a */
|
||||
/* C++ compiler. */
|
||||
/* */
|
||||
#ifndef FT_BEGIN_HEADER
|
||||
# ifdef __cplusplus
|
||||
# define FT_BEGIN_HEADER extern "C" {
|
||||
# else
|
||||
# define FT_BEGIN_HEADER /* nothing */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/*@***********************************************************************/
|
||||
/* */
|
||||
/* <Macro> */
|
||||
/* FT_END_HEADER */
|
||||
/* */
|
||||
/* <Description> */
|
||||
/* This macro is used in association with @FT_BEGIN_HEADER in header */
|
||||
/* files to ensure that the declarations within are properly */
|
||||
/* encapsulated in an `extern "C" { .. }` block when included from a */
|
||||
/* C++ compiler. */
|
||||
/* */
|
||||
#ifndef FT_END_HEADER
|
||||
# ifdef __cplusplus
|
||||
# define FT_END_HEADER }
|
||||
# else
|
||||
# define FT_END_HEADER /* nothing */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* Aliases for the FreeType 2 public and configuration files.
|
||||
*
|
||||
*/
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* header_file_macros
|
||||
*
|
||||
* @title:
|
||||
* Header File Macros
|
||||
*
|
||||
* @abstract:
|
||||
* Macro definitions used to `#include` specific header files.
|
||||
*
|
||||
* @description:
|
||||
* In addition to the normal scheme of including header files like
|
||||
*
|
||||
* ```
|
||||
* #include <freetype/freetype.h>
|
||||
* #include <freetype/ftmm.h>
|
||||
* #include <freetype/ftglyph.h>
|
||||
* ```
|
||||
*
|
||||
* it is possible to used named macros instead. They can be used
|
||||
* directly in `#include` statements as in
|
||||
*
|
||||
* ```
|
||||
* #include FT_FREETYPE_H
|
||||
* #include FT_MULTIPLE_MASTERS_H
|
||||
* #include FT_GLYPH_H
|
||||
* ```
|
||||
*
|
||||
* These macros were introduced to overcome the infamous 8.3~naming rule
|
||||
* required by DOS (and `FT_MULTIPLE_MASTERS_H` is a lot more meaningful
|
||||
* than `ftmm.h`).
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* configuration files */
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_CONFIG_CONFIG_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing
|
||||
* FreeType~2 configuration data.
|
||||
*
|
||||
*/
|
||||
#ifndef FT_CONFIG_CONFIG_H
|
||||
#define FT_CONFIG_CONFIG_H <freetype/config/ftconfig.h>
|
||||
#endif
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_CONFIG_STANDARD_LIBRARY_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing
|
||||
* FreeType~2 interface to the standard C library functions.
|
||||
*
|
||||
*/
|
||||
#ifndef FT_CONFIG_STANDARD_LIBRARY_H
|
||||
#define FT_CONFIG_STANDARD_LIBRARY_H <freetype/config/ftstdlib.h>
|
||||
#endif
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_CONFIG_OPTIONS_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing
|
||||
* FreeType~2 project-specific configuration options.
|
||||
*
|
||||
*/
|
||||
#ifndef FT_CONFIG_OPTIONS_H
|
||||
#define FT_CONFIG_OPTIONS_H <freetype/config/ftoption.h>
|
||||
#endif
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_CONFIG_MODULES_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* list of FreeType~2 modules that are statically linked to new library
|
||||
* instances in @FT_Init_FreeType.
|
||||
*
|
||||
*/
|
||||
#ifndef FT_CONFIG_MODULES_H
|
||||
#define FT_CONFIG_MODULES_H <freetype/config/ftmodule.h>
|
||||
#endif
|
||||
|
||||
/* */
|
||||
|
||||
/* public headers */
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_FREETYPE_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* base FreeType~2 API.
|
||||
*
|
||||
*/
|
||||
#define FT_FREETYPE_H <freetype/freetype.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_ERRORS_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* list of FreeType~2 error codes (and messages).
|
||||
*
|
||||
* It is included by @FT_FREETYPE_H.
|
||||
*
|
||||
*/
|
||||
#define FT_ERRORS_H <freetype/fterrors.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_MODULE_ERRORS_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* list of FreeType~2 module error offsets (and messages).
|
||||
*
|
||||
*/
|
||||
#define FT_MODULE_ERRORS_H <freetype/ftmoderr.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_SYSTEM_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* FreeType~2 interface to low-level operations (i.e., memory management
|
||||
* and stream i/o).
|
||||
*
|
||||
* It is included by @FT_FREETYPE_H.
|
||||
*
|
||||
*/
|
||||
#define FT_SYSTEM_H <freetype/ftsystem.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_IMAGE_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing type
|
||||
* definitions related to glyph images (i.e., bitmaps, outlines,
|
||||
* scan-converter parameters).
|
||||
*
|
||||
* It is included by @FT_FREETYPE_H.
|
||||
*
|
||||
*/
|
||||
#define FT_IMAGE_H <freetype/ftimage.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_TYPES_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* basic data types defined by FreeType~2.
|
||||
*
|
||||
* It is included by @FT_FREETYPE_H.
|
||||
*
|
||||
*/
|
||||
#define FT_TYPES_H <freetype/fttypes.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_LIST_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* list management API of FreeType~2.
|
||||
*
|
||||
* (Most applications will never need to include this file.)
|
||||
*
|
||||
*/
|
||||
#define FT_LIST_H <freetype/ftlist.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_OUTLINE_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* scalable outline management API of FreeType~2.
|
||||
*
|
||||
*/
|
||||
#define FT_OUTLINE_H <freetype/ftoutln.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_SIZES_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* API which manages multiple @FT_Size objects per face.
|
||||
*
|
||||
*/
|
||||
#define FT_SIZES_H <freetype/ftsizes.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_MODULE_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* module management API of FreeType~2.
|
||||
*
|
||||
*/
|
||||
#define FT_MODULE_H <freetype/ftmodapi.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_RENDER_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* renderer module management API of FreeType~2.
|
||||
*
|
||||
*/
|
||||
#define FT_RENDER_H <freetype/ftrender.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_DRIVER_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing
|
||||
* structures and macros related to the driver modules.
|
||||
*
|
||||
*/
|
||||
#define FT_DRIVER_H <freetype/ftdriver.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_AUTOHINTER_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing
|
||||
* structures and macros related to the auto-hinting module.
|
||||
*
|
||||
* Deprecated since version~2.9; use @FT_DRIVER_H instead.
|
||||
*
|
||||
*/
|
||||
#define FT_AUTOHINTER_H FT_DRIVER_H
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_CFF_DRIVER_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing
|
||||
* structures and macros related to the CFF driver module.
|
||||
*
|
||||
* Deprecated since version~2.9; use @FT_DRIVER_H instead.
|
||||
*
|
||||
*/
|
||||
#define FT_CFF_DRIVER_H FT_DRIVER_H
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_TRUETYPE_DRIVER_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing
|
||||
* structures and macros related to the TrueType driver module.
|
||||
*
|
||||
* Deprecated since version~2.9; use @FT_DRIVER_H instead.
|
||||
*
|
||||
*/
|
||||
#define FT_TRUETYPE_DRIVER_H FT_DRIVER_H
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_PCF_DRIVER_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing
|
||||
* structures and macros related to the PCF driver module.
|
||||
*
|
||||
* Deprecated since version~2.9; use @FT_DRIVER_H instead.
|
||||
*
|
||||
*/
|
||||
#define FT_PCF_DRIVER_H FT_DRIVER_H
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_TYPE1_TABLES_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* types and API specific to the Type~1 format.
|
||||
*
|
||||
*/
|
||||
#define FT_TYPE1_TABLES_H <freetype/t1tables.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_TRUETYPE_IDS_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* enumeration values which identify name strings, languages, encodings,
|
||||
* etc. This file really contains a _large_ set of constant macro
|
||||
* definitions, taken from the TrueType and OpenType specifications.
|
||||
*
|
||||
*/
|
||||
#define FT_TRUETYPE_IDS_H <freetype/ttnameid.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_TRUETYPE_TABLES_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* types and API specific to the TrueType (as well as OpenType) format.
|
||||
*
|
||||
*/
|
||||
#define FT_TRUETYPE_TABLES_H <freetype/tttables.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_TRUETYPE_TAGS_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* definitions of TrueType four-byte 'tags' which identify blocks in
|
||||
* SFNT-based font formats (i.e., TrueType and OpenType).
|
||||
*
|
||||
*/
|
||||
#define FT_TRUETYPE_TAGS_H <freetype/tttags.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_BDF_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* definitions of an API which accesses BDF-specific strings from a face.
|
||||
*
|
||||
*/
|
||||
#define FT_BDF_H <freetype/ftbdf.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_CID_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* definitions of an API which access CID font information from a face.
|
||||
*
|
||||
*/
|
||||
#define FT_CID_H <freetype/ftcid.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_GZIP_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* definitions of an API which supports gzip-compressed files.
|
||||
*
|
||||
*/
|
||||
#define FT_GZIP_H <freetype/ftgzip.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_LZW_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* definitions of an API which supports LZW-compressed files.
|
||||
*
|
||||
*/
|
||||
#define FT_LZW_H <freetype/ftlzw.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_BZIP2_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* definitions of an API which supports bzip2-compressed files.
|
||||
*
|
||||
*/
|
||||
#define FT_BZIP2_H <freetype/ftbzip2.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_WINFONTS_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* definitions of an API which supports Windows FNT files.
|
||||
*
|
||||
*/
|
||||
#define FT_WINFONTS_H <freetype/ftwinfnt.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_GLYPH_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* API of the optional glyph management component.
|
||||
*
|
||||
*/
|
||||
#define FT_GLYPH_H <freetype/ftglyph.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_BITMAP_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* API of the optional bitmap conversion component.
|
||||
*
|
||||
*/
|
||||
#define FT_BITMAP_H <freetype/ftbitmap.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_BBOX_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* API of the optional exact bounding box computation routines.
|
||||
*
|
||||
*/
|
||||
#define FT_BBOX_H <freetype/ftbbox.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_CACHE_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* API of the optional FreeType~2 cache sub-system.
|
||||
*
|
||||
*/
|
||||
#define FT_CACHE_H <freetype/ftcache.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_MAC_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* Macintosh-specific FreeType~2 API. The latter is used to access fonts
|
||||
* embedded in resource forks.
|
||||
*
|
||||
* This header file must be explicitly included by client applications
|
||||
* compiled on the Mac (note that the base API still works though).
|
||||
*
|
||||
*/
|
||||
#define FT_MAC_H <freetype/ftmac.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_MULTIPLE_MASTERS_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* optional multiple-masters management API of FreeType~2.
|
||||
*
|
||||
*/
|
||||
#define FT_MULTIPLE_MASTERS_H <freetype/ftmm.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_SFNT_NAMES_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* optional FreeType~2 API which accesses embedded 'name' strings in
|
||||
* SFNT-based font formats (i.e., TrueType and OpenType).
|
||||
*
|
||||
*/
|
||||
#define FT_SFNT_NAMES_H <freetype/ftsnames.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_OPENTYPE_VALIDATE_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* optional FreeType~2 API which validates OpenType tables ('BASE',
|
||||
* 'GDEF', 'GPOS', 'GSUB', 'JSTF').
|
||||
*
|
||||
*/
|
||||
#define FT_OPENTYPE_VALIDATE_H <freetype/ftotval.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_GX_VALIDATE_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* optional FreeType~2 API which validates TrueTypeGX/AAT tables ('feat',
|
||||
* 'mort', 'morx', 'bsln', 'just', 'kern', 'opbd', 'trak', 'prop').
|
||||
*
|
||||
*/
|
||||
#define FT_GX_VALIDATE_H <freetype/ftgxval.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_PFR_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* FreeType~2 API which accesses PFR-specific data.
|
||||
*
|
||||
*/
|
||||
#define FT_PFR_H <freetype/ftpfr.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_STROKER_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* FreeType~2 API which provides functions to stroke outline paths.
|
||||
*/
|
||||
#define FT_STROKER_H <freetype/ftstroke.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_SYNTHESIS_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* FreeType~2 API which performs artificial obliquing and emboldening.
|
||||
*/
|
||||
#define FT_SYNTHESIS_H <freetype/ftsynth.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_FONT_FORMATS_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* FreeType~2 API which provides functions specific to font formats.
|
||||
*/
|
||||
#define FT_FONT_FORMATS_H <freetype/ftfntfmt.h>
|
||||
|
||||
/* deprecated */
|
||||
#define FT_XFREE86_H FT_FONT_FORMATS_H
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_TRIGONOMETRY_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* FreeType~2 API which performs trigonometric computations (e.g.,
|
||||
* cosines and arc tangents).
|
||||
*/
|
||||
#define FT_TRIGONOMETRY_H <freetype/fttrigon.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_LCD_FILTER_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* FreeType~2 API which performs color filtering for subpixel rendering.
|
||||
*/
|
||||
#define FT_LCD_FILTER_H <freetype/ftlcdfil.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_INCREMENTAL_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* FreeType~2 API which performs incremental glyph loading.
|
||||
*/
|
||||
#define FT_INCREMENTAL_H <freetype/ftincrem.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_GASP_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* FreeType~2 API which returns entries from the TrueType GASP table.
|
||||
*/
|
||||
#define FT_GASP_H <freetype/ftgasp.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_ADVANCES_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* FreeType~2 API which returns individual and ranged glyph advances.
|
||||
*/
|
||||
#define FT_ADVANCES_H <freetype/ftadvanc.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_COLOR_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* FreeType~2 API which handles the OpenType 'CPAL' table.
|
||||
*/
|
||||
#define FT_COLOR_H <freetype/ftcolor.h>
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_OTSVG_H
|
||||
*
|
||||
* @description:
|
||||
* A macro used in `#include` statements to name the file containing the
|
||||
* FreeType~2 API which handles the OpenType 'SVG~' glyphs.
|
||||
*/
|
||||
#define FT_OTSVG_H <freetype/otsvg.h>
|
||||
|
||||
|
||||
/* */
|
||||
|
||||
/* These header files don't need to be included by the user. */
|
||||
#define FT_ERROR_DEFINITIONS_H <freetype/fterrdef.h>
|
||||
#define FT_PARAMETER_TAGS_H <freetype/ftparams.h>
|
||||
|
||||
/* Deprecated macros. */
|
||||
#define FT_UNPATENTED_HINTING_H <freetype/ftparams.h>
|
||||
#define FT_TRUETYPE_UNPATENTED_H <freetype/ftparams.h>
|
||||
|
||||
/* `FT_CACHE_H` is the only header file needed for the cache subsystem. */
|
||||
#define FT_CACHE_IMAGE_H FT_CACHE_H
|
||||
#define FT_CACHE_SMALL_BITMAPS_H FT_CACHE_H
|
||||
#define FT_CACHE_CHARMAP_H FT_CACHE_H
|
||||
|
||||
/* The internals of the cache sub-system are no longer exposed. We */
|
||||
/* default to `FT_CACHE_H` at the moment just in case, but we know */
|
||||
/* of no rogue client that uses them. */
|
||||
/* */
|
||||
#define FT_CACHE_MANAGER_H FT_CACHE_H
|
||||
#define FT_CACHE_INTERNAL_MRU_H FT_CACHE_H
|
||||
#define FT_CACHE_INTERNAL_MANAGER_H FT_CACHE_H
|
||||
#define FT_CACHE_INTERNAL_CACHE_H FT_CACHE_H
|
||||
#define FT_CACHE_INTERNAL_GLYPH_H FT_CACHE_H
|
||||
#define FT_CACHE_INTERNAL_IMAGE_H FT_CACHE_H
|
||||
#define FT_CACHE_INTERNAL_SBITS_H FT_CACHE_H
|
||||
|
||||
/* TODO(david): Move this section below to a different header */
|
||||
#ifdef FT2_BUILD_LIBRARY
|
||||
#if defined( _MSC_VER ) /* Visual C++ (and Intel C++) */
|
||||
|
||||
/* We disable the warning `conditional expression is constant' here */
|
||||
/* in order to compile cleanly with the maximum level of warnings. */
|
||||
/* In particular, the warning complains about stuff like `while(0)' */
|
||||
/* which is very useful in macro definitions. There is no benefit */
|
||||
/* in having it enabled. */
|
||||
#pragma warning( disable : 4127 )
|
||||
|
||||
#endif /* _MSC_VER */
|
||||
#endif /* FT2_BUILD_LIBRARY */
|
||||
|
||||
#endif /* FTHEADER_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
12
vendor/freetype/include/freetype/config/ftmodule.h
vendored
Normal file
12
vendor/freetype/include/freetype/config/ftmodule.h
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Custom ftmodule.h for autosample — register only the modules we need.
|
||||
*/
|
||||
|
||||
FT_USE_MODULE( FT_Module_Class, autofit_module_class )
|
||||
FT_USE_MODULE( FT_Driver_ClassRec, tt_driver_class )
|
||||
FT_USE_MODULE( FT_Module_Class, psnames_module_class )
|
||||
FT_USE_MODULE( FT_Module_Class, pshinter_module_class )
|
||||
FT_USE_MODULE( FT_Module_Class, sfnt_module_class )
|
||||
FT_USE_MODULE( FT_Renderer_Class, ft_smooth_renderer_class )
|
||||
|
||||
/* EOF */
|
||||
1030
vendor/freetype/include/freetype/config/ftoption.h
vendored
Normal file
1030
vendor/freetype/include/freetype/config/ftoption.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
185
vendor/freetype/include/freetype/config/ftstdlib.h
vendored
Normal file
185
vendor/freetype/include/freetype/config/ftstdlib.h
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftstdlib.h
|
||||
*
|
||||
* ANSI-specific library and header configuration file (specification
|
||||
* only).
|
||||
*
|
||||
* Copyright (C) 2002-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* This file is used to group all `#includes` to the ANSI~C library that
|
||||
* FreeType normally requires. It also defines macros to rename the
|
||||
* standard functions within the FreeType source code.
|
||||
*
|
||||
* Load a file which defines `FTSTDLIB_H_` before this one to override it.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FTSTDLIB_H_
|
||||
#define FTSTDLIB_H_
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#define ft_ptrdiff_t ptrdiff_t
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* integer limits
|
||||
*
|
||||
* `UINT_MAX` and `ULONG_MAX` are used to automatically compute the size of
|
||||
* `int` and `long` in bytes at compile-time. So far, this works for all
|
||||
* platforms the library has been tested on. We also check `ULLONG_MAX`
|
||||
* to see whether we can use 64-bit `long long` later on.
|
||||
*
|
||||
* Note that on the extremely rare platforms that do not provide integer
|
||||
* types that are _exactly_ 16 and 32~bits wide (e.g., some old Crays where
|
||||
* `int` is 36~bits), we do not make any guarantee about the correct
|
||||
* behaviour of FreeType~2 with all fonts.
|
||||
*
|
||||
* In these cases, `ftconfig.h` will refuse to compile anyway with a
|
||||
* message like 'couldn't find 32-bit type' or something similar.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#define FT_CHAR_BIT CHAR_BIT
|
||||
#define FT_USHORT_MAX USHRT_MAX
|
||||
#define FT_INT_MAX INT_MAX
|
||||
#define FT_INT_MIN INT_MIN
|
||||
#define FT_UINT_MAX UINT_MAX
|
||||
#define FT_LONG_MIN LONG_MIN
|
||||
#define FT_LONG_MAX LONG_MAX
|
||||
#define FT_ULONG_MAX ULONG_MAX
|
||||
#ifdef LLONG_MAX
|
||||
#define FT_LLONG_MAX LLONG_MAX
|
||||
#endif
|
||||
#ifdef LLONG_MIN
|
||||
#define FT_LLONG_MIN LLONG_MIN
|
||||
#endif
|
||||
#ifdef ULLONG_MAX
|
||||
#define FT_ULLONG_MAX ULLONG_MAX
|
||||
#endif
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* character and string processing
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define ft_memchr memchr
|
||||
#define ft_memcmp memcmp
|
||||
#define ft_memcpy memcpy
|
||||
#define ft_memmove memmove
|
||||
#define ft_memset memset
|
||||
#define ft_strcat strcat
|
||||
#define ft_strcmp strcmp
|
||||
#define ft_strcpy strcpy
|
||||
#define ft_strlen strlen
|
||||
#define ft_strncmp strncmp
|
||||
#define ft_strncpy strncpy
|
||||
#define ft_strrchr strrchr
|
||||
#define ft_strstr strstr
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* file handling
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define FT_FILE FILE
|
||||
#define ft_fclose fclose
|
||||
#define ft_fopen fopen
|
||||
#define ft_fread fread
|
||||
#define ft_fseek fseek
|
||||
#define ft_ftell ftell
|
||||
#define ft_snprintf snprintf
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* sorting
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#define ft_qsort qsort
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* memory allocation
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#define ft_scalloc calloc
|
||||
#define ft_sfree free
|
||||
#define ft_smalloc malloc
|
||||
#define ft_srealloc realloc
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* miscellaneous
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#define ft_strtol strtol
|
||||
#define ft_getenv getenv
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* execution control
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <setjmp.h>
|
||||
|
||||
#define ft_jmp_buf jmp_buf /* note: this cannot be a typedef since */
|
||||
/* `jmp_buf` is defined as a macro */
|
||||
/* on certain platforms */
|
||||
|
||||
#define ft_longjmp longjmp
|
||||
#define ft_setjmp( b ) setjmp( *(ft_jmp_buf*) &(b) ) /* same thing here */
|
||||
|
||||
|
||||
/* The following is only used for debugging purposes, i.e., if */
|
||||
/* `FT_DEBUG_LEVEL_ERROR` or `FT_DEBUG_LEVEL_TRACE` are defined. */
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
#endif /* FTSTDLIB_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
250
vendor/freetype/include/freetype/config/integer-types.h
vendored
Normal file
250
vendor/freetype/include/freetype/config/integer-types.h
vendored
Normal file
@@ -0,0 +1,250 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* config/integer-types.h
|
||||
*
|
||||
* FreeType integer types definitions.
|
||||
*
|
||||
* Copyright (C) 1996-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
#ifndef FREETYPE_CONFIG_INTEGER_TYPES_H_
|
||||
#define FREETYPE_CONFIG_INTEGER_TYPES_H_
|
||||
|
||||
/* There are systems (like the Texas Instruments 'C54x) where a `char` */
|
||||
/* has 16~bits. ANSI~C says that `sizeof(char)` is always~1. Since an */
|
||||
/* `int` has 16~bits also for this system, `sizeof(int)` gives~1 which */
|
||||
/* is probably unexpected. */
|
||||
/* */
|
||||
/* `CHAR_BIT` (defined in `limits.h`) gives the number of bits in a */
|
||||
/* `char` type. */
|
||||
|
||||
#ifndef FT_CHAR_BIT
|
||||
#define FT_CHAR_BIT CHAR_BIT
|
||||
#endif
|
||||
|
||||
#ifndef FT_SIZEOF_INT
|
||||
|
||||
/* The size of an `int` type. */
|
||||
#if FT_UINT_MAX == 0xFFFFUL
|
||||
#define FT_SIZEOF_INT ( 16 / FT_CHAR_BIT )
|
||||
#elif FT_UINT_MAX == 0xFFFFFFFFUL
|
||||
#define FT_SIZEOF_INT ( 32 / FT_CHAR_BIT )
|
||||
#elif FT_UINT_MAX > 0xFFFFFFFFUL && FT_UINT_MAX == 0xFFFFFFFFFFFFFFFFUL
|
||||
#define FT_SIZEOF_INT ( 64 / FT_CHAR_BIT )
|
||||
#else
|
||||
#error "Unsupported size of `int' type!"
|
||||
#endif
|
||||
|
||||
#endif /* !defined(FT_SIZEOF_INT) */
|
||||
|
||||
#ifndef FT_SIZEOF_LONG
|
||||
|
||||
/* The size of a `long` type. A five-byte `long` (as used e.g. on the */
|
||||
/* DM642) is recognized but avoided. */
|
||||
#if FT_ULONG_MAX == 0xFFFFFFFFUL
|
||||
#define FT_SIZEOF_LONG ( 32 / FT_CHAR_BIT )
|
||||
#elif FT_ULONG_MAX > 0xFFFFFFFFUL && FT_ULONG_MAX == 0xFFFFFFFFFFUL
|
||||
#define FT_SIZEOF_LONG ( 32 / FT_CHAR_BIT )
|
||||
#elif FT_ULONG_MAX > 0xFFFFFFFFUL && FT_ULONG_MAX == 0xFFFFFFFFFFFFFFFFUL
|
||||
#define FT_SIZEOF_LONG ( 64 / FT_CHAR_BIT )
|
||||
#else
|
||||
#error "Unsupported size of `long' type!"
|
||||
#endif
|
||||
|
||||
#endif /* !defined(FT_SIZEOF_LONG) */
|
||||
|
||||
#ifndef FT_SIZEOF_LONG_LONG
|
||||
|
||||
/* The size of a `long long` type if available */
|
||||
#if defined( FT_ULLONG_MAX ) && FT_ULLONG_MAX >= 0xFFFFFFFFFFFFFFFFULL
|
||||
#define FT_SIZEOF_LONG_LONG ( 64 / FT_CHAR_BIT )
|
||||
#else
|
||||
#define FT_SIZEOF_LONG_LONG 0
|
||||
#endif
|
||||
|
||||
#endif /* !defined(FT_SIZEOF_LONG_LONG) */
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* basic_types
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @type:
|
||||
* FT_Int16
|
||||
*
|
||||
* @description:
|
||||
* A typedef for a 16bit signed integer type.
|
||||
*/
|
||||
typedef signed short FT_Int16;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @type:
|
||||
* FT_UInt16
|
||||
*
|
||||
* @description:
|
||||
* A typedef for a 16bit unsigned integer type.
|
||||
*/
|
||||
typedef unsigned short FT_UInt16;
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
/* this #if 0 ... #endif clause is for documentation purposes */
|
||||
#if 0
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @type:
|
||||
* FT_Int32
|
||||
*
|
||||
* @description:
|
||||
* A typedef for a 32bit signed integer type. The size depends on the
|
||||
* configuration.
|
||||
*/
|
||||
typedef signed XXX FT_Int32;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @type:
|
||||
* FT_UInt32
|
||||
*
|
||||
* A typedef for a 32bit unsigned integer type. The size depends on the
|
||||
* configuration.
|
||||
*/
|
||||
typedef unsigned XXX FT_UInt32;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @type:
|
||||
* FT_Int64
|
||||
*
|
||||
* A typedef for a 64bit signed integer type. The size depends on the
|
||||
* configuration. Only defined if there is real 64bit support;
|
||||
* otherwise, it gets emulated with a structure (if necessary).
|
||||
*/
|
||||
typedef signed XXX FT_Int64;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @type:
|
||||
* FT_UInt64
|
||||
*
|
||||
* A typedef for a 64bit unsigned integer type. The size depends on the
|
||||
* configuration. Only defined if there is real 64bit support;
|
||||
* otherwise, it gets emulated with a structure (if necessary).
|
||||
*/
|
||||
typedef unsigned XXX FT_UInt64;
|
||||
|
||||
/* */
|
||||
|
||||
#endif
|
||||
|
||||
#if FT_SIZEOF_INT == ( 32 / FT_CHAR_BIT )
|
||||
|
||||
typedef signed int FT_Int32;
|
||||
typedef unsigned int FT_UInt32;
|
||||
|
||||
#elif FT_SIZEOF_LONG == ( 32 / FT_CHAR_BIT )
|
||||
|
||||
typedef signed long FT_Int32;
|
||||
typedef unsigned long FT_UInt32;
|
||||
|
||||
#else
|
||||
#error "no 32bit type found -- please check your configuration files"
|
||||
#endif
|
||||
|
||||
|
||||
/* look up an integer type that is at least 32~bits */
|
||||
#if FT_SIZEOF_INT >= ( 32 / FT_CHAR_BIT )
|
||||
|
||||
typedef int FT_Fast;
|
||||
typedef unsigned int FT_UFast;
|
||||
|
||||
#elif FT_SIZEOF_LONG >= ( 32 / FT_CHAR_BIT )
|
||||
|
||||
typedef long FT_Fast;
|
||||
typedef unsigned long FT_UFast;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* determine whether we have a 64-bit integer type */
|
||||
#if FT_SIZEOF_LONG == ( 64 / FT_CHAR_BIT )
|
||||
|
||||
#define FT_INT64 long
|
||||
#define FT_UINT64 unsigned long
|
||||
|
||||
#elif FT_SIZEOF_LONG_LONG >= ( 64 / FT_CHAR_BIT )
|
||||
|
||||
#define FT_INT64 long long int
|
||||
#define FT_UINT64 unsigned long long int
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* A 64-bit data type may create compilation problems if you compile in
|
||||
* strict ANSI mode. To avoid them, we disable other 64-bit data types if
|
||||
* `__STDC__` is defined. You can however ignore this rule by defining the
|
||||
* `FT_CONFIG_OPTION_FORCE_INT64` configuration macro.
|
||||
*/
|
||||
#elif !defined( __STDC__ ) || defined( FT_CONFIG_OPTION_FORCE_INT64 )
|
||||
|
||||
#if defined( _MSC_VER ) && _MSC_VER >= 900 /* Visual C++ (and Intel C++) */
|
||||
|
||||
/* this compiler provides the `__int64` type */
|
||||
#define FT_INT64 __int64
|
||||
#define FT_UINT64 unsigned __int64
|
||||
|
||||
#elif defined( __BORLANDC__ ) /* Borland C++ */
|
||||
|
||||
/* XXXX: We should probably check the value of `__BORLANDC__` in order */
|
||||
/* to test the compiler version. */
|
||||
|
||||
/* this compiler provides the `__int64` type */
|
||||
#define FT_INT64 __int64
|
||||
#define FT_UINT64 unsigned __int64
|
||||
|
||||
#elif defined( __WATCOMC__ ) && __WATCOMC__ >= 1100 /* Watcom C++ */
|
||||
|
||||
#define FT_INT64 long long int
|
||||
#define FT_UINT64 unsigned long long int
|
||||
|
||||
#elif defined( __MWERKS__ ) /* Metrowerks CodeWarrior */
|
||||
|
||||
#define FT_INT64 long long int
|
||||
#define FT_UINT64 unsigned long long int
|
||||
|
||||
#elif defined( __GNUC__ )
|
||||
|
||||
/* GCC provides the `long long` type */
|
||||
#define FT_INT64 long long int
|
||||
#define FT_UINT64 unsigned long long int
|
||||
|
||||
#endif /* !__STDC__ */
|
||||
|
||||
#endif /* FT_SIZEOF_LONG == (64 / FT_CHAR_BIT) */
|
||||
|
||||
#ifdef FT_INT64
|
||||
typedef FT_INT64 FT_Int64;
|
||||
typedef FT_UINT64 FT_UInt64;
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* FREETYPE_CONFIG_INTEGER_TYPES_H_ */
|
||||
49
vendor/freetype/include/freetype/config/mac-support.h
vendored
Normal file
49
vendor/freetype/include/freetype/config/mac-support.h
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* config/mac-support.h
|
||||
*
|
||||
* Mac/OS X support configuration header.
|
||||
*
|
||||
* Copyright (C) 1996-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
#ifndef FREETYPE_CONFIG_MAC_SUPPORT_H_
|
||||
#define FREETYPE_CONFIG_MAC_SUPPORT_H_
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* Mac support
|
||||
*
|
||||
* This is the only necessary change, so it is defined here instead
|
||||
* providing a new configuration file.
|
||||
*/
|
||||
#if defined( __APPLE__ ) || ( defined( __MWERKS__ ) && defined( macintosh ) )
|
||||
/* No Carbon frameworks for 64bit 10.4.x. */
|
||||
/* `AvailabilityMacros.h` is available since Mac OS X 10.2, */
|
||||
/* so guess the system version by maximum errno before inclusion. */
|
||||
#include <errno.h>
|
||||
#ifdef ECANCELED /* defined since 10.2 */
|
||||
#include "AvailabilityMacros.h"
|
||||
#endif
|
||||
#if defined( __LP64__ ) && \
|
||||
( MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 )
|
||||
#undef FT_MACINTOSH
|
||||
#endif
|
||||
|
||||
#elif defined( __SC__ ) || defined( __MRC__ )
|
||||
/* Classic MacOS compilers */
|
||||
#include "ConditionalMacros.h"
|
||||
#if TARGET_OS_MAC
|
||||
#define FT_MACINTOSH 1
|
||||
#endif
|
||||
|
||||
#endif /* Mac support */
|
||||
|
||||
#endif /* FREETYPE_CONFIG_MAC_SUPPORT_H_ */
|
||||
138
vendor/freetype/include/freetype/config/public-macros.h
vendored
Normal file
138
vendor/freetype/include/freetype/config/public-macros.h
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* config/public-macros.h
|
||||
*
|
||||
* Define a set of compiler macros used in public FreeType headers.
|
||||
*
|
||||
* Copyright (C) 2020-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* The definitions in this file are used by the public FreeType headers
|
||||
* and thus should be considered part of the public API.
|
||||
*
|
||||
* Other compiler-specific macro definitions that are not exposed by the
|
||||
* FreeType API should go into
|
||||
* `include/freetype/internal/compiler-macros.h` instead.
|
||||
*/
|
||||
#ifndef FREETYPE_CONFIG_PUBLIC_MACROS_H_
|
||||
#define FREETYPE_CONFIG_PUBLIC_MACROS_H_
|
||||
|
||||
/*
|
||||
* `FT_BEGIN_HEADER` and `FT_END_HEADER` might have already been defined
|
||||
* by `freetype/config/ftheader.h`, but we don't want to include this
|
||||
* header here, so redefine the macros here only when needed. Their
|
||||
* definition is very stable, so keeping them in sync with the ones in the
|
||||
* header should not be a maintenance issue.
|
||||
*/
|
||||
#ifndef FT_BEGIN_HEADER
|
||||
#ifdef __cplusplus
|
||||
#define FT_BEGIN_HEADER extern "C" {
|
||||
#else
|
||||
#define FT_BEGIN_HEADER /* empty */
|
||||
#endif
|
||||
#endif /* FT_BEGIN_HEADER */
|
||||
|
||||
#ifndef FT_END_HEADER
|
||||
#ifdef __cplusplus
|
||||
#define FT_END_HEADER }
|
||||
#else
|
||||
#define FT_END_HEADER /* empty */
|
||||
#endif
|
||||
#endif /* FT_END_HEADER */
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
/*
|
||||
* Mark a function declaration as public. This ensures it will be
|
||||
* properly exported to client code. Place this before a function
|
||||
* declaration.
|
||||
*
|
||||
* NOTE: This macro should be considered an internal implementation
|
||||
* detail, and not part of the FreeType API. It is only defined here
|
||||
* because it is needed by `FT_EXPORT`.
|
||||
*/
|
||||
|
||||
/* Visual C, mingw */
|
||||
#if defined( _WIN32 )
|
||||
|
||||
#if defined( FT2_BUILD_LIBRARY ) && defined( DLL_EXPORT )
|
||||
#define FT_PUBLIC_FUNCTION_ATTRIBUTE __declspec( dllexport )
|
||||
#elif defined( DLL_IMPORT )
|
||||
#define FT_PUBLIC_FUNCTION_ATTRIBUTE __declspec( dllimport )
|
||||
#endif
|
||||
|
||||
/* gcc, clang */
|
||||
#elif ( defined( __GNUC__ ) && __GNUC__ >= 4 ) || defined( __clang__ )
|
||||
#define FT_PUBLIC_FUNCTION_ATTRIBUTE \
|
||||
__attribute__(( visibility( "default" ) ))
|
||||
|
||||
/* Sun */
|
||||
#elif defined( __SUNPRO_C ) && __SUNPRO_C >= 0x550
|
||||
#define FT_PUBLIC_FUNCTION_ATTRIBUTE __global
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef FT_PUBLIC_FUNCTION_ATTRIBUTE
|
||||
#define FT_PUBLIC_FUNCTION_ATTRIBUTE /* empty */
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Define a public FreeType API function. This ensures it is properly
|
||||
* exported or imported at build time. The macro parameter is the
|
||||
* function's return type as in:
|
||||
*
|
||||
* FT_EXPORT( FT_Bool )
|
||||
* FT_Object_Method( FT_Object obj,
|
||||
* ... );
|
||||
*
|
||||
* NOTE: This requires that all `FT_EXPORT` uses are inside
|
||||
* `FT_BEGIN_HEADER ... FT_END_HEADER` blocks. This guarantees that the
|
||||
* functions are exported with C linkage, even when the header is included
|
||||
* by a C++ source file.
|
||||
*/
|
||||
#define FT_EXPORT( x ) FT_PUBLIC_FUNCTION_ATTRIBUTE extern x
|
||||
|
||||
|
||||
/*
|
||||
* `FT_UNUSED` indicates that a given parameter is not used -- this is
|
||||
* only used to get rid of unpleasant compiler warnings.
|
||||
*
|
||||
* Technically, this was not meant to be part of the public API, but some
|
||||
* third-party code depends on it.
|
||||
*/
|
||||
#ifndef FT_UNUSED
|
||||
#define FT_UNUSED( arg ) ( (arg) = (arg) )
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Support for casts in both C and C++.
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
#define FT_STATIC_CAST( type, var ) static_cast<type>(var)
|
||||
#define FT_REINTERPRET_CAST( type, var ) reinterpret_cast<type>(var)
|
||||
|
||||
#define FT_STATIC_BYTE_CAST( type, var ) \
|
||||
static_cast<type>( static_cast<unsigned char>( var ) )
|
||||
#else
|
||||
#define FT_STATIC_CAST( type, var ) (type)(var)
|
||||
#define FT_REINTERPRET_CAST( type, var ) (type)(var)
|
||||
|
||||
#define FT_STATIC_BYTE_CAST( type, var ) (type)(unsigned char)(var)
|
||||
#endif
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* FREETYPE_CONFIG_PUBLIC_MACROS_H_ */
|
||||
5289
vendor/freetype/include/freetype/freetype.h
vendored
Normal file
5289
vendor/freetype/include/freetype/freetype.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
188
vendor/freetype/include/freetype/ftadvanc.h
vendored
Normal file
188
vendor/freetype/include/freetype/ftadvanc.h
vendored
Normal file
@@ -0,0 +1,188 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftadvanc.h
|
||||
*
|
||||
* Quick computation of advance widths (specification only).
|
||||
*
|
||||
* Copyright (C) 2008-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FTADVANC_H_
|
||||
#define FTADVANC_H_
|
||||
|
||||
|
||||
#include <freetype/freetype.h>
|
||||
|
||||
#ifdef FREETYPE_H
|
||||
#error "freetype.h of FreeType 1 has been loaded!"
|
||||
#error "Please fix the directory search order for header files"
|
||||
#error "so that freetype.h of FreeType 2 is found first."
|
||||
#endif
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* quick_advance
|
||||
*
|
||||
* @title:
|
||||
* Quick retrieval of advance values
|
||||
*
|
||||
* @abstract:
|
||||
* Retrieve horizontal and vertical advance values without processing
|
||||
* glyph outlines, if possible.
|
||||
*
|
||||
* @description:
|
||||
* This section contains functions to quickly extract advance values
|
||||
* without handling glyph outlines, if possible.
|
||||
*
|
||||
* @order:
|
||||
* FT_Get_Advance
|
||||
* FT_Get_Advances
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @enum:
|
||||
* FT_ADVANCE_FLAG_FAST_ONLY
|
||||
*
|
||||
* @description:
|
||||
* A bit-flag to be OR-ed with the `flags` parameter of the
|
||||
* @FT_Get_Advance and @FT_Get_Advances functions.
|
||||
*
|
||||
* If set, it indicates that you want these functions to fail if the
|
||||
* corresponding hinting mode or font driver doesn't allow for very quick
|
||||
* advance computation.
|
||||
*
|
||||
* Typically, glyphs that are either unscaled, unhinted, bitmapped, or
|
||||
* light-hinted can have their advance width computed very quickly.
|
||||
*
|
||||
* Normal and bytecode hinted modes that require loading, scaling, and
|
||||
* hinting of the glyph outline, are extremely slow by comparison.
|
||||
*/
|
||||
#define FT_ADVANCE_FLAG_FAST_ONLY 0x20000000L
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Get_Advance
|
||||
*
|
||||
* @description:
|
||||
* Retrieve the advance value of a given glyph outline in an @FT_Face.
|
||||
*
|
||||
* @input:
|
||||
* face ::
|
||||
* The source @FT_Face handle.
|
||||
*
|
||||
* gindex ::
|
||||
* The glyph index.
|
||||
*
|
||||
* load_flags ::
|
||||
* A set of bit flags similar to those used when calling
|
||||
* @FT_Load_Glyph, used to determine what kind of advances you need.
|
||||
*
|
||||
* @output:
|
||||
* padvance ::
|
||||
* The advance value. If scaling is performed (based on the value of
|
||||
* `load_flags`), the advance value is in 16.16 format. Otherwise, it
|
||||
* is in font units.
|
||||
*
|
||||
* If @FT_LOAD_VERTICAL_LAYOUT is set, this is the vertical advance
|
||||
* corresponding to a vertical layout. Otherwise, it is the horizontal
|
||||
* advance in a horizontal layout.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0 means success.
|
||||
*
|
||||
* @note:
|
||||
* This function may fail if you use @FT_ADVANCE_FLAG_FAST_ONLY and if
|
||||
* the corresponding font backend doesn't have a quick way to retrieve
|
||||
* the advances.
|
||||
*
|
||||
* A scaled advance is returned in 16.16 format but isn't transformed by
|
||||
* the affine transformation specified by @FT_Set_Transform.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Get_Advance( FT_Face face,
|
||||
FT_UInt gindex,
|
||||
FT_Int32 load_flags,
|
||||
FT_Fixed *padvance );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Get_Advances
|
||||
*
|
||||
* @description:
|
||||
* Retrieve the advance values of several glyph outlines in an @FT_Face.
|
||||
*
|
||||
* @input:
|
||||
* face ::
|
||||
* The source @FT_Face handle.
|
||||
*
|
||||
* start ::
|
||||
* The first glyph index.
|
||||
*
|
||||
* count ::
|
||||
* The number of advance values you want to retrieve.
|
||||
*
|
||||
* load_flags ::
|
||||
* A set of bit flags similar to those used when calling
|
||||
* @FT_Load_Glyph.
|
||||
*
|
||||
* @output:
|
||||
* padvance ::
|
||||
* The advance values. This array, to be provided by the caller, must
|
||||
* contain at least `count` elements.
|
||||
*
|
||||
* If scaling is performed (based on the value of `load_flags`), the
|
||||
* advance values are in 16.16 format. Otherwise, they are in font
|
||||
* units.
|
||||
*
|
||||
* If @FT_LOAD_VERTICAL_LAYOUT is set, these are the vertical advances
|
||||
* corresponding to a vertical layout. Otherwise, they are the
|
||||
* horizontal advances in a horizontal layout.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0 means success.
|
||||
*
|
||||
* @note:
|
||||
* This function may fail if you use @FT_ADVANCE_FLAG_FAST_ONLY and if
|
||||
* the corresponding font backend doesn't have a quick way to retrieve
|
||||
* the advances.
|
||||
*
|
||||
* Scaled advances are returned in 16.16 format but aren't transformed by
|
||||
* the affine transformation specified by @FT_Set_Transform.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Get_Advances( FT_Face face,
|
||||
FT_UInt start,
|
||||
FT_UInt count,
|
||||
FT_Int32 load_flags,
|
||||
FT_Fixed *padvances );
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* FTADVANC_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
101
vendor/freetype/include/freetype/ftbbox.h
vendored
Normal file
101
vendor/freetype/include/freetype/ftbbox.h
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftbbox.h
|
||||
*
|
||||
* FreeType exact bbox computation (specification).
|
||||
*
|
||||
* Copyright (C) 1996-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* This component has a _single_ role: to compute exact outline bounding
|
||||
* boxes.
|
||||
*
|
||||
* It is separated from the rest of the engine for various technical
|
||||
* reasons. It may well be integrated in 'ftoutln' later.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FTBBOX_H_
|
||||
#define FTBBOX_H_
|
||||
|
||||
|
||||
#include <freetype/freetype.h>
|
||||
|
||||
#ifdef FREETYPE_H
|
||||
#error "freetype.h of FreeType 1 has been loaded!"
|
||||
#error "Please fix the directory search order for header files"
|
||||
#error "so that freetype.h of FreeType 2 is found first."
|
||||
#endif
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* outline_processing
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Outline_Get_BBox
|
||||
*
|
||||
* @description:
|
||||
* Compute the exact bounding box of an outline. This is slower than
|
||||
* computing the control box. However, it uses an advanced algorithm
|
||||
* that returns _very_ quickly when the two boxes coincide. Otherwise,
|
||||
* the outline Bezier arcs are traversed to extract their extrema.
|
||||
*
|
||||
* @input:
|
||||
* outline ::
|
||||
* A pointer to the source outline.
|
||||
*
|
||||
* @output:
|
||||
* abbox ::
|
||||
* The outline's exact bounding box.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* If the font is tricky and the glyph has been loaded with
|
||||
* @FT_LOAD_NO_SCALE, the resulting BBox is meaningless. To get
|
||||
* reasonable values for the BBox it is necessary to load the glyph at a
|
||||
* large ppem value (so that the hinting instructions can properly shift
|
||||
* and scale the subglyphs), then extracting the BBox, which can be
|
||||
* eventually converted back to font units.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Outline_Get_BBox( FT_Outline* outline,
|
||||
FT_BBox *abbox );
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* FTBBOX_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
|
||||
|
||||
/* Local Variables: */
|
||||
/* coding: utf-8 */
|
||||
/* End: */
|
||||
212
vendor/freetype/include/freetype/ftbdf.h
vendored
Normal file
212
vendor/freetype/include/freetype/ftbdf.h
vendored
Normal file
@@ -0,0 +1,212 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftbdf.h
|
||||
*
|
||||
* FreeType API for accessing BDF-specific strings (specification).
|
||||
*
|
||||
* Copyright (C) 2002-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FTBDF_H_
|
||||
#define FTBDF_H_
|
||||
|
||||
#include <freetype/freetype.h>
|
||||
|
||||
#ifdef FREETYPE_H
|
||||
#error "freetype.h of FreeType 1 has been loaded!"
|
||||
#error "Please fix the directory search order for header files"
|
||||
#error "so that freetype.h of FreeType 2 is found first."
|
||||
#endif
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* bdf_fonts
|
||||
*
|
||||
* @title:
|
||||
* BDF and PCF Files
|
||||
*
|
||||
* @abstract:
|
||||
* BDF and PCF specific API.
|
||||
*
|
||||
* @description:
|
||||
* This section contains the declaration of functions specific to BDF and
|
||||
* PCF fonts.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @enum:
|
||||
* BDF_PropertyType
|
||||
*
|
||||
* @description:
|
||||
* A list of BDF property types.
|
||||
*
|
||||
* @values:
|
||||
* BDF_PROPERTY_TYPE_NONE ::
|
||||
* Value~0 is used to indicate a missing property.
|
||||
*
|
||||
* BDF_PROPERTY_TYPE_ATOM ::
|
||||
* Property is a string atom.
|
||||
*
|
||||
* BDF_PROPERTY_TYPE_INTEGER ::
|
||||
* Property is a 32-bit signed integer.
|
||||
*
|
||||
* BDF_PROPERTY_TYPE_CARDINAL ::
|
||||
* Property is a 32-bit unsigned integer.
|
||||
*/
|
||||
typedef enum BDF_PropertyType_
|
||||
{
|
||||
BDF_PROPERTY_TYPE_NONE = 0,
|
||||
BDF_PROPERTY_TYPE_ATOM = 1,
|
||||
BDF_PROPERTY_TYPE_INTEGER = 2,
|
||||
BDF_PROPERTY_TYPE_CARDINAL = 3
|
||||
|
||||
} BDF_PropertyType;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @type:
|
||||
* BDF_Property
|
||||
*
|
||||
* @description:
|
||||
* A handle to a @BDF_PropertyRec structure to model a given BDF/PCF
|
||||
* property.
|
||||
*/
|
||||
typedef struct BDF_PropertyRec_* BDF_Property;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @struct:
|
||||
* BDF_PropertyRec
|
||||
*
|
||||
* @description:
|
||||
* This structure models a given BDF/PCF property.
|
||||
*
|
||||
* @fields:
|
||||
* type ::
|
||||
* The property type.
|
||||
*
|
||||
* u.atom ::
|
||||
* The atom string, if type is @BDF_PROPERTY_TYPE_ATOM. May be
|
||||
* `NULL`, indicating an empty string.
|
||||
*
|
||||
* u.integer ::
|
||||
* A signed integer, if type is @BDF_PROPERTY_TYPE_INTEGER.
|
||||
*
|
||||
* u.cardinal ::
|
||||
* An unsigned integer, if type is @BDF_PROPERTY_TYPE_CARDINAL.
|
||||
*/
|
||||
typedef struct BDF_PropertyRec_
|
||||
{
|
||||
BDF_PropertyType type;
|
||||
union {
|
||||
const char* atom;
|
||||
FT_Int32 integer;
|
||||
FT_UInt32 cardinal;
|
||||
|
||||
} u;
|
||||
|
||||
} BDF_PropertyRec;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Get_BDF_Charset_ID
|
||||
*
|
||||
* @description:
|
||||
* Retrieve a BDF font character set identity, according to the BDF
|
||||
* specification.
|
||||
*
|
||||
* @input:
|
||||
* face ::
|
||||
* A handle to the input face.
|
||||
*
|
||||
* @output:
|
||||
* acharset_encoding ::
|
||||
* Charset encoding, as a C~string, owned by the face.
|
||||
*
|
||||
* acharset_registry ::
|
||||
* Charset registry, as a C~string, owned by the face.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* This function only works with BDF faces, returning an error otherwise.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Get_BDF_Charset_ID( FT_Face face,
|
||||
const char* *acharset_encoding,
|
||||
const char* *acharset_registry );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Get_BDF_Property
|
||||
*
|
||||
* @description:
|
||||
* Retrieve a BDF property from a BDF or PCF font file.
|
||||
*
|
||||
* @input:
|
||||
* face ::
|
||||
* A handle to the input face.
|
||||
*
|
||||
* name ::
|
||||
* The property name.
|
||||
*
|
||||
* @output:
|
||||
* aproperty ::
|
||||
* The property.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* This function works with BDF _and_ PCF fonts. It returns an error
|
||||
* otherwise. It also returns an error if the property is not in the
|
||||
* font.
|
||||
*
|
||||
* A 'property' is a either key-value pair within the STARTPROPERTIES
|
||||
* ... ENDPROPERTIES block of a BDF font or a key-value pair from the
|
||||
* `info->props` array within a `FontRec` structure of a PCF font.
|
||||
*
|
||||
* Integer properties are always stored as 'signed' within PCF fonts;
|
||||
* consequently, @BDF_PROPERTY_TYPE_CARDINAL is a possible return value
|
||||
* for BDF fonts only.
|
||||
*
|
||||
* In case of error, `aproperty->type` is always set to
|
||||
* @BDF_PROPERTY_TYPE_NONE.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Get_BDF_Property( FT_Face face,
|
||||
const char* prop_name,
|
||||
BDF_PropertyRec *aproperty );
|
||||
|
||||
/* */
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* FTBDF_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
329
vendor/freetype/include/freetype/ftbitmap.h
vendored
Normal file
329
vendor/freetype/include/freetype/ftbitmap.h
vendored
Normal file
@@ -0,0 +1,329 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftbitmap.h
|
||||
*
|
||||
* FreeType utility functions for bitmaps (specification).
|
||||
*
|
||||
* Copyright (C) 2004-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FTBITMAP_H_
|
||||
#define FTBITMAP_H_
|
||||
|
||||
|
||||
#include <freetype/freetype.h>
|
||||
#include <freetype/ftcolor.h>
|
||||
|
||||
#ifdef FREETYPE_H
|
||||
#error "freetype.h of FreeType 1 has been loaded!"
|
||||
#error "Please fix the directory search order for header files"
|
||||
#error "so that freetype.h of FreeType 2 is found first."
|
||||
#endif
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* bitmap_handling
|
||||
*
|
||||
* @title:
|
||||
* Bitmap Handling
|
||||
*
|
||||
* @abstract:
|
||||
* Handling FT_Bitmap objects.
|
||||
*
|
||||
* @description:
|
||||
* This section contains functions for handling @FT_Bitmap objects,
|
||||
* automatically adjusting the target's bitmap buffer size as needed.
|
||||
*
|
||||
* Note that none of the functions changes the bitmap's 'flow' (as
|
||||
* indicated by the sign of the `pitch` field in @FT_Bitmap).
|
||||
*
|
||||
* To set the flow, assign an appropriate positive or negative value to
|
||||
* the `pitch` field of the target @FT_Bitmap object after calling
|
||||
* @FT_Bitmap_Init but before calling any of the other functions
|
||||
* described here.
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Bitmap_Init
|
||||
*
|
||||
* @description:
|
||||
* Initialize a pointer to an @FT_Bitmap structure.
|
||||
*
|
||||
* @inout:
|
||||
* abitmap ::
|
||||
* A pointer to the bitmap structure.
|
||||
*
|
||||
* @note:
|
||||
* A deprecated name for the same function is `FT_Bitmap_New`.
|
||||
*/
|
||||
FT_EXPORT( void )
|
||||
FT_Bitmap_Init( FT_Bitmap *abitmap );
|
||||
|
||||
|
||||
/* deprecated */
|
||||
FT_EXPORT( void )
|
||||
FT_Bitmap_New( FT_Bitmap *abitmap );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Bitmap_Copy
|
||||
*
|
||||
* @description:
|
||||
* Copy a bitmap into another one.
|
||||
*
|
||||
* @input:
|
||||
* library ::
|
||||
* A handle to a library object.
|
||||
*
|
||||
* source ::
|
||||
* A handle to the source bitmap.
|
||||
*
|
||||
* @output:
|
||||
* target ::
|
||||
* A handle to the target bitmap.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* `source->buffer` and `target->buffer` must neither be equal nor
|
||||
* overlap.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Bitmap_Copy( FT_Library library,
|
||||
const FT_Bitmap *source,
|
||||
FT_Bitmap *target );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Bitmap_Embolden
|
||||
*
|
||||
* @description:
|
||||
* Embolden a bitmap. The new bitmap will be about `xStrength` pixels
|
||||
* wider and `yStrength` pixels higher. The left and bottom borders are
|
||||
* kept unchanged.
|
||||
*
|
||||
* @input:
|
||||
* library ::
|
||||
* A handle to a library object.
|
||||
*
|
||||
* xStrength ::
|
||||
* How strong the glyph is emboldened horizontally. Expressed in 26.6
|
||||
* pixel format.
|
||||
*
|
||||
* yStrength ::
|
||||
* How strong the glyph is emboldened vertically. Expressed in 26.6
|
||||
* pixel format.
|
||||
*
|
||||
* @inout:
|
||||
* bitmap ::
|
||||
* A handle to the target bitmap.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* The current implementation restricts `xStrength` to be less than or
|
||||
* equal to~8 if bitmap is of pixel_mode @FT_PIXEL_MODE_MONO.
|
||||
*
|
||||
* If you want to embolden the bitmap owned by a @FT_GlyphSlotRec, you
|
||||
* should call @FT_GlyphSlot_Own_Bitmap on the slot first.
|
||||
*
|
||||
* Bitmaps in @FT_PIXEL_MODE_GRAY2 and @FT_PIXEL_MODE_GRAY@ format are
|
||||
* converted to @FT_PIXEL_MODE_GRAY format (i.e., 8bpp).
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Bitmap_Embolden( FT_Library library,
|
||||
FT_Bitmap* bitmap,
|
||||
FT_Pos xStrength,
|
||||
FT_Pos yStrength );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Bitmap_Convert
|
||||
*
|
||||
* @description:
|
||||
* Convert a bitmap object with depth 1bpp, 2bpp, 4bpp, 8bpp or 32bpp to
|
||||
* a bitmap object with depth 8bpp, making the number of used bytes per
|
||||
* line (a.k.a. the 'pitch') a multiple of `alignment`.
|
||||
*
|
||||
* @input:
|
||||
* library ::
|
||||
* A handle to a library object.
|
||||
*
|
||||
* source ::
|
||||
* The source bitmap.
|
||||
*
|
||||
* alignment ::
|
||||
* The pitch of the bitmap is a multiple of this argument. Common
|
||||
* values are 1, 2, or 4.
|
||||
*
|
||||
* @output:
|
||||
* target ::
|
||||
* The target bitmap.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* It is possible to call @FT_Bitmap_Convert multiple times without
|
||||
* calling @FT_Bitmap_Done (the memory is simply reallocated).
|
||||
*
|
||||
* Use @FT_Bitmap_Done to finally remove the bitmap object.
|
||||
*
|
||||
* The `library` argument is taken to have access to FreeType's memory
|
||||
* handling functions.
|
||||
*
|
||||
* `source->buffer` and `target->buffer` must neither be equal nor
|
||||
* overlap.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Bitmap_Convert( FT_Library library,
|
||||
const FT_Bitmap *source,
|
||||
FT_Bitmap *target,
|
||||
FT_Int alignment );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Bitmap_Blend
|
||||
*
|
||||
* @description:
|
||||
* Blend a bitmap onto another bitmap, using a given color.
|
||||
*
|
||||
* @input:
|
||||
* library ::
|
||||
* A handle to a library object.
|
||||
*
|
||||
* source ::
|
||||
* The source bitmap, which can have any @FT_Pixel_Mode format.
|
||||
*
|
||||
* source_offset ::
|
||||
* The offset vector to the upper left corner of the source bitmap in
|
||||
* 26.6 pixel format. It should represent an integer offset; the
|
||||
* function will set the lowest six bits to zero to enforce that.
|
||||
*
|
||||
* color ::
|
||||
* The color used to draw `source` onto `target`.
|
||||
*
|
||||
* @inout:
|
||||
* target ::
|
||||
* A handle to an `FT_Bitmap` object. It should be either initialized
|
||||
* as empty with a call to @FT_Bitmap_Init, or it should be of type
|
||||
* @FT_PIXEL_MODE_BGRA.
|
||||
*
|
||||
* atarget_offset ::
|
||||
* The offset vector to the upper left corner of the target bitmap in
|
||||
* 26.6 pixel format. It should represent an integer offset; the
|
||||
* function will set the lowest six bits to zero to enforce that.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* This function doesn't perform clipping.
|
||||
*
|
||||
* The bitmap in `target` gets allocated or reallocated as needed; the
|
||||
* vector `atarget_offset` is updated accordingly.
|
||||
*
|
||||
* In case of allocation or reallocation, the bitmap's pitch is set to
|
||||
* `4 * width`. Both `source` and `target` must have the same bitmap
|
||||
* flow (as indicated by the sign of the `pitch` field).
|
||||
*
|
||||
* `source->buffer` and `target->buffer` must neither be equal nor
|
||||
* overlap.
|
||||
*
|
||||
* @since:
|
||||
* 2.10
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Bitmap_Blend( FT_Library library,
|
||||
const FT_Bitmap* source,
|
||||
const FT_Vector source_offset,
|
||||
FT_Bitmap* target,
|
||||
FT_Vector *atarget_offset,
|
||||
FT_Color color );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_GlyphSlot_Own_Bitmap
|
||||
*
|
||||
* @description:
|
||||
* Make sure that a glyph slot owns `slot->bitmap`.
|
||||
*
|
||||
* @input:
|
||||
* slot ::
|
||||
* The glyph slot.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* This function is to be used in combination with @FT_Bitmap_Embolden.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_GlyphSlot_Own_Bitmap( FT_GlyphSlot slot );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Bitmap_Done
|
||||
*
|
||||
* @description:
|
||||
* Destroy a bitmap object initialized with @FT_Bitmap_Init.
|
||||
*
|
||||
* @input:
|
||||
* library ::
|
||||
* A handle to a library object.
|
||||
*
|
||||
* bitmap ::
|
||||
* The bitmap object to be freed.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* The `library` argument is taken to have access to FreeType's memory
|
||||
* handling functions.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Bitmap_Done( FT_Library library,
|
||||
FT_Bitmap *bitmap );
|
||||
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* FTBITMAP_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
102
vendor/freetype/include/freetype/ftbzip2.h
vendored
Normal file
102
vendor/freetype/include/freetype/ftbzip2.h
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftbzip2.h
|
||||
*
|
||||
* Bzip2-compressed stream support.
|
||||
*
|
||||
* Copyright (C) 2010-2024 by
|
||||
* Joel Klinghed.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FTBZIP2_H_
|
||||
#define FTBZIP2_H_
|
||||
|
||||
#include <freetype/freetype.h>
|
||||
|
||||
#ifdef FREETYPE_H
|
||||
#error "freetype.h of FreeType 1 has been loaded!"
|
||||
#error "Please fix the directory search order for header files"
|
||||
#error "so that freetype.h of FreeType 2 is found first."
|
||||
#endif
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* bzip2
|
||||
*
|
||||
* @title:
|
||||
* BZIP2 Streams
|
||||
*
|
||||
* @abstract:
|
||||
* Using bzip2-compressed font files.
|
||||
*
|
||||
* @description:
|
||||
* In certain builds of the library, bzip2 compression recognition is
|
||||
* automatically handled when calling @FT_New_Face or @FT_Open_Face.
|
||||
* This means that if no font driver is capable of handling the raw
|
||||
* compressed file, the library will try to open a bzip2 compressed
|
||||
* stream from it and re-open the face with it.
|
||||
*
|
||||
* The stream implementation is very basic and resets the decompression
|
||||
* process each time seeking backwards is needed within the stream,
|
||||
* which significantly undermines the performance.
|
||||
*
|
||||
* This section contains the declaration of Bzip2-specific functions.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Stream_OpenBzip2
|
||||
*
|
||||
* @description:
|
||||
* Open a new stream to parse bzip2-compressed font files. This is
|
||||
* mainly used to support the compressed `*.pcf.bz2` fonts that come with
|
||||
* XFree86.
|
||||
*
|
||||
* @input:
|
||||
* stream ::
|
||||
* The target embedding stream.
|
||||
*
|
||||
* source ::
|
||||
* The source stream.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* The source stream must be opened _before_ calling this function.
|
||||
*
|
||||
* Calling the internal function `FT_Stream_Close` on the new stream will
|
||||
* **not** call `FT_Stream_Close` on the source stream. None of the
|
||||
* stream objects will be released to the heap.
|
||||
*
|
||||
* This function may return `FT_Err_Unimplemented_Feature` if your build
|
||||
* of FreeType was not compiled with bzip2 support.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Stream_OpenBzip2( FT_Stream stream,
|
||||
FT_Stream source );
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* FTBZIP2_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
1087
vendor/freetype/include/freetype/ftcache.h
vendored
Normal file
1087
vendor/freetype/include/freetype/ftcache.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
168
vendor/freetype/include/freetype/ftchapters.h
vendored
Normal file
168
vendor/freetype/include/freetype/ftchapters.h
vendored
Normal file
@@ -0,0 +1,168 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* This file defines the structure of the FreeType reference.
|
||||
* It is used by the python script that generates the HTML files.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @chapter:
|
||||
* general_remarks
|
||||
*
|
||||
* @title:
|
||||
* General Remarks
|
||||
*
|
||||
* @sections:
|
||||
* preamble
|
||||
* header_inclusion
|
||||
* user_allocation
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @chapter:
|
||||
* core_api
|
||||
*
|
||||
* @title:
|
||||
* Core API
|
||||
*
|
||||
* @sections:
|
||||
* basic_types
|
||||
* library_setup
|
||||
* face_creation
|
||||
* font_testing_macros
|
||||
* sizing_and_scaling
|
||||
* glyph_retrieval
|
||||
* character_mapping
|
||||
* information_retrieval
|
||||
* other_api_data
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @chapter:
|
||||
* extended_api
|
||||
*
|
||||
* @title:
|
||||
* Extended API
|
||||
*
|
||||
* @sections:
|
||||
* glyph_variants
|
||||
* color_management
|
||||
* layer_management
|
||||
* glyph_management
|
||||
* mac_specific
|
||||
* sizes_management
|
||||
* header_file_macros
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @chapter:
|
||||
* format_specific
|
||||
*
|
||||
* @title:
|
||||
* Format-Specific API
|
||||
*
|
||||
* @sections:
|
||||
* multiple_masters
|
||||
* truetype_tables
|
||||
* type1_tables
|
||||
* sfnt_names
|
||||
* bdf_fonts
|
||||
* cid_fonts
|
||||
* pfr_fonts
|
||||
* winfnt_fonts
|
||||
* svg_fonts
|
||||
* font_formats
|
||||
* gasp_table
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @chapter:
|
||||
* module_specific
|
||||
*
|
||||
* @title:
|
||||
* Controlling FreeType Modules
|
||||
*
|
||||
* @sections:
|
||||
* auto_hinter
|
||||
* cff_driver
|
||||
* t1_cid_driver
|
||||
* tt_driver
|
||||
* pcf_driver
|
||||
* ot_svg_driver
|
||||
* properties
|
||||
* parameter_tags
|
||||
* lcd_rendering
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @chapter:
|
||||
* cache_subsystem
|
||||
*
|
||||
* @title:
|
||||
* Cache Sub-System
|
||||
*
|
||||
* @sections:
|
||||
* cache_subsystem
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @chapter:
|
||||
* support_api
|
||||
*
|
||||
* @title:
|
||||
* Support API
|
||||
*
|
||||
* @sections:
|
||||
* computations
|
||||
* list_processing
|
||||
* outline_processing
|
||||
* quick_advance
|
||||
* bitmap_handling
|
||||
* raster
|
||||
* glyph_stroker
|
||||
* system_interface
|
||||
* module_management
|
||||
* gzip
|
||||
* lzw
|
||||
* bzip2
|
||||
* debugging_apis
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @chapter:
|
||||
* error_codes
|
||||
*
|
||||
* @title:
|
||||
* Error Codes
|
||||
*
|
||||
* @sections:
|
||||
* error_enumerations
|
||||
* error_code_values
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* END */
|
||||
167
vendor/freetype/include/freetype/ftcid.h
vendored
Normal file
167
vendor/freetype/include/freetype/ftcid.h
vendored
Normal file
@@ -0,0 +1,167 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftcid.h
|
||||
*
|
||||
* FreeType API for accessing CID font information (specification).
|
||||
*
|
||||
* Copyright (C) 2007-2024 by
|
||||
* Dereg Clegg and Michael Toftdal.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FTCID_H_
|
||||
#define FTCID_H_
|
||||
|
||||
#include <freetype/freetype.h>
|
||||
|
||||
#ifdef FREETYPE_H
|
||||
#error "freetype.h of FreeType 1 has been loaded!"
|
||||
#error "Please fix the directory search order for header files"
|
||||
#error "so that freetype.h of FreeType 2 is found first."
|
||||
#endif
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* cid_fonts
|
||||
*
|
||||
* @title:
|
||||
* CID Fonts
|
||||
*
|
||||
* @abstract:
|
||||
* CID-keyed font-specific API.
|
||||
*
|
||||
* @description:
|
||||
* This section contains the declaration of CID-keyed font-specific
|
||||
* functions.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Get_CID_Registry_Ordering_Supplement
|
||||
*
|
||||
* @description:
|
||||
* Retrieve the Registry/Ordering/Supplement triple (also known as the
|
||||
* "R/O/S") from a CID-keyed font.
|
||||
*
|
||||
* @input:
|
||||
* face ::
|
||||
* A handle to the input face.
|
||||
*
|
||||
* @output:
|
||||
* registry ::
|
||||
* The registry, as a C~string, owned by the face.
|
||||
*
|
||||
* ordering ::
|
||||
* The ordering, as a C~string, owned by the face.
|
||||
*
|
||||
* supplement ::
|
||||
* The supplement.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* This function only works with CID faces, returning an error
|
||||
* otherwise.
|
||||
*
|
||||
* @since:
|
||||
* 2.3.6
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Get_CID_Registry_Ordering_Supplement( FT_Face face,
|
||||
const char* *registry,
|
||||
const char* *ordering,
|
||||
FT_Int *supplement );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Get_CID_Is_Internally_CID_Keyed
|
||||
*
|
||||
* @description:
|
||||
* Retrieve the type of the input face, CID keyed or not. In contrast
|
||||
* to the @FT_IS_CID_KEYED macro this function returns successfully also
|
||||
* for CID-keyed fonts in an SFNT wrapper.
|
||||
*
|
||||
* @input:
|
||||
* face ::
|
||||
* A handle to the input face.
|
||||
*
|
||||
* @output:
|
||||
* is_cid ::
|
||||
* The type of the face as an @FT_Bool.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* This function only works with CID faces and OpenType fonts, returning
|
||||
* an error otherwise.
|
||||
*
|
||||
* @since:
|
||||
* 2.3.9
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Get_CID_Is_Internally_CID_Keyed( FT_Face face,
|
||||
FT_Bool *is_cid );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Get_CID_From_Glyph_Index
|
||||
*
|
||||
* @description:
|
||||
* Retrieve the CID of the input glyph index.
|
||||
*
|
||||
* @input:
|
||||
* face ::
|
||||
* A handle to the input face.
|
||||
*
|
||||
* glyph_index ::
|
||||
* The input glyph index.
|
||||
*
|
||||
* @output:
|
||||
* cid ::
|
||||
* The CID as an @FT_UInt.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* This function only works with CID faces and OpenType fonts, returning
|
||||
* an error otherwise.
|
||||
*
|
||||
* @since:
|
||||
* 2.3.9
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Get_CID_From_Glyph_Index( FT_Face face,
|
||||
FT_UInt glyph_index,
|
||||
FT_UInt *cid );
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* FTCID_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
1667
vendor/freetype/include/freetype/ftcolor.h
vendored
Normal file
1667
vendor/freetype/include/freetype/ftcolor.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1320
vendor/freetype/include/freetype/ftdriver.h
vendored
Normal file
1320
vendor/freetype/include/freetype/ftdriver.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
283
vendor/freetype/include/freetype/fterrdef.h
vendored
Normal file
283
vendor/freetype/include/freetype/fterrdef.h
vendored
Normal file
@@ -0,0 +1,283 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* fterrdef.h
|
||||
*
|
||||
* FreeType error codes (specification).
|
||||
*
|
||||
* Copyright (C) 2002-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* error_code_values
|
||||
*
|
||||
* @title:
|
||||
* Error Code Values
|
||||
*
|
||||
* @abstract:
|
||||
* All possible error codes returned by FreeType functions.
|
||||
*
|
||||
* @description:
|
||||
* The list below is taken verbatim from the file `fterrdef.h` (loaded
|
||||
* automatically by including `FT_FREETYPE_H`). The first argument of the
|
||||
* `FT_ERROR_DEF_` macro is the error label; by default, the prefix
|
||||
* `FT_Err_` gets added so that you get error names like
|
||||
* `FT_Err_Cannot_Open_Resource`. The second argument is the error code,
|
||||
* and the last argument an error string, which is not used by FreeType.
|
||||
*
|
||||
* Within your application you should **only** use error names and
|
||||
* **never** its numeric values! The latter might (and actually do)
|
||||
* change in forthcoming FreeType versions.
|
||||
*
|
||||
* Macro `FT_NOERRORDEF_` defines `FT_Err_Ok`, which is always zero. See
|
||||
* the 'Error Enumerations' subsection how to automatically generate a
|
||||
* list of error strings.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @enum:
|
||||
* FT_Err_XXX
|
||||
*
|
||||
*/
|
||||
|
||||
/* generic errors */
|
||||
|
||||
FT_NOERRORDEF_( Ok, 0x00,
|
||||
"no error" )
|
||||
|
||||
FT_ERRORDEF_( Cannot_Open_Resource, 0x01,
|
||||
"cannot open resource" )
|
||||
FT_ERRORDEF_( Unknown_File_Format, 0x02,
|
||||
"unknown file format" )
|
||||
FT_ERRORDEF_( Invalid_File_Format, 0x03,
|
||||
"broken file" )
|
||||
FT_ERRORDEF_( Invalid_Version, 0x04,
|
||||
"invalid FreeType version" )
|
||||
FT_ERRORDEF_( Lower_Module_Version, 0x05,
|
||||
"module version is too low" )
|
||||
FT_ERRORDEF_( Invalid_Argument, 0x06,
|
||||
"invalid argument" )
|
||||
FT_ERRORDEF_( Unimplemented_Feature, 0x07,
|
||||
"unimplemented feature" )
|
||||
FT_ERRORDEF_( Invalid_Table, 0x08,
|
||||
"broken table" )
|
||||
FT_ERRORDEF_( Invalid_Offset, 0x09,
|
||||
"broken offset within table" )
|
||||
FT_ERRORDEF_( Array_Too_Large, 0x0A,
|
||||
"array allocation size too large" )
|
||||
FT_ERRORDEF_( Missing_Module, 0x0B,
|
||||
"missing module" )
|
||||
FT_ERRORDEF_( Missing_Property, 0x0C,
|
||||
"missing property" )
|
||||
|
||||
/* glyph/character errors */
|
||||
|
||||
FT_ERRORDEF_( Invalid_Glyph_Index, 0x10,
|
||||
"invalid glyph index" )
|
||||
FT_ERRORDEF_( Invalid_Character_Code, 0x11,
|
||||
"invalid character code" )
|
||||
FT_ERRORDEF_( Invalid_Glyph_Format, 0x12,
|
||||
"unsupported glyph image format" )
|
||||
FT_ERRORDEF_( Cannot_Render_Glyph, 0x13,
|
||||
"cannot render this glyph format" )
|
||||
FT_ERRORDEF_( Invalid_Outline, 0x14,
|
||||
"invalid outline" )
|
||||
FT_ERRORDEF_( Invalid_Composite, 0x15,
|
||||
"invalid composite glyph" )
|
||||
FT_ERRORDEF_( Too_Many_Hints, 0x16,
|
||||
"too many hints" )
|
||||
FT_ERRORDEF_( Invalid_Pixel_Size, 0x17,
|
||||
"invalid pixel size" )
|
||||
FT_ERRORDEF_( Invalid_SVG_Document, 0x18,
|
||||
"invalid SVG document" )
|
||||
|
||||
/* handle errors */
|
||||
|
||||
FT_ERRORDEF_( Invalid_Handle, 0x20,
|
||||
"invalid object handle" )
|
||||
FT_ERRORDEF_( Invalid_Library_Handle, 0x21,
|
||||
"invalid library handle" )
|
||||
FT_ERRORDEF_( Invalid_Driver_Handle, 0x22,
|
||||
"invalid module handle" )
|
||||
FT_ERRORDEF_( Invalid_Face_Handle, 0x23,
|
||||
"invalid face handle" )
|
||||
FT_ERRORDEF_( Invalid_Size_Handle, 0x24,
|
||||
"invalid size handle" )
|
||||
FT_ERRORDEF_( Invalid_Slot_Handle, 0x25,
|
||||
"invalid glyph slot handle" )
|
||||
FT_ERRORDEF_( Invalid_CharMap_Handle, 0x26,
|
||||
"invalid charmap handle" )
|
||||
FT_ERRORDEF_( Invalid_Cache_Handle, 0x27,
|
||||
"invalid cache manager handle" )
|
||||
FT_ERRORDEF_( Invalid_Stream_Handle, 0x28,
|
||||
"invalid stream handle" )
|
||||
|
||||
/* driver errors */
|
||||
|
||||
FT_ERRORDEF_( Too_Many_Drivers, 0x30,
|
||||
"too many modules" )
|
||||
FT_ERRORDEF_( Too_Many_Extensions, 0x31,
|
||||
"too many extensions" )
|
||||
|
||||
/* memory errors */
|
||||
|
||||
FT_ERRORDEF_( Out_Of_Memory, 0x40,
|
||||
"out of memory" )
|
||||
FT_ERRORDEF_( Unlisted_Object, 0x41,
|
||||
"unlisted object" )
|
||||
|
||||
/* stream errors */
|
||||
|
||||
FT_ERRORDEF_( Cannot_Open_Stream, 0x51,
|
||||
"cannot open stream" )
|
||||
FT_ERRORDEF_( Invalid_Stream_Seek, 0x52,
|
||||
"invalid stream seek" )
|
||||
FT_ERRORDEF_( Invalid_Stream_Skip, 0x53,
|
||||
"invalid stream skip" )
|
||||
FT_ERRORDEF_( Invalid_Stream_Read, 0x54,
|
||||
"invalid stream read" )
|
||||
FT_ERRORDEF_( Invalid_Stream_Operation, 0x55,
|
||||
"invalid stream operation" )
|
||||
FT_ERRORDEF_( Invalid_Frame_Operation, 0x56,
|
||||
"invalid frame operation" )
|
||||
FT_ERRORDEF_( Nested_Frame_Access, 0x57,
|
||||
"nested frame access" )
|
||||
FT_ERRORDEF_( Invalid_Frame_Read, 0x58,
|
||||
"invalid frame read" )
|
||||
|
||||
/* raster errors */
|
||||
|
||||
FT_ERRORDEF_( Raster_Uninitialized, 0x60,
|
||||
"raster uninitialized" )
|
||||
FT_ERRORDEF_( Raster_Corrupted, 0x61,
|
||||
"raster corrupted" )
|
||||
FT_ERRORDEF_( Raster_Overflow, 0x62,
|
||||
"raster overflow" )
|
||||
FT_ERRORDEF_( Raster_Negative_Height, 0x63,
|
||||
"negative height while rastering" )
|
||||
|
||||
/* cache errors */
|
||||
|
||||
FT_ERRORDEF_( Too_Many_Caches, 0x70,
|
||||
"too many registered caches" )
|
||||
|
||||
/* TrueType and SFNT errors */
|
||||
|
||||
FT_ERRORDEF_( Invalid_Opcode, 0x80,
|
||||
"invalid opcode" )
|
||||
FT_ERRORDEF_( Too_Few_Arguments, 0x81,
|
||||
"too few arguments" )
|
||||
FT_ERRORDEF_( Stack_Overflow, 0x82,
|
||||
"stack overflow" )
|
||||
FT_ERRORDEF_( Code_Overflow, 0x83,
|
||||
"code overflow" )
|
||||
FT_ERRORDEF_( Bad_Argument, 0x84,
|
||||
"bad argument" )
|
||||
FT_ERRORDEF_( Divide_By_Zero, 0x85,
|
||||
"division by zero" )
|
||||
FT_ERRORDEF_( Invalid_Reference, 0x86,
|
||||
"invalid reference" )
|
||||
FT_ERRORDEF_( Debug_OpCode, 0x87,
|
||||
"found debug opcode" )
|
||||
FT_ERRORDEF_( ENDF_In_Exec_Stream, 0x88,
|
||||
"found ENDF opcode in execution stream" )
|
||||
FT_ERRORDEF_( Nested_DEFS, 0x89,
|
||||
"nested DEFS" )
|
||||
FT_ERRORDEF_( Invalid_CodeRange, 0x8A,
|
||||
"invalid code range" )
|
||||
FT_ERRORDEF_( Execution_Too_Long, 0x8B,
|
||||
"execution context too long" )
|
||||
FT_ERRORDEF_( Too_Many_Function_Defs, 0x8C,
|
||||
"too many function definitions" )
|
||||
FT_ERRORDEF_( Too_Many_Instruction_Defs, 0x8D,
|
||||
"too many instruction definitions" )
|
||||
FT_ERRORDEF_( Table_Missing, 0x8E,
|
||||
"SFNT font table missing" )
|
||||
FT_ERRORDEF_( Horiz_Header_Missing, 0x8F,
|
||||
"horizontal header (hhea) table missing" )
|
||||
FT_ERRORDEF_( Locations_Missing, 0x90,
|
||||
"locations (loca) table missing" )
|
||||
FT_ERRORDEF_( Name_Table_Missing, 0x91,
|
||||
"name table missing" )
|
||||
FT_ERRORDEF_( CMap_Table_Missing, 0x92,
|
||||
"character map (cmap) table missing" )
|
||||
FT_ERRORDEF_( Hmtx_Table_Missing, 0x93,
|
||||
"horizontal metrics (hmtx) table missing" )
|
||||
FT_ERRORDEF_( Post_Table_Missing, 0x94,
|
||||
"PostScript (post) table missing" )
|
||||
FT_ERRORDEF_( Invalid_Horiz_Metrics, 0x95,
|
||||
"invalid horizontal metrics" )
|
||||
FT_ERRORDEF_( Invalid_CharMap_Format, 0x96,
|
||||
"invalid character map (cmap) format" )
|
||||
FT_ERRORDEF_( Invalid_PPem, 0x97,
|
||||
"invalid ppem value" )
|
||||
FT_ERRORDEF_( Invalid_Vert_Metrics, 0x98,
|
||||
"invalid vertical metrics" )
|
||||
FT_ERRORDEF_( Could_Not_Find_Context, 0x99,
|
||||
"could not find context" )
|
||||
FT_ERRORDEF_( Invalid_Post_Table_Format, 0x9A,
|
||||
"invalid PostScript (post) table format" )
|
||||
FT_ERRORDEF_( Invalid_Post_Table, 0x9B,
|
||||
"invalid PostScript (post) table" )
|
||||
FT_ERRORDEF_( DEF_In_Glyf_Bytecode, 0x9C,
|
||||
"found FDEF or IDEF opcode in glyf bytecode" )
|
||||
FT_ERRORDEF_( Missing_Bitmap, 0x9D,
|
||||
"missing bitmap in strike" )
|
||||
FT_ERRORDEF_( Missing_SVG_Hooks, 0x9E,
|
||||
"SVG hooks have not been set" )
|
||||
|
||||
/* CFF, CID, and Type 1 errors */
|
||||
|
||||
FT_ERRORDEF_( Syntax_Error, 0xA0,
|
||||
"opcode syntax error" )
|
||||
FT_ERRORDEF_( Stack_Underflow, 0xA1,
|
||||
"argument stack underflow" )
|
||||
FT_ERRORDEF_( Ignore, 0xA2,
|
||||
"ignore" )
|
||||
FT_ERRORDEF_( No_Unicode_Glyph_Name, 0xA3,
|
||||
"no Unicode glyph name found" )
|
||||
FT_ERRORDEF_( Glyph_Too_Big, 0xA4,
|
||||
"glyph too big for hinting" )
|
||||
|
||||
/* BDF errors */
|
||||
|
||||
FT_ERRORDEF_( Missing_Startfont_Field, 0xB0,
|
||||
"`STARTFONT' field missing" )
|
||||
FT_ERRORDEF_( Missing_Font_Field, 0xB1,
|
||||
"`FONT' field missing" )
|
||||
FT_ERRORDEF_( Missing_Size_Field, 0xB2,
|
||||
"`SIZE' field missing" )
|
||||
FT_ERRORDEF_( Missing_Fontboundingbox_Field, 0xB3,
|
||||
"`FONTBOUNDINGBOX' field missing" )
|
||||
FT_ERRORDEF_( Missing_Chars_Field, 0xB4,
|
||||
"`CHARS' field missing" )
|
||||
FT_ERRORDEF_( Missing_Startchar_Field, 0xB5,
|
||||
"`STARTCHAR' field missing" )
|
||||
FT_ERRORDEF_( Missing_Encoding_Field, 0xB6,
|
||||
"`ENCODING' field missing" )
|
||||
FT_ERRORDEF_( Missing_Bbx_Field, 0xB7,
|
||||
"`BBX' field missing" )
|
||||
FT_ERRORDEF_( Bbx_Too_Big, 0xB8,
|
||||
"`BBX' too big" )
|
||||
FT_ERRORDEF_( Corrupted_Font_Header, 0xB9,
|
||||
"Font header corrupted or missing fields" )
|
||||
FT_ERRORDEF_( Corrupted_Font_Glyphs, 0xBA,
|
||||
"Font glyphs corrupted or missing fields" )
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
/* END */
|
||||
296
vendor/freetype/include/freetype/fterrors.h
vendored
Normal file
296
vendor/freetype/include/freetype/fterrors.h
vendored
Normal file
@@ -0,0 +1,296 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* fterrors.h
|
||||
*
|
||||
* FreeType error code handling (specification).
|
||||
*
|
||||
* Copyright (C) 1996-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* error_enumerations
|
||||
*
|
||||
* @title:
|
||||
* Error Enumerations
|
||||
*
|
||||
* @abstract:
|
||||
* How to handle errors and error strings.
|
||||
*
|
||||
* @description:
|
||||
* The header file `fterrors.h` (which is automatically included by
|
||||
* `freetype.h`) defines the handling of FreeType's enumeration
|
||||
* constants. It can also be used to generate error message strings
|
||||
* with a small macro trick explained below.
|
||||
*
|
||||
* **Error Formats**
|
||||
*
|
||||
* The configuration macro `FT_CONFIG_OPTION_USE_MODULE_ERRORS` can be
|
||||
* defined in `ftoption.h` in order to make the higher byte indicate the
|
||||
* module where the error has happened (this is not compatible with
|
||||
* standard builds of FreeType~2, however). See the file `ftmoderr.h`
|
||||
* for more details.
|
||||
*
|
||||
* **Error Message Strings**
|
||||
*
|
||||
* Error definitions are set up with special macros that allow client
|
||||
* applications to build a table of error message strings. The strings
|
||||
* are not included in a normal build of FreeType~2 to save space (most
|
||||
* client applications do not use them).
|
||||
*
|
||||
* To do so, you have to define the following macros before including
|
||||
* this file.
|
||||
*
|
||||
* ```
|
||||
* FT_ERROR_START_LIST
|
||||
* ```
|
||||
*
|
||||
* This macro is called before anything else to define the start of the
|
||||
* error list. It is followed by several `FT_ERROR_DEF` calls.
|
||||
*
|
||||
* ```
|
||||
* FT_ERROR_DEF( e, v, s )
|
||||
* ```
|
||||
*
|
||||
* This macro is called to define one single error. 'e' is the error
|
||||
* code identifier (e.g., `Invalid_Argument`), 'v' is the error's
|
||||
* numerical value, and 's' is the corresponding error string.
|
||||
*
|
||||
* ```
|
||||
* FT_ERROR_END_LIST
|
||||
* ```
|
||||
*
|
||||
* This macro ends the list.
|
||||
*
|
||||
* Additionally, you have to undefine `FTERRORS_H_` before #including
|
||||
* this file.
|
||||
*
|
||||
* Here is a simple example.
|
||||
*
|
||||
* ```
|
||||
* #undef FTERRORS_H_
|
||||
* #define FT_ERRORDEF( e, v, s ) { e, s },
|
||||
* #define FT_ERROR_START_LIST {
|
||||
* #define FT_ERROR_END_LIST { 0, NULL } };
|
||||
*
|
||||
* const struct
|
||||
* {
|
||||
* int err_code;
|
||||
* const char* err_msg;
|
||||
* } ft_errors[] =
|
||||
*
|
||||
* #include <freetype/fterrors.h>
|
||||
* ```
|
||||
*
|
||||
* An alternative to using an array is a switch statement.
|
||||
*
|
||||
* ```
|
||||
* #undef FTERRORS_H_
|
||||
* #define FT_ERROR_START_LIST switch ( error_code ) {
|
||||
* #define FT_ERRORDEF( e, v, s ) case v: return s;
|
||||
* #define FT_ERROR_END_LIST }
|
||||
* ```
|
||||
*
|
||||
* If you use `FT_CONFIG_OPTION_USE_MODULE_ERRORS`, `error_code` should
|
||||
* be replaced with `FT_ERROR_BASE(error_code)` in the last example.
|
||||
*/
|
||||
|
||||
/* */
|
||||
|
||||
/* In previous FreeType versions we used `__FTERRORS_H__`. However, */
|
||||
/* using two successive underscores in a non-system symbol name */
|
||||
/* violates the C (and C++) standard, so it was changed to the */
|
||||
/* current form. In spite of this, we have to make */
|
||||
/* */
|
||||
/* ``` */
|
||||
/* #undefine __FTERRORS_H__ */
|
||||
/* ``` */
|
||||
/* */
|
||||
/* work for backward compatibility. */
|
||||
/* */
|
||||
#if !( defined( FTERRORS_H_ ) && defined ( __FTERRORS_H__ ) )
|
||||
#define FTERRORS_H_
|
||||
#define __FTERRORS_H__
|
||||
|
||||
|
||||
/* include module base error codes */
|
||||
#include <freetype/ftmoderr.h>
|
||||
|
||||
|
||||
/*******************************************************************/
|
||||
/*******************************************************************/
|
||||
/***** *****/
|
||||
/***** SETUP MACROS *****/
|
||||
/***** *****/
|
||||
/*******************************************************************/
|
||||
/*******************************************************************/
|
||||
|
||||
|
||||
#undef FT_NEED_EXTERN_C
|
||||
|
||||
|
||||
/* FT_ERR_PREFIX is used as a prefix for error identifiers. */
|
||||
/* By default, we use `FT_Err_`. */
|
||||
/* */
|
||||
#ifndef FT_ERR_PREFIX
|
||||
#define FT_ERR_PREFIX FT_Err_
|
||||
#endif
|
||||
|
||||
|
||||
/* FT_ERR_BASE is used as the base for module-specific errors. */
|
||||
/* */
|
||||
#ifdef FT_CONFIG_OPTION_USE_MODULE_ERRORS
|
||||
|
||||
#ifndef FT_ERR_BASE
|
||||
#define FT_ERR_BASE FT_Mod_Err_Base
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#undef FT_ERR_BASE
|
||||
#define FT_ERR_BASE 0
|
||||
|
||||
#endif /* FT_CONFIG_OPTION_USE_MODULE_ERRORS */
|
||||
|
||||
|
||||
/* If FT_ERRORDEF is not defined, we need to define a simple */
|
||||
/* enumeration type. */
|
||||
/* */
|
||||
#ifndef FT_ERRORDEF
|
||||
|
||||
#define FT_INCLUDE_ERR_PROTOS
|
||||
|
||||
#define FT_ERRORDEF( e, v, s ) e = v,
|
||||
#define FT_ERROR_START_LIST enum {
|
||||
#define FT_ERROR_END_LIST FT_ERR_CAT( FT_ERR_PREFIX, Max ) };
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define FT_NEED_EXTERN_C
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#endif /* !FT_ERRORDEF */
|
||||
|
||||
|
||||
/* this macro is used to define an error */
|
||||
#define FT_ERRORDEF_( e, v, s ) \
|
||||
FT_ERRORDEF( FT_ERR_CAT( FT_ERR_PREFIX, e ), v + FT_ERR_BASE, s )
|
||||
|
||||
/* this is only used for <module>_Err_Ok, which must be 0! */
|
||||
#define FT_NOERRORDEF_( e, v, s ) \
|
||||
FT_ERRORDEF( FT_ERR_CAT( FT_ERR_PREFIX, e ), v, s )
|
||||
|
||||
|
||||
#ifdef FT_ERROR_START_LIST
|
||||
FT_ERROR_START_LIST
|
||||
#endif
|
||||
|
||||
|
||||
/* now include the error codes */
|
||||
#include <freetype/fterrdef.h>
|
||||
|
||||
|
||||
#ifdef FT_ERROR_END_LIST
|
||||
FT_ERROR_END_LIST
|
||||
#endif
|
||||
|
||||
|
||||
/*******************************************************************/
|
||||
/*******************************************************************/
|
||||
/***** *****/
|
||||
/***** SIMPLE CLEANUP *****/
|
||||
/***** *****/
|
||||
/*******************************************************************/
|
||||
/*******************************************************************/
|
||||
|
||||
#ifdef FT_NEED_EXTERN_C
|
||||
}
|
||||
#endif
|
||||
|
||||
#undef FT_ERROR_START_LIST
|
||||
#undef FT_ERROR_END_LIST
|
||||
|
||||
#undef FT_ERRORDEF
|
||||
#undef FT_ERRORDEF_
|
||||
#undef FT_NOERRORDEF_
|
||||
|
||||
#undef FT_NEED_EXTERN_C
|
||||
#undef FT_ERR_BASE
|
||||
|
||||
/* FT_ERR_PREFIX is needed internally */
|
||||
#ifndef FT2_BUILD_LIBRARY
|
||||
#undef FT_ERR_PREFIX
|
||||
#endif
|
||||
|
||||
/* FT_INCLUDE_ERR_PROTOS: Control whether function prototypes should be */
|
||||
/* included with */
|
||||
/* */
|
||||
/* #include <freetype/fterrors.h> */
|
||||
/* */
|
||||
/* This is only true where `FT_ERRORDEF` is */
|
||||
/* undefined. */
|
||||
/* */
|
||||
/* FT_ERR_PROTOS_DEFINED: Actual multiple-inclusion protection of */
|
||||
/* `fterrors.h`. */
|
||||
#ifdef FT_INCLUDE_ERR_PROTOS
|
||||
#undef FT_INCLUDE_ERR_PROTOS
|
||||
|
||||
#ifndef FT_ERR_PROTOS_DEFINED
|
||||
#define FT_ERR_PROTOS_DEFINED
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Error_String
|
||||
*
|
||||
* @description:
|
||||
* Retrieve the description of a valid FreeType error code.
|
||||
*
|
||||
* @input:
|
||||
* error_code ::
|
||||
* A valid FreeType error code.
|
||||
*
|
||||
* @return:
|
||||
* A C~string or `NULL`, if any error occurred.
|
||||
*
|
||||
* @note:
|
||||
* FreeType has to be compiled with `FT_CONFIG_OPTION_ERROR_STRINGS` or
|
||||
* `FT_DEBUG_LEVEL_ERROR` to get meaningful descriptions.
|
||||
* 'error_string' will be `NULL` otherwise.
|
||||
*
|
||||
* Module identification will be ignored:
|
||||
*
|
||||
* ```c
|
||||
* strcmp( FT_Error_String( FT_Err_Unknown_File_Format ),
|
||||
* FT_Error_String( BDF_Err_Unknown_File_Format ) ) == 0;
|
||||
* ```
|
||||
*/
|
||||
FT_EXPORT( const char* )
|
||||
FT_Error_String( FT_Error error_code );
|
||||
|
||||
/* */
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
|
||||
#endif /* FT_ERR_PROTOS_DEFINED */
|
||||
|
||||
#endif /* FT_INCLUDE_ERR_PROTOS */
|
||||
|
||||
#endif /* !(FTERRORS_H_ && __FTERRORS_H__) */
|
||||
|
||||
|
||||
/* END */
|
||||
93
vendor/freetype/include/freetype/ftfntfmt.h
vendored
Normal file
93
vendor/freetype/include/freetype/ftfntfmt.h
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftfntfmt.h
|
||||
*
|
||||
* Support functions for font formats.
|
||||
*
|
||||
* Copyright (C) 2002-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FTFNTFMT_H_
|
||||
#define FTFNTFMT_H_
|
||||
|
||||
#include <freetype/freetype.h>
|
||||
|
||||
#ifdef FREETYPE_H
|
||||
#error "freetype.h of FreeType 1 has been loaded!"
|
||||
#error "Please fix the directory search order for header files"
|
||||
#error "so that freetype.h of FreeType 2 is found first."
|
||||
#endif
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* font_formats
|
||||
*
|
||||
* @title:
|
||||
* Font Formats
|
||||
*
|
||||
* @abstract:
|
||||
* Getting the font format.
|
||||
*
|
||||
* @description:
|
||||
* The single function in this section can be used to get the font format.
|
||||
* Note that this information is not needed normally; however, there are
|
||||
* special cases (like in PDF devices) where it is important to
|
||||
* differentiate, in spite of FreeType's uniform API.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Get_Font_Format
|
||||
*
|
||||
* @description:
|
||||
* Return a string describing the format of a given face. Possible values
|
||||
* are 'TrueType', 'Type~1', 'BDF', 'PCF', 'Type~42', 'CID~Type~1', 'CFF',
|
||||
* 'PFR', and 'Windows~FNT'.
|
||||
*
|
||||
* The return value is suitable to be used as an X11 FONT_PROPERTY.
|
||||
*
|
||||
* @input:
|
||||
* face ::
|
||||
* Input face handle.
|
||||
*
|
||||
* @return:
|
||||
* Font format string. `NULL` in case of error.
|
||||
*
|
||||
* @note:
|
||||
* A deprecated name for the same function is `FT_Get_X11_Font_Format`.
|
||||
*/
|
||||
FT_EXPORT( const char* )
|
||||
FT_Get_Font_Format( FT_Face face );
|
||||
|
||||
|
||||
/* deprecated */
|
||||
FT_EXPORT( const char* )
|
||||
FT_Get_X11_Font_Format( FT_Face face );
|
||||
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* FTFNTFMT_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
143
vendor/freetype/include/freetype/ftgasp.h
vendored
Normal file
143
vendor/freetype/include/freetype/ftgasp.h
vendored
Normal file
@@ -0,0 +1,143 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftgasp.h
|
||||
*
|
||||
* Access of TrueType's 'gasp' table (specification).
|
||||
*
|
||||
* Copyright (C) 2007-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FTGASP_H_
|
||||
#define FTGASP_H_
|
||||
|
||||
#include <freetype/freetype.h>
|
||||
|
||||
#ifdef FREETYPE_H
|
||||
#error "freetype.h of FreeType 1 has been loaded!"
|
||||
#error "Please fix the directory search order for header files"
|
||||
#error "so that freetype.h of FreeType 2 is found first."
|
||||
#endif
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* gasp_table
|
||||
*
|
||||
* @title:
|
||||
* Gasp Table
|
||||
*
|
||||
* @abstract:
|
||||
* Retrieving TrueType 'gasp' table entries.
|
||||
*
|
||||
* @description:
|
||||
* The function @FT_Get_Gasp can be used to query a TrueType or OpenType
|
||||
* font for specific entries in its 'gasp' table, if any. This is mainly
|
||||
* useful when implementing native TrueType hinting with the bytecode
|
||||
* interpreter to duplicate the Windows text rendering results.
|
||||
*/
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @enum:
|
||||
* FT_GASP_XXX
|
||||
*
|
||||
* @description:
|
||||
* A list of values and/or bit-flags returned by the @FT_Get_Gasp
|
||||
* function.
|
||||
*
|
||||
* @values:
|
||||
* FT_GASP_NO_TABLE ::
|
||||
* This special value means that there is no GASP table in this face.
|
||||
* It is up to the client to decide what to do.
|
||||
*
|
||||
* FT_GASP_DO_GRIDFIT ::
|
||||
* Grid-fitting and hinting should be performed at the specified ppem.
|
||||
* This **really** means TrueType bytecode interpretation. If this bit
|
||||
* is not set, no hinting gets applied.
|
||||
*
|
||||
* FT_GASP_DO_GRAY ::
|
||||
* Anti-aliased rendering should be performed at the specified ppem.
|
||||
* If not set, do monochrome rendering.
|
||||
*
|
||||
* FT_GASP_SYMMETRIC_SMOOTHING ::
|
||||
* If set, smoothing along multiple axes must be used with ClearType.
|
||||
*
|
||||
* FT_GASP_SYMMETRIC_GRIDFIT ::
|
||||
* Grid-fitting must be used with ClearType's symmetric smoothing.
|
||||
*
|
||||
* @note:
|
||||
* The bit-flags `FT_GASP_DO_GRIDFIT` and `FT_GASP_DO_GRAY` are to be
|
||||
* used for standard font rasterization only. Independently of that,
|
||||
* `FT_GASP_SYMMETRIC_SMOOTHING` and `FT_GASP_SYMMETRIC_GRIDFIT` are to
|
||||
* be used if ClearType is enabled (and `FT_GASP_DO_GRIDFIT` and
|
||||
* `FT_GASP_DO_GRAY` are consequently ignored).
|
||||
*
|
||||
* 'ClearType' is Microsoft's implementation of LCD rendering, partly
|
||||
* protected by patents.
|
||||
*
|
||||
* @since:
|
||||
* 2.3.0
|
||||
*/
|
||||
#define FT_GASP_NO_TABLE -1
|
||||
#define FT_GASP_DO_GRIDFIT 0x01
|
||||
#define FT_GASP_DO_GRAY 0x02
|
||||
#define FT_GASP_SYMMETRIC_GRIDFIT 0x04
|
||||
#define FT_GASP_SYMMETRIC_SMOOTHING 0x08
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Get_Gasp
|
||||
*
|
||||
* @description:
|
||||
* For a TrueType or OpenType font file, return the rasterizer behaviour
|
||||
* flags from the font's 'gasp' table corresponding to a given character
|
||||
* pixel size.
|
||||
*
|
||||
* @input:
|
||||
* face ::
|
||||
* The source face handle.
|
||||
*
|
||||
* ppem ::
|
||||
* The vertical character pixel size.
|
||||
*
|
||||
* @return:
|
||||
* Bit flags (see @FT_GASP_XXX), or @FT_GASP_NO_TABLE if there is no
|
||||
* 'gasp' table in the face.
|
||||
*
|
||||
* @note:
|
||||
* If you want to use the MM functionality of OpenType variation fonts
|
||||
* (i.e., using @FT_Set_Var_Design_Coordinates and friends), call this
|
||||
* function **after** setting an instance since the return values can
|
||||
* change.
|
||||
*
|
||||
* @since:
|
||||
* 2.3.0
|
||||
*/
|
||||
FT_EXPORT( FT_Int )
|
||||
FT_Get_Gasp( FT_Face face,
|
||||
FT_UInt ppem );
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* FTGASP_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
750
vendor/freetype/include/freetype/ftglyph.h
vendored
Normal file
750
vendor/freetype/include/freetype/ftglyph.h
vendored
Normal file
@@ -0,0 +1,750 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftglyph.h
|
||||
*
|
||||
* FreeType convenience functions to handle glyphs (specification).
|
||||
*
|
||||
* Copyright (C) 1996-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* This file contains the definition of several convenience functions that
|
||||
* can be used by client applications to easily retrieve glyph bitmaps and
|
||||
* outlines from a given face.
|
||||
*
|
||||
* These functions should be optional if you are writing a font server or
|
||||
* text layout engine on top of FreeType. However, they are pretty handy
|
||||
* for many other simple uses of the library.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FTGLYPH_H_
|
||||
#define FTGLYPH_H_
|
||||
|
||||
|
||||
#include <freetype/freetype.h>
|
||||
|
||||
#ifdef FREETYPE_H
|
||||
#error "freetype.h of FreeType 1 has been loaded!"
|
||||
#error "Please fix the directory search order for header files"
|
||||
#error "so that freetype.h of FreeType 2 is found first."
|
||||
#endif
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* glyph_management
|
||||
*
|
||||
* @title:
|
||||
* Glyph Management
|
||||
*
|
||||
* @abstract:
|
||||
* Generic interface to manage individual glyph data.
|
||||
*
|
||||
* @description:
|
||||
* This section contains definitions used to manage glyph data through
|
||||
* generic @FT_Glyph objects. Each of them can contain a bitmap,
|
||||
* a vector outline, or even images in other formats. These objects are
|
||||
* detached from @FT_Face, contrary to @FT_GlyphSlot.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* forward declaration to a private type */
|
||||
typedef struct FT_Glyph_Class_ FT_Glyph_Class;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @type:
|
||||
* FT_Glyph
|
||||
*
|
||||
* @description:
|
||||
* Handle to an object used to model generic glyph images. It is a
|
||||
* pointer to the @FT_GlyphRec structure and can contain a glyph bitmap
|
||||
* or pointer.
|
||||
*
|
||||
* @note:
|
||||
* Glyph objects are not owned by the library. You must thus release
|
||||
* them manually (through @FT_Done_Glyph) _before_ calling
|
||||
* @FT_Done_FreeType.
|
||||
*/
|
||||
typedef struct FT_GlyphRec_* FT_Glyph;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @struct:
|
||||
* FT_GlyphRec
|
||||
*
|
||||
* @description:
|
||||
* The root glyph structure contains a given glyph image plus its advance
|
||||
* width in 16.16 fixed-point format.
|
||||
*
|
||||
* @fields:
|
||||
* library ::
|
||||
* A handle to the FreeType library object.
|
||||
*
|
||||
* clazz ::
|
||||
* A pointer to the glyph's class. Private.
|
||||
*
|
||||
* format ::
|
||||
* The format of the glyph's image.
|
||||
*
|
||||
* advance ::
|
||||
* A 16.16 vector that gives the glyph's advance width.
|
||||
*/
|
||||
typedef struct FT_GlyphRec_
|
||||
{
|
||||
FT_Library library;
|
||||
const FT_Glyph_Class* clazz;
|
||||
FT_Glyph_Format format;
|
||||
FT_Vector advance;
|
||||
|
||||
} FT_GlyphRec;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @type:
|
||||
* FT_BitmapGlyph
|
||||
*
|
||||
* @description:
|
||||
* A handle to an object used to model a bitmap glyph image. This is a
|
||||
* 'sub-class' of @FT_Glyph, and a pointer to @FT_BitmapGlyphRec.
|
||||
*/
|
||||
typedef struct FT_BitmapGlyphRec_* FT_BitmapGlyph;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @struct:
|
||||
* FT_BitmapGlyphRec
|
||||
*
|
||||
* @description:
|
||||
* A structure used for bitmap glyph images. This really is a
|
||||
* 'sub-class' of @FT_GlyphRec.
|
||||
*
|
||||
* @fields:
|
||||
* root ::
|
||||
* The root fields of @FT_Glyph.
|
||||
*
|
||||
* left ::
|
||||
* The left-side bearing, i.e., the horizontal distance from the
|
||||
* current pen position to the left border of the glyph bitmap.
|
||||
*
|
||||
* top ::
|
||||
* The top-side bearing, i.e., the vertical distance from the current
|
||||
* pen position to the top border of the glyph bitmap. This distance
|
||||
* is positive for upwards~y!
|
||||
*
|
||||
* bitmap ::
|
||||
* A descriptor for the bitmap.
|
||||
*
|
||||
* @note:
|
||||
* You can typecast an @FT_Glyph to @FT_BitmapGlyph if you have
|
||||
* `glyph->format == FT_GLYPH_FORMAT_BITMAP`. This lets you access the
|
||||
* bitmap's contents easily.
|
||||
*
|
||||
* The corresponding pixel buffer is always owned by @FT_BitmapGlyph and
|
||||
* is thus created and destroyed with it.
|
||||
*/
|
||||
typedef struct FT_BitmapGlyphRec_
|
||||
{
|
||||
FT_GlyphRec root;
|
||||
FT_Int left;
|
||||
FT_Int top;
|
||||
FT_Bitmap bitmap;
|
||||
|
||||
} FT_BitmapGlyphRec;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @type:
|
||||
* FT_OutlineGlyph
|
||||
*
|
||||
* @description:
|
||||
* A handle to an object used to model an outline glyph image. This is a
|
||||
* 'sub-class' of @FT_Glyph, and a pointer to @FT_OutlineGlyphRec.
|
||||
*/
|
||||
typedef struct FT_OutlineGlyphRec_* FT_OutlineGlyph;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @struct:
|
||||
* FT_OutlineGlyphRec
|
||||
*
|
||||
* @description:
|
||||
* A structure used for outline (vectorial) glyph images. This really is
|
||||
* a 'sub-class' of @FT_GlyphRec.
|
||||
*
|
||||
* @fields:
|
||||
* root ::
|
||||
* The root @FT_Glyph fields.
|
||||
*
|
||||
* outline ::
|
||||
* A descriptor for the outline.
|
||||
*
|
||||
* @note:
|
||||
* You can typecast an @FT_Glyph to @FT_OutlineGlyph if you have
|
||||
* `glyph->format == FT_GLYPH_FORMAT_OUTLINE`. This lets you access the
|
||||
* outline's content easily.
|
||||
*
|
||||
* As the outline is extracted from a glyph slot, its coordinates are
|
||||
* expressed normally in 26.6 pixels, unless the flag @FT_LOAD_NO_SCALE
|
||||
* was used in @FT_Load_Glyph or @FT_Load_Char.
|
||||
*
|
||||
* The outline's tables are always owned by the object and are destroyed
|
||||
* with it.
|
||||
*/
|
||||
typedef struct FT_OutlineGlyphRec_
|
||||
{
|
||||
FT_GlyphRec root;
|
||||
FT_Outline outline;
|
||||
|
||||
} FT_OutlineGlyphRec;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @type:
|
||||
* FT_SvgGlyph
|
||||
*
|
||||
* @description:
|
||||
* A handle to an object used to model an SVG glyph. This is a
|
||||
* 'sub-class' of @FT_Glyph, and a pointer to @FT_SvgGlyphRec.
|
||||
*
|
||||
* @since:
|
||||
* 2.12
|
||||
*/
|
||||
typedef struct FT_SvgGlyphRec_* FT_SvgGlyph;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @struct:
|
||||
* FT_SvgGlyphRec
|
||||
*
|
||||
* @description:
|
||||
* A structure used for OT-SVG glyphs. This is a 'sub-class' of
|
||||
* @FT_GlyphRec.
|
||||
*
|
||||
* @fields:
|
||||
* root ::
|
||||
* The root @FT_GlyphRec fields.
|
||||
*
|
||||
* svg_document ::
|
||||
* A pointer to the SVG document.
|
||||
*
|
||||
* svg_document_length ::
|
||||
* The length of `svg_document`.
|
||||
*
|
||||
* glyph_index ::
|
||||
* The index of the glyph to be rendered.
|
||||
*
|
||||
* metrics ::
|
||||
* A metrics object storing the size information.
|
||||
*
|
||||
* units_per_EM ::
|
||||
* The size of the EM square.
|
||||
*
|
||||
* start_glyph_id ::
|
||||
* The first glyph ID in the glyph range covered by this document.
|
||||
*
|
||||
* end_glyph_id ::
|
||||
* The last glyph ID in the glyph range covered by this document.
|
||||
*
|
||||
* transform ::
|
||||
* A 2x2 transformation matrix to apply to the glyph while rendering
|
||||
* it.
|
||||
*
|
||||
* delta ::
|
||||
* Translation to apply to the glyph while rendering.
|
||||
*
|
||||
* @note:
|
||||
* The Glyph Management API requires @FT_Glyph or its 'sub-class' to have
|
||||
* all the information needed to completely define the glyph's rendering.
|
||||
* Outline-based glyphs can directly apply transformations to the outline
|
||||
* but this is not possible for an SVG document that hasn't been parsed.
|
||||
* Therefore, the transformation is stored along with the document. In
|
||||
* the absence of a 'ViewBox' or 'Width'/'Height' attribute, the size of
|
||||
* the ViewPort should be assumed to be 'units_per_EM'.
|
||||
*/
|
||||
typedef struct FT_SvgGlyphRec_
|
||||
{
|
||||
FT_GlyphRec root;
|
||||
|
||||
FT_Byte* svg_document;
|
||||
FT_ULong svg_document_length;
|
||||
|
||||
FT_UInt glyph_index;
|
||||
|
||||
FT_Size_Metrics metrics;
|
||||
FT_UShort units_per_EM;
|
||||
|
||||
FT_UShort start_glyph_id;
|
||||
FT_UShort end_glyph_id;
|
||||
|
||||
FT_Matrix transform;
|
||||
FT_Vector delta;
|
||||
|
||||
} FT_SvgGlyphRec;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_New_Glyph
|
||||
*
|
||||
* @description:
|
||||
* A function used to create a new empty glyph image. Note that the
|
||||
* created @FT_Glyph object must be released with @FT_Done_Glyph.
|
||||
*
|
||||
* @input:
|
||||
* library ::
|
||||
* A handle to the FreeType library object.
|
||||
*
|
||||
* format ::
|
||||
* The format of the glyph's image.
|
||||
*
|
||||
* @output:
|
||||
* aglyph ::
|
||||
* A handle to the glyph object.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @since:
|
||||
* 2.10
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_New_Glyph( FT_Library library,
|
||||
FT_Glyph_Format format,
|
||||
FT_Glyph *aglyph );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Get_Glyph
|
||||
*
|
||||
* @description:
|
||||
* A function used to extract a glyph image from a slot. Note that the
|
||||
* created @FT_Glyph object must be released with @FT_Done_Glyph.
|
||||
*
|
||||
* @input:
|
||||
* slot ::
|
||||
* A handle to the source glyph slot.
|
||||
*
|
||||
* @output:
|
||||
* aglyph ::
|
||||
* A handle to the glyph object. `NULL` in case of error.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* Because `*aglyph->advance.x` and `*aglyph->advance.y` are 16.16
|
||||
* fixed-point numbers, `slot->advance.x` and `slot->advance.y` (which
|
||||
* are in 26.6 fixed-point format) must be in the range ]-32768;32768[.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Get_Glyph( FT_GlyphSlot slot,
|
||||
FT_Glyph *aglyph );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Glyph_Copy
|
||||
*
|
||||
* @description:
|
||||
* A function used to copy a glyph image. Note that the created
|
||||
* @FT_Glyph object must be released with @FT_Done_Glyph.
|
||||
*
|
||||
* @input:
|
||||
* source ::
|
||||
* A handle to the source glyph object.
|
||||
*
|
||||
* @output:
|
||||
* target ::
|
||||
* A handle to the target glyph object. `NULL` in case of error.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Glyph_Copy( FT_Glyph source,
|
||||
FT_Glyph *target );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Glyph_Transform
|
||||
*
|
||||
* @description:
|
||||
* Transform a glyph image if its format is scalable.
|
||||
*
|
||||
* @inout:
|
||||
* glyph ::
|
||||
* A handle to the target glyph object.
|
||||
*
|
||||
* @input:
|
||||
* matrix ::
|
||||
* A pointer to a 2x2 matrix to apply.
|
||||
*
|
||||
* delta ::
|
||||
* A pointer to a 2d vector to apply. Coordinates are expressed in
|
||||
* 1/64 of a pixel.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code (if not 0, the glyph format is not scalable).
|
||||
*
|
||||
* @note:
|
||||
* The 2x2 transformation matrix is also applied to the glyph's advance
|
||||
* vector.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Glyph_Transform( FT_Glyph glyph,
|
||||
const FT_Matrix* matrix,
|
||||
const FT_Vector* delta );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @enum:
|
||||
* FT_Glyph_BBox_Mode
|
||||
*
|
||||
* @description:
|
||||
* The mode how the values of @FT_Glyph_Get_CBox are returned.
|
||||
*
|
||||
* @values:
|
||||
* FT_GLYPH_BBOX_UNSCALED ::
|
||||
* Return unscaled font units.
|
||||
*
|
||||
* FT_GLYPH_BBOX_SUBPIXELS ::
|
||||
* Return unfitted 26.6 coordinates.
|
||||
*
|
||||
* FT_GLYPH_BBOX_GRIDFIT ::
|
||||
* Return grid-fitted 26.6 coordinates.
|
||||
*
|
||||
* FT_GLYPH_BBOX_TRUNCATE ::
|
||||
* Return coordinates in integer pixels.
|
||||
*
|
||||
* FT_GLYPH_BBOX_PIXELS ::
|
||||
* Return grid-fitted pixel coordinates.
|
||||
*/
|
||||
typedef enum FT_Glyph_BBox_Mode_
|
||||
{
|
||||
FT_GLYPH_BBOX_UNSCALED = 0,
|
||||
FT_GLYPH_BBOX_SUBPIXELS = 0,
|
||||
FT_GLYPH_BBOX_GRIDFIT = 1,
|
||||
FT_GLYPH_BBOX_TRUNCATE = 2,
|
||||
FT_GLYPH_BBOX_PIXELS = 3
|
||||
|
||||
} FT_Glyph_BBox_Mode;
|
||||
|
||||
|
||||
/* these constants are deprecated; use the corresponding */
|
||||
/* `FT_Glyph_BBox_Mode` values instead */
|
||||
#define ft_glyph_bbox_unscaled FT_GLYPH_BBOX_UNSCALED
|
||||
#define ft_glyph_bbox_subpixels FT_GLYPH_BBOX_SUBPIXELS
|
||||
#define ft_glyph_bbox_gridfit FT_GLYPH_BBOX_GRIDFIT
|
||||
#define ft_glyph_bbox_truncate FT_GLYPH_BBOX_TRUNCATE
|
||||
#define ft_glyph_bbox_pixels FT_GLYPH_BBOX_PIXELS
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Glyph_Get_CBox
|
||||
*
|
||||
* @description:
|
||||
* Return a glyph's 'control box'. The control box encloses all the
|
||||
* outline's points, including Bezier control points. Though it
|
||||
* coincides with the exact bounding box for most glyphs, it can be
|
||||
* slightly larger in some situations (like when rotating an outline that
|
||||
* contains Bezier outside arcs).
|
||||
*
|
||||
* Computing the control box is very fast, while getting the bounding box
|
||||
* can take much more time as it needs to walk over all segments and arcs
|
||||
* in the outline. To get the latter, you can use the 'ftbbox'
|
||||
* component, which is dedicated to this single task.
|
||||
*
|
||||
* @input:
|
||||
* glyph ::
|
||||
* A handle to the source glyph object.
|
||||
*
|
||||
* mode ::
|
||||
* The mode that indicates how to interpret the returned bounding box
|
||||
* values.
|
||||
*
|
||||
* @output:
|
||||
* acbox ::
|
||||
* The glyph coordinate bounding box. Coordinates are expressed in
|
||||
* 1/64 of pixels if it is grid-fitted.
|
||||
*
|
||||
* @note:
|
||||
* Coordinates are relative to the glyph origin, using the y~upwards
|
||||
* convention.
|
||||
*
|
||||
* If the glyph has been loaded with @FT_LOAD_NO_SCALE, `bbox_mode` must
|
||||
* be set to @FT_GLYPH_BBOX_UNSCALED to get unscaled font units in 26.6
|
||||
* pixel format. The value @FT_GLYPH_BBOX_SUBPIXELS is another name for
|
||||
* this constant.
|
||||
*
|
||||
* If the font is tricky and the glyph has been loaded with
|
||||
* @FT_LOAD_NO_SCALE, the resulting CBox is meaningless. To get
|
||||
* reasonable values for the CBox it is necessary to load the glyph at a
|
||||
* large ppem value (so that the hinting instructions can properly shift
|
||||
* and scale the subglyphs), then extracting the CBox, which can be
|
||||
* eventually converted back to font units.
|
||||
*
|
||||
* Note that the maximum coordinates are exclusive, which means that one
|
||||
* can compute the width and height of the glyph image (be it in integer
|
||||
* or 26.6 pixels) as:
|
||||
*
|
||||
* ```
|
||||
* width = bbox.xMax - bbox.xMin;
|
||||
* height = bbox.yMax - bbox.yMin;
|
||||
* ```
|
||||
*
|
||||
* Note also that for 26.6 coordinates, if `bbox_mode` is set to
|
||||
* @FT_GLYPH_BBOX_GRIDFIT, the coordinates will also be grid-fitted,
|
||||
* which corresponds to:
|
||||
*
|
||||
* ```
|
||||
* bbox.xMin = FLOOR(bbox.xMin);
|
||||
* bbox.yMin = FLOOR(bbox.yMin);
|
||||
* bbox.xMax = CEILING(bbox.xMax);
|
||||
* bbox.yMax = CEILING(bbox.yMax);
|
||||
* ```
|
||||
*
|
||||
* To get the bbox in pixel coordinates, set `bbox_mode` to
|
||||
* @FT_GLYPH_BBOX_TRUNCATE.
|
||||
*
|
||||
* To get the bbox in grid-fitted pixel coordinates, set `bbox_mode` to
|
||||
* @FT_GLYPH_BBOX_PIXELS.
|
||||
*/
|
||||
FT_EXPORT( void )
|
||||
FT_Glyph_Get_CBox( FT_Glyph glyph,
|
||||
FT_UInt bbox_mode,
|
||||
FT_BBox *acbox );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Glyph_To_Bitmap
|
||||
*
|
||||
* @description:
|
||||
* Convert a given glyph object to a bitmap glyph object.
|
||||
*
|
||||
* @inout:
|
||||
* the_glyph ::
|
||||
* A pointer to a handle to the target glyph.
|
||||
*
|
||||
* @input:
|
||||
* render_mode ::
|
||||
* An enumeration that describes how the data is rendered.
|
||||
*
|
||||
* origin ::
|
||||
* A pointer to a vector used to translate the glyph image before
|
||||
* rendering. Can be~0 (if no translation). The origin is expressed
|
||||
* in 26.6 pixels.
|
||||
*
|
||||
* destroy ::
|
||||
* A boolean that indicates that the original glyph image should be
|
||||
* destroyed by this function. It is never destroyed in case of error.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* This function does nothing if the glyph format isn't scalable.
|
||||
*
|
||||
* The glyph image is translated with the `origin` vector before
|
||||
* rendering.
|
||||
*
|
||||
* The first parameter is a pointer to an @FT_Glyph handle that will be
|
||||
* _replaced_ by this function (with newly allocated data). Typically,
|
||||
* you would do something like the following (omitting error handling).
|
||||
*
|
||||
* ```
|
||||
* FT_Glyph glyph;
|
||||
* FT_BitmapGlyph glyph_bitmap;
|
||||
*
|
||||
*
|
||||
* // load glyph
|
||||
* error = FT_Load_Char( face, glyph_index, FT_LOAD_DEFAULT );
|
||||
*
|
||||
* // extract glyph image
|
||||
* error = FT_Get_Glyph( face->glyph, &glyph );
|
||||
*
|
||||
* // convert to a bitmap (default render mode + destroying old)
|
||||
* if ( glyph->format != FT_GLYPH_FORMAT_BITMAP )
|
||||
* {
|
||||
* error = FT_Glyph_To_Bitmap( &glyph, FT_RENDER_MODE_NORMAL,
|
||||
* 0, 1 );
|
||||
* if ( error ) // `glyph' unchanged
|
||||
* ...
|
||||
* }
|
||||
*
|
||||
* // access bitmap content by typecasting
|
||||
* glyph_bitmap = (FT_BitmapGlyph)glyph;
|
||||
*
|
||||
* // do funny stuff with it, like blitting/drawing
|
||||
* ...
|
||||
*
|
||||
* // discard glyph image (bitmap or not)
|
||||
* FT_Done_Glyph( glyph );
|
||||
* ```
|
||||
*
|
||||
* Here is another example, again without error handling.
|
||||
*
|
||||
* ```
|
||||
* FT_Glyph glyphs[MAX_GLYPHS]
|
||||
*
|
||||
*
|
||||
* ...
|
||||
*
|
||||
* for ( idx = 0; i < MAX_GLYPHS; i++ )
|
||||
* error = FT_Load_Glyph( face, idx, FT_LOAD_DEFAULT ) ||
|
||||
* FT_Get_Glyph ( face->glyph, &glyphs[idx] );
|
||||
*
|
||||
* ...
|
||||
*
|
||||
* for ( idx = 0; i < MAX_GLYPHS; i++ )
|
||||
* {
|
||||
* FT_Glyph bitmap = glyphs[idx];
|
||||
*
|
||||
*
|
||||
* ...
|
||||
*
|
||||
* // after this call, `bitmap' no longer points into
|
||||
* // the `glyphs' array (and the old value isn't destroyed)
|
||||
* FT_Glyph_To_Bitmap( &bitmap, FT_RENDER_MODE_MONO, 0, 0 );
|
||||
*
|
||||
* ...
|
||||
*
|
||||
* FT_Done_Glyph( bitmap );
|
||||
* }
|
||||
*
|
||||
* ...
|
||||
*
|
||||
* for ( idx = 0; i < MAX_GLYPHS; i++ )
|
||||
* FT_Done_Glyph( glyphs[idx] );
|
||||
* ```
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Glyph_To_Bitmap( FT_Glyph* the_glyph,
|
||||
FT_Render_Mode render_mode,
|
||||
const FT_Vector* origin,
|
||||
FT_Bool destroy );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Done_Glyph
|
||||
*
|
||||
* @description:
|
||||
* Destroy a given glyph.
|
||||
*
|
||||
* @input:
|
||||
* glyph ::
|
||||
* A handle to the target glyph object. Can be `NULL`.
|
||||
*/
|
||||
FT_EXPORT( void )
|
||||
FT_Done_Glyph( FT_Glyph glyph );
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
/* other helpful functions */
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* computations
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Matrix_Multiply
|
||||
*
|
||||
* @description:
|
||||
* Perform the matrix operation `b = a*b`.
|
||||
*
|
||||
* @input:
|
||||
* a ::
|
||||
* A pointer to matrix `a`.
|
||||
*
|
||||
* @inout:
|
||||
* b ::
|
||||
* A pointer to matrix `b`.
|
||||
*
|
||||
* @note:
|
||||
* The result is undefined if either `a` or `b` is zero.
|
||||
*
|
||||
* Since the function uses wrap-around arithmetic, results become
|
||||
* meaningless if the arguments are very large.
|
||||
*/
|
||||
FT_EXPORT( void )
|
||||
FT_Matrix_Multiply( const FT_Matrix* a,
|
||||
FT_Matrix* b );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Matrix_Invert
|
||||
*
|
||||
* @description:
|
||||
* Invert a 2x2 matrix. Return an error if it can't be inverted.
|
||||
*
|
||||
* @inout:
|
||||
* matrix ::
|
||||
* A pointer to the target matrix. Remains untouched in case of error.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Matrix_Invert( FT_Matrix* matrix );
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* FTGLYPH_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
|
||||
|
||||
/* Local Variables: */
|
||||
/* coding: utf-8 */
|
||||
/* End: */
|
||||
354
vendor/freetype/include/freetype/ftgxval.h
vendored
Normal file
354
vendor/freetype/include/freetype/ftgxval.h
vendored
Normal file
@@ -0,0 +1,354 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftgxval.h
|
||||
*
|
||||
* FreeType API for validating TrueTypeGX/AAT tables (specification).
|
||||
*
|
||||
* Copyright (C) 2004-2024 by
|
||||
* Masatake YAMATO, Redhat K.K,
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* gxvalid is derived from both gxlayout module and otvalid module.
|
||||
* Development of gxlayout is supported by the Information-technology
|
||||
* Promotion Agency(IPA), Japan.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FTGXVAL_H_
|
||||
#define FTGXVAL_H_
|
||||
|
||||
#include <freetype/freetype.h>
|
||||
|
||||
#ifdef FREETYPE_H
|
||||
#error "freetype.h of FreeType 1 has been loaded!"
|
||||
#error "Please fix the directory search order for header files"
|
||||
#error "so that freetype.h of FreeType 2 is found first."
|
||||
#endif
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* gx_validation
|
||||
*
|
||||
* @title:
|
||||
* TrueTypeGX/AAT Validation
|
||||
*
|
||||
* @abstract:
|
||||
* An API to validate TrueTypeGX/AAT tables.
|
||||
*
|
||||
* @description:
|
||||
* This section contains the declaration of functions to validate some
|
||||
* TrueTypeGX tables (feat, mort, morx, bsln, just, kern, opbd, trak,
|
||||
* prop, lcar).
|
||||
*
|
||||
* @order:
|
||||
* FT_TrueTypeGX_Validate
|
||||
* FT_TrueTypeGX_Free
|
||||
*
|
||||
* FT_ClassicKern_Validate
|
||||
* FT_ClassicKern_Free
|
||||
*
|
||||
* FT_VALIDATE_GX_LENGTH
|
||||
* FT_VALIDATE_GXXXX
|
||||
* FT_VALIDATE_CKERNXXX
|
||||
*
|
||||
*/
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
*
|
||||
* Warning: Use `FT_VALIDATE_XXX` to validate a table.
|
||||
* Following definitions are for gxvalid developers.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#define FT_VALIDATE_feat_INDEX 0
|
||||
#define FT_VALIDATE_mort_INDEX 1
|
||||
#define FT_VALIDATE_morx_INDEX 2
|
||||
#define FT_VALIDATE_bsln_INDEX 3
|
||||
#define FT_VALIDATE_just_INDEX 4
|
||||
#define FT_VALIDATE_kern_INDEX 5
|
||||
#define FT_VALIDATE_opbd_INDEX 6
|
||||
#define FT_VALIDATE_trak_INDEX 7
|
||||
#define FT_VALIDATE_prop_INDEX 8
|
||||
#define FT_VALIDATE_lcar_INDEX 9
|
||||
#define FT_VALIDATE_GX_LAST_INDEX FT_VALIDATE_lcar_INDEX
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_VALIDATE_GX_LENGTH
|
||||
*
|
||||
* @description:
|
||||
* The number of tables checked in this module. Use it as a parameter
|
||||
* for the `table-length` argument of function @FT_TrueTypeGX_Validate.
|
||||
*/
|
||||
#define FT_VALIDATE_GX_LENGTH ( FT_VALIDATE_GX_LAST_INDEX + 1 )
|
||||
|
||||
/* */
|
||||
|
||||
/* Up to 0x1000 is used by otvalid.
|
||||
Ox2xxx is reserved for feature OT extension. */
|
||||
#define FT_VALIDATE_GX_START 0x4000
|
||||
#define FT_VALIDATE_GX_BITFIELD( tag ) \
|
||||
( FT_VALIDATE_GX_START << FT_VALIDATE_##tag##_INDEX )
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @enum:
|
||||
* FT_VALIDATE_GXXXX
|
||||
*
|
||||
* @description:
|
||||
* A list of bit-field constants used with @FT_TrueTypeGX_Validate to
|
||||
* indicate which TrueTypeGX/AAT Type tables should be validated.
|
||||
*
|
||||
* @values:
|
||||
* FT_VALIDATE_feat ::
|
||||
* Validate 'feat' table.
|
||||
*
|
||||
* FT_VALIDATE_mort ::
|
||||
* Validate 'mort' table.
|
||||
*
|
||||
* FT_VALIDATE_morx ::
|
||||
* Validate 'morx' table.
|
||||
*
|
||||
* FT_VALIDATE_bsln ::
|
||||
* Validate 'bsln' table.
|
||||
*
|
||||
* FT_VALIDATE_just ::
|
||||
* Validate 'just' table.
|
||||
*
|
||||
* FT_VALIDATE_kern ::
|
||||
* Validate 'kern' table.
|
||||
*
|
||||
* FT_VALIDATE_opbd ::
|
||||
* Validate 'opbd' table.
|
||||
*
|
||||
* FT_VALIDATE_trak ::
|
||||
* Validate 'trak' table.
|
||||
*
|
||||
* FT_VALIDATE_prop ::
|
||||
* Validate 'prop' table.
|
||||
*
|
||||
* FT_VALIDATE_lcar ::
|
||||
* Validate 'lcar' table.
|
||||
*
|
||||
* FT_VALIDATE_GX ::
|
||||
* Validate all TrueTypeGX tables (feat, mort, morx, bsln, just, kern,
|
||||
* opbd, trak, prop and lcar).
|
||||
*
|
||||
*/
|
||||
|
||||
#define FT_VALIDATE_feat FT_VALIDATE_GX_BITFIELD( feat )
|
||||
#define FT_VALIDATE_mort FT_VALIDATE_GX_BITFIELD( mort )
|
||||
#define FT_VALIDATE_morx FT_VALIDATE_GX_BITFIELD( morx )
|
||||
#define FT_VALIDATE_bsln FT_VALIDATE_GX_BITFIELD( bsln )
|
||||
#define FT_VALIDATE_just FT_VALIDATE_GX_BITFIELD( just )
|
||||
#define FT_VALIDATE_kern FT_VALIDATE_GX_BITFIELD( kern )
|
||||
#define FT_VALIDATE_opbd FT_VALIDATE_GX_BITFIELD( opbd )
|
||||
#define FT_VALIDATE_trak FT_VALIDATE_GX_BITFIELD( trak )
|
||||
#define FT_VALIDATE_prop FT_VALIDATE_GX_BITFIELD( prop )
|
||||
#define FT_VALIDATE_lcar FT_VALIDATE_GX_BITFIELD( lcar )
|
||||
|
||||
#define FT_VALIDATE_GX ( FT_VALIDATE_feat | \
|
||||
FT_VALIDATE_mort | \
|
||||
FT_VALIDATE_morx | \
|
||||
FT_VALIDATE_bsln | \
|
||||
FT_VALIDATE_just | \
|
||||
FT_VALIDATE_kern | \
|
||||
FT_VALIDATE_opbd | \
|
||||
FT_VALIDATE_trak | \
|
||||
FT_VALIDATE_prop | \
|
||||
FT_VALIDATE_lcar )
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_TrueTypeGX_Validate
|
||||
*
|
||||
* @description:
|
||||
* Validate various TrueTypeGX tables to assure that all offsets and
|
||||
* indices are valid. The idea is that a higher-level library that
|
||||
* actually does the text layout can access those tables without error
|
||||
* checking (which can be quite time consuming).
|
||||
*
|
||||
* @input:
|
||||
* face ::
|
||||
* A handle to the input face.
|
||||
*
|
||||
* validation_flags ::
|
||||
* A bit field that specifies the tables to be validated. See
|
||||
* @FT_VALIDATE_GXXXX for possible values.
|
||||
*
|
||||
* table_length ::
|
||||
* The size of the `tables` array. Normally, @FT_VALIDATE_GX_LENGTH
|
||||
* should be passed.
|
||||
*
|
||||
* @output:
|
||||
* tables ::
|
||||
* The array where all validated sfnt tables are stored. The array
|
||||
* itself must be allocated by a client.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* This function only works with TrueTypeGX fonts, returning an error
|
||||
* otherwise.
|
||||
*
|
||||
* After use, the application should deallocate the buffers pointed to by
|
||||
* each `tables` element, by calling @FT_TrueTypeGX_Free. A `NULL` value
|
||||
* indicates that the table either doesn't exist in the font, the
|
||||
* application hasn't asked for validation, or the validator doesn't have
|
||||
* the ability to validate the sfnt table.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_TrueTypeGX_Validate( FT_Face face,
|
||||
FT_UInt validation_flags,
|
||||
FT_Bytes tables[FT_VALIDATE_GX_LENGTH],
|
||||
FT_UInt table_length );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_TrueTypeGX_Free
|
||||
*
|
||||
* @description:
|
||||
* Free the buffer allocated by TrueTypeGX validator.
|
||||
*
|
||||
* @input:
|
||||
* face ::
|
||||
* A handle to the input face.
|
||||
*
|
||||
* table ::
|
||||
* The pointer to the buffer allocated by @FT_TrueTypeGX_Validate.
|
||||
*
|
||||
* @note:
|
||||
* This function must be used to free the buffer allocated by
|
||||
* @FT_TrueTypeGX_Validate only.
|
||||
*/
|
||||
FT_EXPORT( void )
|
||||
FT_TrueTypeGX_Free( FT_Face face,
|
||||
FT_Bytes table );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @enum:
|
||||
* FT_VALIDATE_CKERNXXX
|
||||
*
|
||||
* @description:
|
||||
* A list of bit-field constants used with @FT_ClassicKern_Validate to
|
||||
* indicate the classic kern dialect or dialects. If the selected type
|
||||
* doesn't fit, @FT_ClassicKern_Validate regards the table as invalid.
|
||||
*
|
||||
* @values:
|
||||
* FT_VALIDATE_MS ::
|
||||
* Handle the 'kern' table as a classic Microsoft kern table.
|
||||
*
|
||||
* FT_VALIDATE_APPLE ::
|
||||
* Handle the 'kern' table as a classic Apple kern table.
|
||||
*
|
||||
* FT_VALIDATE_CKERN ::
|
||||
* Handle the 'kern' as either classic Apple or Microsoft kern table.
|
||||
*/
|
||||
#define FT_VALIDATE_MS ( FT_VALIDATE_GX_START << 0 )
|
||||
#define FT_VALIDATE_APPLE ( FT_VALIDATE_GX_START << 1 )
|
||||
|
||||
#define FT_VALIDATE_CKERN ( FT_VALIDATE_MS | FT_VALIDATE_APPLE )
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_ClassicKern_Validate
|
||||
*
|
||||
* @description:
|
||||
* Validate classic (16-bit format) kern table to assure that the
|
||||
* offsets and indices are valid. The idea is that a higher-level
|
||||
* library that actually does the text layout can access those tables
|
||||
* without error checking (which can be quite time consuming).
|
||||
*
|
||||
* The 'kern' table validator in @FT_TrueTypeGX_Validate deals with both
|
||||
* the new 32-bit format and the classic 16-bit format, while
|
||||
* FT_ClassicKern_Validate only supports the classic 16-bit format.
|
||||
*
|
||||
* @input:
|
||||
* face ::
|
||||
* A handle to the input face.
|
||||
*
|
||||
* validation_flags ::
|
||||
* A bit field that specifies the dialect to be validated. See
|
||||
* @FT_VALIDATE_CKERNXXX for possible values.
|
||||
*
|
||||
* @output:
|
||||
* ckern_table ::
|
||||
* A pointer to the kern table.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* After use, the application should deallocate the buffers pointed to by
|
||||
* `ckern_table`, by calling @FT_ClassicKern_Free. A `NULL` value
|
||||
* indicates that the table doesn't exist in the font.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_ClassicKern_Validate( FT_Face face,
|
||||
FT_UInt validation_flags,
|
||||
FT_Bytes *ckern_table );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_ClassicKern_Free
|
||||
*
|
||||
* @description:
|
||||
* Free the buffer allocated by classic Kern validator.
|
||||
*
|
||||
* @input:
|
||||
* face ::
|
||||
* A handle to the input face.
|
||||
*
|
||||
* table ::
|
||||
* The pointer to the buffer that is allocated by
|
||||
* @FT_ClassicKern_Validate.
|
||||
*
|
||||
* @note:
|
||||
* This function must be used to free the buffer allocated by
|
||||
* @FT_ClassicKern_Validate only.
|
||||
*/
|
||||
FT_EXPORT( void )
|
||||
FT_ClassicKern_Free( FT_Face face,
|
||||
FT_Bytes table );
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* FTGXVAL_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
151
vendor/freetype/include/freetype/ftgzip.h
vendored
Normal file
151
vendor/freetype/include/freetype/ftgzip.h
vendored
Normal file
@@ -0,0 +1,151 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftgzip.h
|
||||
*
|
||||
* Gzip-compressed stream support.
|
||||
*
|
||||
* Copyright (C) 2002-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FTGZIP_H_
|
||||
#define FTGZIP_H_
|
||||
|
||||
#include <freetype/freetype.h>
|
||||
|
||||
#ifdef FREETYPE_H
|
||||
#error "freetype.h of FreeType 1 has been loaded!"
|
||||
#error "Please fix the directory search order for header files"
|
||||
#error "so that freetype.h of FreeType 2 is found first."
|
||||
#endif
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* gzip
|
||||
*
|
||||
* @title:
|
||||
* GZIP Streams
|
||||
*
|
||||
* @abstract:
|
||||
* Using gzip-compressed font files.
|
||||
*
|
||||
* @description:
|
||||
* In certain builds of the library, gzip compression recognition is
|
||||
* automatically handled when calling @FT_New_Face or @FT_Open_Face.
|
||||
* This means that if no font driver is capable of handling the raw
|
||||
* compressed file, the library will try to open a gzipped stream from it
|
||||
* and re-open the face with it.
|
||||
*
|
||||
* The stream implementation is very basic and resets the decompression
|
||||
* process each time seeking backwards is needed within the stream,
|
||||
* which significantly undermines the performance.
|
||||
*
|
||||
* This section contains the declaration of Gzip-specific functions.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Stream_OpenGzip
|
||||
*
|
||||
* @description:
|
||||
* Open a new stream to parse gzip-compressed font files. This is mainly
|
||||
* used to support the compressed `*.pcf.gz` fonts that come with
|
||||
* XFree86.
|
||||
*
|
||||
* @input:
|
||||
* stream ::
|
||||
* The target embedding stream.
|
||||
*
|
||||
* source ::
|
||||
* The source stream.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* The source stream must be opened _before_ calling this function.
|
||||
*
|
||||
* Calling the internal function `FT_Stream_Close` on the new stream will
|
||||
* **not** call `FT_Stream_Close` on the source stream. None of the
|
||||
* stream objects will be released to the heap.
|
||||
*
|
||||
* This function may return `FT_Err_Unimplemented_Feature` if your build
|
||||
* of FreeType was not compiled with zlib support.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Stream_OpenGzip( FT_Stream stream,
|
||||
FT_Stream source );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Gzip_Uncompress
|
||||
*
|
||||
* @description:
|
||||
* Decompress a zipped input buffer into an output buffer. This function
|
||||
* is modeled after zlib's `uncompress` function.
|
||||
*
|
||||
* @input:
|
||||
* memory ::
|
||||
* A FreeType memory handle.
|
||||
*
|
||||
* input ::
|
||||
* The input buffer.
|
||||
*
|
||||
* input_len ::
|
||||
* The length of the input buffer.
|
||||
*
|
||||
* @output:
|
||||
* output ::
|
||||
* The output buffer.
|
||||
*
|
||||
* @inout:
|
||||
* output_len ::
|
||||
* Before calling the function, this is the total size of the output
|
||||
* buffer, which must be large enough to hold the entire uncompressed
|
||||
* data (so the size of the uncompressed data must be known in
|
||||
* advance). After calling the function, `output_len` is the size of
|
||||
* the used data in `output`.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* This function may return `FT_Err_Unimplemented_Feature` if your build
|
||||
* of FreeType was not compiled with zlib support.
|
||||
*
|
||||
* @since:
|
||||
* 2.5.1
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Gzip_Uncompress( FT_Memory memory,
|
||||
FT_Byte* output,
|
||||
FT_ULong* output_len,
|
||||
const FT_Byte* input,
|
||||
FT_ULong input_len );
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* FTGZIP_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
1289
vendor/freetype/include/freetype/ftimage.h
vendored
Normal file
1289
vendor/freetype/include/freetype/ftimage.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
348
vendor/freetype/include/freetype/ftincrem.h
vendored
Normal file
348
vendor/freetype/include/freetype/ftincrem.h
vendored
Normal file
@@ -0,0 +1,348 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftincrem.h
|
||||
*
|
||||
* FreeType incremental loading (specification).
|
||||
*
|
||||
* Copyright (C) 2002-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FTINCREM_H_
|
||||
#define FTINCREM_H_
|
||||
|
||||
#include <freetype/freetype.h>
|
||||
#include <freetype/ftparams.h>
|
||||
|
||||
#ifdef FREETYPE_H
|
||||
#error "freetype.h of FreeType 1 has been loaded!"
|
||||
#error "Please fix the directory search order for header files"
|
||||
#error "so that freetype.h of FreeType 2 is found first."
|
||||
#endif
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* incremental
|
||||
*
|
||||
* @title:
|
||||
* Incremental Loading
|
||||
*
|
||||
* @abstract:
|
||||
* Custom Glyph Loading.
|
||||
*
|
||||
* @description:
|
||||
* This section contains various functions used to perform so-called
|
||||
* 'incremental' glyph loading. This is a mode where all glyphs loaded
|
||||
* from a given @FT_Face are provided by the client application.
|
||||
*
|
||||
* Apart from that, all other tables are loaded normally from the font
|
||||
* file. This mode is useful when FreeType is used within another
|
||||
* engine, e.g., a PostScript Imaging Processor.
|
||||
*
|
||||
* To enable this mode, you must use @FT_Open_Face, passing an
|
||||
* @FT_Parameter with the @FT_PARAM_TAG_INCREMENTAL tag and an
|
||||
* @FT_Incremental_Interface value. See the comments for
|
||||
* @FT_Incremental_InterfaceRec for an example.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @type:
|
||||
* FT_Incremental
|
||||
*
|
||||
* @description:
|
||||
* An opaque type describing a user-provided object used to implement
|
||||
* 'incremental' glyph loading within FreeType. This is used to support
|
||||
* embedded fonts in certain environments (e.g., PostScript
|
||||
* interpreters), where the glyph data isn't in the font file, or must be
|
||||
* overridden by different values.
|
||||
*
|
||||
* @note:
|
||||
* It is up to client applications to create and implement
|
||||
* @FT_Incremental objects, as long as they provide implementations for
|
||||
* the methods @FT_Incremental_GetGlyphDataFunc,
|
||||
* @FT_Incremental_FreeGlyphDataFunc and
|
||||
* @FT_Incremental_GetGlyphMetricsFunc.
|
||||
*
|
||||
* See the description of @FT_Incremental_InterfaceRec to understand how
|
||||
* to use incremental objects with FreeType.
|
||||
*
|
||||
*/
|
||||
typedef struct FT_IncrementalRec_* FT_Incremental;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @struct:
|
||||
* FT_Incremental_MetricsRec
|
||||
*
|
||||
* @description:
|
||||
* A small structure used to contain the basic glyph metrics returned by
|
||||
* the @FT_Incremental_GetGlyphMetricsFunc method.
|
||||
*
|
||||
* @fields:
|
||||
* bearing_x ::
|
||||
* Left bearing, in font units.
|
||||
*
|
||||
* bearing_y ::
|
||||
* Top bearing, in font units.
|
||||
*
|
||||
* advance ::
|
||||
* Horizontal component of glyph advance, in font units.
|
||||
*
|
||||
* advance_v ::
|
||||
* Vertical component of glyph advance, in font units.
|
||||
*
|
||||
* @note:
|
||||
* These correspond to horizontal or vertical metrics depending on the
|
||||
* value of the `vertical` argument to the function
|
||||
* @FT_Incremental_GetGlyphMetricsFunc.
|
||||
*
|
||||
*/
|
||||
typedef struct FT_Incremental_MetricsRec_
|
||||
{
|
||||
FT_Long bearing_x;
|
||||
FT_Long bearing_y;
|
||||
FT_Long advance;
|
||||
FT_Long advance_v; /* since 2.3.12 */
|
||||
|
||||
} FT_Incremental_MetricsRec;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @struct:
|
||||
* FT_Incremental_Metrics
|
||||
*
|
||||
* @description:
|
||||
* A handle to an @FT_Incremental_MetricsRec structure.
|
||||
*
|
||||
*/
|
||||
typedef struct FT_Incremental_MetricsRec_* FT_Incremental_Metrics;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @type:
|
||||
* FT_Incremental_GetGlyphDataFunc
|
||||
*
|
||||
* @description:
|
||||
* A function called by FreeType to access a given glyph's data bytes
|
||||
* during @FT_Load_Glyph or @FT_Load_Char if incremental loading is
|
||||
* enabled.
|
||||
*
|
||||
* Note that the format of the glyph's data bytes depends on the font
|
||||
* file format. For TrueType, it must correspond to the raw bytes within
|
||||
* the 'glyf' table. For PostScript formats, it must correspond to the
|
||||
* **unencrypted** charstring bytes, without any `lenIV` header. It is
|
||||
* undefined for any other format.
|
||||
*
|
||||
* @input:
|
||||
* incremental ::
|
||||
* Handle to an opaque @FT_Incremental handle provided by the client
|
||||
* application.
|
||||
*
|
||||
* glyph_index ::
|
||||
* Index of relevant glyph.
|
||||
*
|
||||
* @output:
|
||||
* adata ::
|
||||
* A structure describing the returned glyph data bytes (which will be
|
||||
* accessed as a read-only byte block).
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* If this function returns successfully the method
|
||||
* @FT_Incremental_FreeGlyphDataFunc will be called later to release the
|
||||
* data bytes.
|
||||
*
|
||||
* Nested calls to @FT_Incremental_GetGlyphDataFunc can happen for
|
||||
* compound glyphs.
|
||||
*
|
||||
*/
|
||||
typedef FT_Error
|
||||
(*FT_Incremental_GetGlyphDataFunc)( FT_Incremental incremental,
|
||||
FT_UInt glyph_index,
|
||||
FT_Data* adata );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @type:
|
||||
* FT_Incremental_FreeGlyphDataFunc
|
||||
*
|
||||
* @description:
|
||||
* A function used to release the glyph data bytes returned by a
|
||||
* successful call to @FT_Incremental_GetGlyphDataFunc.
|
||||
*
|
||||
* @input:
|
||||
* incremental ::
|
||||
* A handle to an opaque @FT_Incremental handle provided by the client
|
||||
* application.
|
||||
*
|
||||
* data ::
|
||||
* A structure describing the glyph data bytes (which will be accessed
|
||||
* as a read-only byte block).
|
||||
*
|
||||
*/
|
||||
typedef void
|
||||
(*FT_Incremental_FreeGlyphDataFunc)( FT_Incremental incremental,
|
||||
FT_Data* data );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @type:
|
||||
* FT_Incremental_GetGlyphMetricsFunc
|
||||
*
|
||||
* @description:
|
||||
* A function used to retrieve the basic metrics of a given glyph index
|
||||
* before accessing its data. This allows for handling font types such
|
||||
* as PCL~XL Format~1, Class~2 downloaded TrueType fonts, where the glyph
|
||||
* metrics (`hmtx` and `vmtx` tables) are permitted to be omitted from
|
||||
* the font, and the relevant metrics included in the header of the glyph
|
||||
* outline data. Importantly, this is not intended to allow custom glyph
|
||||
* metrics (for example, Postscript Metrics dictionaries), because that
|
||||
* conflicts with the requirements of outline hinting. Such custom
|
||||
* metrics must be handled separately, by the calling application.
|
||||
*
|
||||
* @input:
|
||||
* incremental ::
|
||||
* A handle to an opaque @FT_Incremental handle provided by the client
|
||||
* application.
|
||||
*
|
||||
* glyph_index ::
|
||||
* Index of relevant glyph.
|
||||
*
|
||||
* vertical ::
|
||||
* If true, return vertical metrics.
|
||||
*
|
||||
* ametrics ::
|
||||
* This parameter is used for both input and output. The original
|
||||
* glyph metrics, if any, in font units. If metrics are not available
|
||||
* all the values must be set to zero.
|
||||
*
|
||||
* @output:
|
||||
* ametrics ::
|
||||
* The glyph metrics in font units.
|
||||
*
|
||||
*/
|
||||
typedef FT_Error
|
||||
(*FT_Incremental_GetGlyphMetricsFunc)
|
||||
( FT_Incremental incremental,
|
||||
FT_UInt glyph_index,
|
||||
FT_Bool vertical,
|
||||
FT_Incremental_MetricsRec *ametrics );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @struct:
|
||||
* FT_Incremental_FuncsRec
|
||||
*
|
||||
* @description:
|
||||
* A table of functions for accessing fonts that load data incrementally.
|
||||
* Used in @FT_Incremental_InterfaceRec.
|
||||
*
|
||||
* @fields:
|
||||
* get_glyph_data ::
|
||||
* The function to get glyph data. Must not be null.
|
||||
*
|
||||
* free_glyph_data ::
|
||||
* The function to release glyph data. Must not be null.
|
||||
*
|
||||
* get_glyph_metrics ::
|
||||
* The function to get glyph metrics. May be null if the font does not
|
||||
* require it.
|
||||
*
|
||||
*/
|
||||
typedef struct FT_Incremental_FuncsRec_
|
||||
{
|
||||
FT_Incremental_GetGlyphDataFunc get_glyph_data;
|
||||
FT_Incremental_FreeGlyphDataFunc free_glyph_data;
|
||||
FT_Incremental_GetGlyphMetricsFunc get_glyph_metrics;
|
||||
|
||||
} FT_Incremental_FuncsRec;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @struct:
|
||||
* FT_Incremental_InterfaceRec
|
||||
*
|
||||
* @description:
|
||||
* A structure to be used with @FT_Open_Face to indicate that the user
|
||||
* wants to support incremental glyph loading. You should use it with
|
||||
* @FT_PARAM_TAG_INCREMENTAL as in the following example:
|
||||
*
|
||||
* ```
|
||||
* FT_Incremental_InterfaceRec inc_int;
|
||||
* FT_Parameter parameter;
|
||||
* FT_Open_Args open_args;
|
||||
*
|
||||
*
|
||||
* // set up incremental descriptor
|
||||
* inc_int.funcs = my_funcs;
|
||||
* inc_int.object = my_object;
|
||||
*
|
||||
* // set up optional parameter
|
||||
* parameter.tag = FT_PARAM_TAG_INCREMENTAL;
|
||||
* parameter.data = &inc_int;
|
||||
*
|
||||
* // set up FT_Open_Args structure
|
||||
* open_args.flags = FT_OPEN_PATHNAME | FT_OPEN_PARAMS;
|
||||
* open_args.pathname = my_font_pathname;
|
||||
* open_args.num_params = 1;
|
||||
* open_args.params = ¶meter; // we use one optional argument
|
||||
*
|
||||
* // open the font
|
||||
* error = FT_Open_Face( library, &open_args, index, &face );
|
||||
* ...
|
||||
* ```
|
||||
*
|
||||
*/
|
||||
typedef struct FT_Incremental_InterfaceRec_
|
||||
{
|
||||
const FT_Incremental_FuncsRec* funcs;
|
||||
FT_Incremental object;
|
||||
|
||||
} FT_Incremental_InterfaceRec;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @type:
|
||||
* FT_Incremental_Interface
|
||||
*
|
||||
* @description:
|
||||
* A pointer to an @FT_Incremental_InterfaceRec structure.
|
||||
*
|
||||
*/
|
||||
typedef FT_Incremental_InterfaceRec* FT_Incremental_Interface;
|
||||
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* FTINCREM_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
323
vendor/freetype/include/freetype/ftlcdfil.h
vendored
Normal file
323
vendor/freetype/include/freetype/ftlcdfil.h
vendored
Normal file
@@ -0,0 +1,323 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftlcdfil.h
|
||||
*
|
||||
* FreeType API for color filtering of subpixel bitmap glyphs
|
||||
* (specification).
|
||||
*
|
||||
* Copyright (C) 2006-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FTLCDFIL_H_
|
||||
#define FTLCDFIL_H_
|
||||
|
||||
#include <freetype/freetype.h>
|
||||
#include <freetype/ftparams.h>
|
||||
|
||||
#ifdef FREETYPE_H
|
||||
#error "freetype.h of FreeType 1 has been loaded!"
|
||||
#error "Please fix the directory search order for header files"
|
||||
#error "so that freetype.h of FreeType 2 is found first."
|
||||
#endif
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* lcd_rendering
|
||||
*
|
||||
* @title:
|
||||
* Subpixel Rendering
|
||||
*
|
||||
* @abstract:
|
||||
* API to control subpixel rendering.
|
||||
*
|
||||
* @description:
|
||||
* FreeType provides two alternative subpixel rendering technologies.
|
||||
* Should you define `FT_CONFIG_OPTION_SUBPIXEL_RENDERING` in your
|
||||
* `ftoption.h` file, this enables ClearType-style rendering.
|
||||
* Otherwise, Harmony LCD rendering is enabled. These technologies are
|
||||
* controlled differently and API described below, although always
|
||||
* available, performs its function when appropriate method is enabled
|
||||
* and does nothing otherwise.
|
||||
*
|
||||
* ClearType-style LCD rendering exploits the color-striped structure of
|
||||
* LCD pixels, increasing the available resolution in the direction of
|
||||
* the stripe (usually horizontal RGB) by a factor of~3. Using the
|
||||
* subpixel coverages unfiltered can create severe color fringes
|
||||
* especially when rendering thin features. Indeed, to produce
|
||||
* black-on-white text, the nearby color subpixels must be dimmed
|
||||
* evenly. Therefore, an equalizing 5-tap FIR filter should be applied
|
||||
* to subpixel coverages regardless of pixel boundaries and should have
|
||||
* these properties:
|
||||
*
|
||||
* 1. It should be symmetrical, like {~a, b, c, b, a~}, to avoid
|
||||
* any shifts in appearance.
|
||||
*
|
||||
* 2. It should be color-balanced, meaning a~+ b~=~c, to reduce color
|
||||
* fringes by distributing the computed coverage for one subpixel to
|
||||
* all subpixels equally.
|
||||
*
|
||||
* 3. It should be normalized, meaning 2a~+ 2b~+ c~=~1.0 to maintain
|
||||
* overall brightness.
|
||||
*
|
||||
* Boxy 3-tap filter {0, 1/3, 1/3, 1/3, 0} is sharper but is less
|
||||
* forgiving of non-ideal gamma curves of a screen (and viewing angles),
|
||||
* beveled filters are fuzzier but more tolerant.
|
||||
*
|
||||
* Use the @FT_Library_SetLcdFilter or @FT_Library_SetLcdFilterWeights
|
||||
* API to specify a low-pass filter, which is then applied to
|
||||
* subpixel-rendered bitmaps generated through @FT_Render_Glyph.
|
||||
*
|
||||
* Harmony LCD rendering is suitable to panels with any regular subpixel
|
||||
* structure, not just monitors with 3 color striped subpixels, as long
|
||||
* as the color subpixels have fixed positions relative to the pixel
|
||||
* center. In this case, each color channel can be rendered separately
|
||||
* after shifting the outline opposite to the subpixel shift so that the
|
||||
* coverage maps are aligned. This method is immune to color fringes
|
||||
* because the shifts do not change integral coverage.
|
||||
*
|
||||
* The subpixel geometry must be specified by xy-coordinates for each
|
||||
* subpixel. By convention they may come in the RGB order: {{-1/3, 0},
|
||||
* {0, 0}, {1/3, 0}} for standard RGB striped panel or {{-1/6, 1/4},
|
||||
* {-1/6, -1/4}, {1/3, 0}} for a certain PenTile panel.
|
||||
*
|
||||
* Use the @FT_Library_SetLcdGeometry API to specify subpixel positions.
|
||||
* If one follows the RGB order convention, the same order applies to the
|
||||
* resulting @FT_PIXEL_MODE_LCD and @FT_PIXEL_MODE_LCD_V bitmaps. Note,
|
||||
* however, that the coordinate frame for the latter must be rotated
|
||||
* clockwise. Harmony with default LCD geometry is equivalent to
|
||||
* ClearType with light filter.
|
||||
*
|
||||
* As a result of ClearType filtering or Harmony shifts, the resulting
|
||||
* dimensions of LCD bitmaps can be slightly wider or taller than the
|
||||
* dimensions the original outline with regard to the pixel grid.
|
||||
* For example, for @FT_RENDER_MODE_LCD, the filter adds 2~subpixels to
|
||||
* the left, and 2~subpixels to the right. The bitmap offset values are
|
||||
* adjusted accordingly, so clients shouldn't need to modify their layout
|
||||
* and glyph positioning code when enabling the filter.
|
||||
*
|
||||
* The ClearType and Harmony rendering is applicable to glyph bitmaps
|
||||
* rendered through @FT_Render_Glyph, @FT_Load_Glyph, @FT_Load_Char, and
|
||||
* @FT_Glyph_To_Bitmap, when @FT_RENDER_MODE_LCD or @FT_RENDER_MODE_LCD_V
|
||||
* is specified. This API does not control @FT_Outline_Render and
|
||||
* @FT_Outline_Get_Bitmap.
|
||||
*
|
||||
* The described algorithms can completely remove color artefacts when
|
||||
* combined with gamma-corrected alpha blending in linear space. Each of
|
||||
* the 3~alpha values (subpixels) must by independently used to blend one
|
||||
* color channel. That is, red alpha blends the red channel of the text
|
||||
* color with the red channel of the background pixel.
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @enum:
|
||||
* FT_LcdFilter
|
||||
*
|
||||
* @description:
|
||||
* A list of values to identify various types of LCD filters.
|
||||
*
|
||||
* @values:
|
||||
* FT_LCD_FILTER_NONE ::
|
||||
* Do not perform filtering. When used with subpixel rendering, this
|
||||
* results in sometimes severe color fringes.
|
||||
*
|
||||
* FT_LCD_FILTER_DEFAULT ::
|
||||
* This is a beveled, normalized, and color-balanced five-tap filter
|
||||
* with weights of [0x08 0x4D 0x56 0x4D 0x08] in 1/256 units.
|
||||
*
|
||||
* FT_LCD_FILTER_LIGHT ::
|
||||
* this is a boxy, normalized, and color-balanced three-tap filter with
|
||||
* weights of [0x00 0x55 0x56 0x55 0x00] in 1/256 units.
|
||||
*
|
||||
* FT_LCD_FILTER_LEGACY ::
|
||||
* FT_LCD_FILTER_LEGACY1 ::
|
||||
* This filter corresponds to the original libXft color filter. It
|
||||
* provides high contrast output but can exhibit really bad color
|
||||
* fringes if glyphs are not extremely well hinted to the pixel grid.
|
||||
* This filter is only provided for comparison purposes, and might be
|
||||
* disabled or stay unsupported in the future. The second value is
|
||||
* provided for compatibility with FontConfig, which historically used
|
||||
* different enumeration, sometimes incorrectly forwarded to FreeType.
|
||||
*
|
||||
* @since:
|
||||
* 2.3.0 (`FT_LCD_FILTER_LEGACY1` since 2.6.2)
|
||||
*/
|
||||
typedef enum FT_LcdFilter_
|
||||
{
|
||||
FT_LCD_FILTER_NONE = 0,
|
||||
FT_LCD_FILTER_DEFAULT = 1,
|
||||
FT_LCD_FILTER_LIGHT = 2,
|
||||
FT_LCD_FILTER_LEGACY1 = 3,
|
||||
FT_LCD_FILTER_LEGACY = 16,
|
||||
|
||||
FT_LCD_FILTER_MAX /* do not remove */
|
||||
|
||||
} FT_LcdFilter;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Library_SetLcdFilter
|
||||
*
|
||||
* @description:
|
||||
* This function is used to change filter applied to LCD decimated
|
||||
* bitmaps, like the ones used when calling @FT_Render_Glyph with
|
||||
* @FT_RENDER_MODE_LCD or @FT_RENDER_MODE_LCD_V.
|
||||
*
|
||||
* @input:
|
||||
* library ::
|
||||
* A handle to the target library instance.
|
||||
*
|
||||
* filter ::
|
||||
* The filter type.
|
||||
*
|
||||
* You can use @FT_LCD_FILTER_NONE here to disable this feature, or
|
||||
* @FT_LCD_FILTER_DEFAULT to use a default filter that should work well
|
||||
* on most LCD screens.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* Since 2.10.3 the LCD filtering is enabled with @FT_LCD_FILTER_DEFAULT.
|
||||
* It is no longer necessary to call this function explicitly except
|
||||
* to choose a different filter or disable filtering altogether with
|
||||
* @FT_LCD_FILTER_NONE.
|
||||
*
|
||||
* This function does nothing but returns `FT_Err_Unimplemented_Feature`
|
||||
* if the configuration macro `FT_CONFIG_OPTION_SUBPIXEL_RENDERING` is
|
||||
* not defined in your build of the library.
|
||||
*
|
||||
* @since:
|
||||
* 2.3.0
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Library_SetLcdFilter( FT_Library library,
|
||||
FT_LcdFilter filter );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Library_SetLcdFilterWeights
|
||||
*
|
||||
* @description:
|
||||
* This function can be used to enable LCD filter with custom weights,
|
||||
* instead of using presets in @FT_Library_SetLcdFilter.
|
||||
*
|
||||
* @input:
|
||||
* library ::
|
||||
* A handle to the target library instance.
|
||||
*
|
||||
* weights ::
|
||||
* A pointer to an array; the function copies the first five bytes and
|
||||
* uses them to specify the filter weights in 1/256 units.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* This function does nothing but returns `FT_Err_Unimplemented_Feature`
|
||||
* if the configuration macro `FT_CONFIG_OPTION_SUBPIXEL_RENDERING` is
|
||||
* not defined in your build of the library.
|
||||
*
|
||||
* LCD filter weights can also be set per face using @FT_Face_Properties
|
||||
* with @FT_PARAM_TAG_LCD_FILTER_WEIGHTS.
|
||||
*
|
||||
* @since:
|
||||
* 2.4.0
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Library_SetLcdFilterWeights( FT_Library library,
|
||||
unsigned char *weights );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @type:
|
||||
* FT_LcdFiveTapFilter
|
||||
*
|
||||
* @description:
|
||||
* A typedef for passing the five LCD filter weights to
|
||||
* @FT_Face_Properties within an @FT_Parameter structure.
|
||||
*
|
||||
* @since:
|
||||
* 2.8
|
||||
*
|
||||
*/
|
||||
#define FT_LCD_FILTER_FIVE_TAPS 5
|
||||
|
||||
typedef FT_Byte FT_LcdFiveTapFilter[FT_LCD_FILTER_FIVE_TAPS];
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Library_SetLcdGeometry
|
||||
*
|
||||
* @description:
|
||||
* This function can be used to modify default positions of color
|
||||
* subpixels, which controls Harmony LCD rendering.
|
||||
*
|
||||
* @input:
|
||||
* library ::
|
||||
* A handle to the target library instance.
|
||||
*
|
||||
* sub ::
|
||||
* A pointer to an array of 3 vectors in 26.6 fractional pixel format;
|
||||
* the function modifies the default values, see the note below.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* Subpixel geometry examples:
|
||||
*
|
||||
* - {{-21, 0}, {0, 0}, {21, 0}} is the default, corresponding to 3 color
|
||||
* stripes shifted by a third of a pixel. This could be an RGB panel.
|
||||
*
|
||||
* - {{21, 0}, {0, 0}, {-21, 0}} looks the same as the default but can
|
||||
* specify a BGR panel instead, while keeping the bitmap in the same
|
||||
* RGB888 format.
|
||||
*
|
||||
* - {{0, 21}, {0, 0}, {0, -21}} is the vertical RGB, but the bitmap
|
||||
* stays RGB888 as a result.
|
||||
*
|
||||
* - {{-11, 16}, {-11, -16}, {22, 0}} is a certain PenTile arrangement.
|
||||
*
|
||||
* This function does nothing and returns `FT_Err_Unimplemented_Feature`
|
||||
* in the context of ClearType-style subpixel rendering when
|
||||
* `FT_CONFIG_OPTION_SUBPIXEL_RENDERING` is defined in your build of the
|
||||
* library.
|
||||
*
|
||||
* @since:
|
||||
* 2.10.0
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Library_SetLcdGeometry( FT_Library library,
|
||||
FT_Vector sub[3] );
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* FTLCDFIL_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
296
vendor/freetype/include/freetype/ftlist.h
vendored
Normal file
296
vendor/freetype/include/freetype/ftlist.h
vendored
Normal file
@@ -0,0 +1,296 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftlist.h
|
||||
*
|
||||
* Generic list support for FreeType (specification).
|
||||
*
|
||||
* Copyright (C) 1996-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* This file implements functions relative to list processing. Its data
|
||||
* structures are defined in `freetype.h`.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FTLIST_H_
|
||||
#define FTLIST_H_
|
||||
|
||||
|
||||
#include <freetype/freetype.h>
|
||||
|
||||
#ifdef FREETYPE_H
|
||||
#error "freetype.h of FreeType 1 has been loaded!"
|
||||
#error "Please fix the directory search order for header files"
|
||||
#error "so that freetype.h of FreeType 2 is found first."
|
||||
#endif
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* list_processing
|
||||
*
|
||||
* @title:
|
||||
* List Processing
|
||||
*
|
||||
* @abstract:
|
||||
* Simple management of lists.
|
||||
*
|
||||
* @description:
|
||||
* This section contains various definitions related to list processing
|
||||
* using doubly-linked nodes.
|
||||
*
|
||||
* @order:
|
||||
* FT_List
|
||||
* FT_ListNode
|
||||
* FT_ListRec
|
||||
* FT_ListNodeRec
|
||||
*
|
||||
* FT_List_Add
|
||||
* FT_List_Insert
|
||||
* FT_List_Find
|
||||
* FT_List_Remove
|
||||
* FT_List_Up
|
||||
* FT_List_Iterate
|
||||
* FT_List_Iterator
|
||||
* FT_List_Finalize
|
||||
* FT_List_Destructor
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_List_Find
|
||||
*
|
||||
* @description:
|
||||
* Find the list node for a given listed object.
|
||||
*
|
||||
* @input:
|
||||
* list ::
|
||||
* A pointer to the parent list.
|
||||
* data ::
|
||||
* The address of the listed object.
|
||||
*
|
||||
* @return:
|
||||
* List node. `NULL` if it wasn't found.
|
||||
*/
|
||||
FT_EXPORT( FT_ListNode )
|
||||
FT_List_Find( FT_List list,
|
||||
void* data );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_List_Add
|
||||
*
|
||||
* @description:
|
||||
* Append an element to the end of a list.
|
||||
*
|
||||
* @inout:
|
||||
* list ::
|
||||
* A pointer to the parent list.
|
||||
* node ::
|
||||
* The node to append.
|
||||
*/
|
||||
FT_EXPORT( void )
|
||||
FT_List_Add( FT_List list,
|
||||
FT_ListNode node );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_List_Insert
|
||||
*
|
||||
* @description:
|
||||
* Insert an element at the head of a list.
|
||||
*
|
||||
* @inout:
|
||||
* list ::
|
||||
* A pointer to parent list.
|
||||
* node ::
|
||||
* The node to insert.
|
||||
*/
|
||||
FT_EXPORT( void )
|
||||
FT_List_Insert( FT_List list,
|
||||
FT_ListNode node );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_List_Remove
|
||||
*
|
||||
* @description:
|
||||
* Remove a node from a list. This function doesn't check whether the
|
||||
* node is in the list!
|
||||
*
|
||||
* @input:
|
||||
* node ::
|
||||
* The node to remove.
|
||||
*
|
||||
* @inout:
|
||||
* list ::
|
||||
* A pointer to the parent list.
|
||||
*/
|
||||
FT_EXPORT( void )
|
||||
FT_List_Remove( FT_List list,
|
||||
FT_ListNode node );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_List_Up
|
||||
*
|
||||
* @description:
|
||||
* Move a node to the head/top of a list. Used to maintain LRU lists.
|
||||
*
|
||||
* @inout:
|
||||
* list ::
|
||||
* A pointer to the parent list.
|
||||
* node ::
|
||||
* The node to move.
|
||||
*/
|
||||
FT_EXPORT( void )
|
||||
FT_List_Up( FT_List list,
|
||||
FT_ListNode node );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @functype:
|
||||
* FT_List_Iterator
|
||||
*
|
||||
* @description:
|
||||
* An FT_List iterator function that is called during a list parse by
|
||||
* @FT_List_Iterate.
|
||||
*
|
||||
* @input:
|
||||
* node ::
|
||||
* The current iteration list node.
|
||||
*
|
||||
* user ::
|
||||
* A typeless pointer passed to @FT_List_Iterate. Can be used to point
|
||||
* to the iteration's state.
|
||||
*/
|
||||
typedef FT_Error
|
||||
(*FT_List_Iterator)( FT_ListNode node,
|
||||
void* user );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_List_Iterate
|
||||
*
|
||||
* @description:
|
||||
* Parse a list and calls a given iterator function on each element.
|
||||
* Note that parsing is stopped as soon as one of the iterator calls
|
||||
* returns a non-zero value.
|
||||
*
|
||||
* @input:
|
||||
* list ::
|
||||
* A handle to the list.
|
||||
* iterator ::
|
||||
* An iterator function, called on each node of the list.
|
||||
* user ::
|
||||
* A user-supplied field that is passed as the second argument to the
|
||||
* iterator.
|
||||
*
|
||||
* @return:
|
||||
* The result (a FreeType error code) of the last iterator call.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_List_Iterate( FT_List list,
|
||||
FT_List_Iterator iterator,
|
||||
void* user );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @functype:
|
||||
* FT_List_Destructor
|
||||
*
|
||||
* @description:
|
||||
* An @FT_List iterator function that is called during a list
|
||||
* finalization by @FT_List_Finalize to destroy all elements in a given
|
||||
* list.
|
||||
*
|
||||
* @input:
|
||||
* system ::
|
||||
* The current system object.
|
||||
*
|
||||
* data ::
|
||||
* The current object to destroy.
|
||||
*
|
||||
* user ::
|
||||
* A typeless pointer passed to @FT_List_Iterate. It can be used to
|
||||
* point to the iteration's state.
|
||||
*/
|
||||
typedef void
|
||||
(*FT_List_Destructor)( FT_Memory memory,
|
||||
void* data,
|
||||
void* user );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_List_Finalize
|
||||
*
|
||||
* @description:
|
||||
* Destroy all elements in the list as well as the list itself.
|
||||
*
|
||||
* @input:
|
||||
* list ::
|
||||
* A handle to the list.
|
||||
*
|
||||
* destroy ::
|
||||
* A list destructor that will be applied to each element of the list.
|
||||
* Set this to `NULL` if not needed.
|
||||
*
|
||||
* memory ::
|
||||
* The current memory object that handles deallocation.
|
||||
*
|
||||
* user ::
|
||||
* A user-supplied field that is passed as the last argument to the
|
||||
* destructor.
|
||||
*
|
||||
* @note:
|
||||
* This function expects that all nodes added by @FT_List_Add or
|
||||
* @FT_List_Insert have been dynamically allocated.
|
||||
*/
|
||||
FT_EXPORT( void )
|
||||
FT_List_Finalize( FT_List list,
|
||||
FT_List_Destructor destroy,
|
||||
FT_Memory memory,
|
||||
void* user );
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* FTLIST_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
184
vendor/freetype/include/freetype/ftlogging.h
vendored
Normal file
184
vendor/freetype/include/freetype/ftlogging.h
vendored
Normal file
@@ -0,0 +1,184 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftlogging.h
|
||||
*
|
||||
* Additional debugging APIs.
|
||||
*
|
||||
* Copyright (C) 2020-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FTLOGGING_H_
|
||||
#define FTLOGGING_H_
|
||||
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_CONFIG_CONFIG_H
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* debugging_apis
|
||||
*
|
||||
* @title:
|
||||
* External Debugging APIs
|
||||
*
|
||||
* @abstract:
|
||||
* Public APIs to control the `FT_DEBUG_LOGGING` macro.
|
||||
*
|
||||
* @description:
|
||||
* This section contains the declarations of public functions that
|
||||
* enables fine control of what the `FT_DEBUG_LOGGING` macro outputs.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Trace_Set_Level
|
||||
*
|
||||
* @description:
|
||||
* Change the levels of tracing components of FreeType at run time.
|
||||
*
|
||||
* @input:
|
||||
* tracing_level ::
|
||||
* New tracing value.
|
||||
*
|
||||
* @example:
|
||||
* The following call makes FreeType trace everything but the 'memory'
|
||||
* component.
|
||||
*
|
||||
* ```
|
||||
* FT_Trace_Set_Level( "any:7 memory:0" );
|
||||
* ```
|
||||
*
|
||||
* @note:
|
||||
* This function does nothing if compilation option `FT_DEBUG_LOGGING`
|
||||
* isn't set.
|
||||
*
|
||||
* @since:
|
||||
* 2.11
|
||||
*
|
||||
*/
|
||||
FT_EXPORT( void )
|
||||
FT_Trace_Set_Level( const char* tracing_level );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Trace_Set_Default_Level
|
||||
*
|
||||
* @description:
|
||||
* Reset tracing value of FreeType's components to the default value
|
||||
* (i.e., to the value of the `FT2_DEBUG` environment value or to NULL
|
||||
* if `FT2_DEBUG` is not set).
|
||||
*
|
||||
* @note:
|
||||
* This function does nothing if compilation option `FT_DEBUG_LOGGING`
|
||||
* isn't set.
|
||||
*
|
||||
* @since:
|
||||
* 2.11
|
||||
*
|
||||
*/
|
||||
FT_EXPORT( void )
|
||||
FT_Trace_Set_Default_Level( void );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @functype:
|
||||
* FT_Custom_Log_Handler
|
||||
*
|
||||
* @description:
|
||||
* A function typedef that is used to handle the logging of tracing and
|
||||
* debug messages on a file system.
|
||||
*
|
||||
* @input:
|
||||
* ft_component ::
|
||||
* The name of `FT_COMPONENT` from which the current debug or error
|
||||
* message is produced.
|
||||
*
|
||||
* fmt ::
|
||||
* Actual debug or tracing message.
|
||||
*
|
||||
* args::
|
||||
* Arguments of debug or tracing messages.
|
||||
*
|
||||
* @since:
|
||||
* 2.11
|
||||
*
|
||||
*/
|
||||
typedef void
|
||||
(*FT_Custom_Log_Handler)( const char* ft_component,
|
||||
const char* fmt,
|
||||
va_list args );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Set_Log_Handler
|
||||
*
|
||||
* @description:
|
||||
* A function to set a custom log handler.
|
||||
*
|
||||
* @input:
|
||||
* handler ::
|
||||
* New logging function.
|
||||
*
|
||||
* @note:
|
||||
* This function does nothing if compilation option `FT_DEBUG_LOGGING`
|
||||
* isn't set.
|
||||
*
|
||||
* @since:
|
||||
* 2.11
|
||||
*
|
||||
*/
|
||||
FT_EXPORT( void )
|
||||
FT_Set_Log_Handler( FT_Custom_Log_Handler handler );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Set_Default_Log_Handler
|
||||
*
|
||||
* @description:
|
||||
* A function to undo the effect of @FT_Set_Log_Handler, resetting the
|
||||
* log handler to FreeType's built-in version.
|
||||
*
|
||||
* @note:
|
||||
* This function does nothing if compilation option `FT_DEBUG_LOGGING`
|
||||
* isn't set.
|
||||
*
|
||||
* @since:
|
||||
* 2.11
|
||||
*
|
||||
*/
|
||||
FT_EXPORT( void )
|
||||
FT_Set_Default_Log_Handler( void );
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* FTLOGGING_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
100
vendor/freetype/include/freetype/ftlzw.h
vendored
Normal file
100
vendor/freetype/include/freetype/ftlzw.h
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftlzw.h
|
||||
*
|
||||
* LZW-compressed stream support.
|
||||
*
|
||||
* Copyright (C) 2004-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FTLZW_H_
|
||||
#define FTLZW_H_
|
||||
|
||||
#include <freetype/freetype.h>
|
||||
|
||||
#ifdef FREETYPE_H
|
||||
#error "freetype.h of FreeType 1 has been loaded!"
|
||||
#error "Please fix the directory search order for header files"
|
||||
#error "so that freetype.h of FreeType 2 is found first."
|
||||
#endif
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* lzw
|
||||
*
|
||||
* @title:
|
||||
* LZW Streams
|
||||
*
|
||||
* @abstract:
|
||||
* Using LZW-compressed font files.
|
||||
*
|
||||
* @description:
|
||||
* In certain builds of the library, LZW compression recognition is
|
||||
* automatically handled when calling @FT_New_Face or @FT_Open_Face.
|
||||
* This means that if no font driver is capable of handling the raw
|
||||
* compressed file, the library will try to open a LZW stream from it and
|
||||
* re-open the face with it.
|
||||
*
|
||||
* The stream implementation is very basic and resets the decompression
|
||||
* process each time seeking backwards is needed within the stream,
|
||||
* which significantly undermines the performance.
|
||||
*
|
||||
* This section contains the declaration of LZW-specific functions.
|
||||
*
|
||||
*/
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Stream_OpenLZW
|
||||
*
|
||||
* @description:
|
||||
* Open a new stream to parse LZW-compressed font files. This is mainly
|
||||
* used to support the compressed `*.pcf.Z` fonts that come with XFree86.
|
||||
*
|
||||
* @input:
|
||||
* stream ::
|
||||
* The target embedding stream.
|
||||
*
|
||||
* source ::
|
||||
* The source stream.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* The source stream must be opened _before_ calling this function.
|
||||
*
|
||||
* Calling the internal function `FT_Stream_Close` on the new stream will
|
||||
* **not** call `FT_Stream_Close` on the source stream. None of the
|
||||
* stream objects will be released to the heap.
|
||||
*
|
||||
* This function may return `FT_Err_Unimplemented_Feature` if your build
|
||||
* of FreeType was not compiled with LZW support.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Stream_OpenLZW( FT_Stream stream,
|
||||
FT_Stream source );
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* FTLZW_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
289
vendor/freetype/include/freetype/ftmac.h
vendored
Normal file
289
vendor/freetype/include/freetype/ftmac.h
vendored
Normal file
@@ -0,0 +1,289 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftmac.h
|
||||
*
|
||||
* Additional Mac-specific API.
|
||||
*
|
||||
* Copyright (C) 1996-2024 by
|
||||
* Just van Rossum, David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* NOTE: Include this file after `FT_FREETYPE_H` and after any
|
||||
* Mac-specific headers (because this header uses Mac types such as
|
||||
* 'Handle', 'FSSpec', 'FSRef', etc.)
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FTMAC_H_
|
||||
#define FTMAC_H_
|
||||
|
||||
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
|
||||
/* gcc-3.1 and later can warn about functions tagged as deprecated */
|
||||
#ifndef FT_DEPRECATED_ATTRIBUTE
|
||||
#if defined( __GNUC__ ) && \
|
||||
( ( __GNUC__ >= 4 ) || \
|
||||
( ( __GNUC__ == 3 ) && ( __GNUC_MINOR__ >= 1 ) ) )
|
||||
#define FT_DEPRECATED_ATTRIBUTE __attribute__(( deprecated ))
|
||||
#else
|
||||
#define FT_DEPRECATED_ATTRIBUTE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* mac_specific
|
||||
*
|
||||
* @title:
|
||||
* Mac Specific Interface
|
||||
*
|
||||
* @abstract:
|
||||
* Only available on the Macintosh.
|
||||
*
|
||||
* @description:
|
||||
* The following definitions are only available if FreeType is compiled
|
||||
* on a Macintosh.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_New_Face_From_FOND
|
||||
*
|
||||
* @description:
|
||||
* Create a new face object from a FOND resource.
|
||||
*
|
||||
* @inout:
|
||||
* library ::
|
||||
* A handle to the library resource.
|
||||
*
|
||||
* @input:
|
||||
* fond ::
|
||||
* A FOND resource.
|
||||
*
|
||||
* face_index ::
|
||||
* Only supported for the -1 'sanity check' special case.
|
||||
*
|
||||
* @output:
|
||||
* aface ::
|
||||
* A handle to a new face object.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @example:
|
||||
* This function can be used to create @FT_Face objects from fonts that
|
||||
* are installed in the system as follows.
|
||||
*
|
||||
* ```
|
||||
* fond = GetResource( 'FOND', fontName );
|
||||
* error = FT_New_Face_From_FOND( library, fond, 0, &face );
|
||||
* ```
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_New_Face_From_FOND( FT_Library library,
|
||||
Handle fond,
|
||||
FT_Long face_index,
|
||||
FT_Face *aface )
|
||||
FT_DEPRECATED_ATTRIBUTE;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_GetFile_From_Mac_Name
|
||||
*
|
||||
* @description:
|
||||
* Return an FSSpec for the disk file containing the named font.
|
||||
*
|
||||
* @input:
|
||||
* fontName ::
|
||||
* Mac OS name of the font (e.g., Times New Roman Bold).
|
||||
*
|
||||
* @output:
|
||||
* pathSpec ::
|
||||
* FSSpec to the file. For passing to @FT_New_Face_From_FSSpec.
|
||||
*
|
||||
* face_index ::
|
||||
* Index of the face. For passing to @FT_New_Face_From_FSSpec.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_GetFile_From_Mac_Name( const char* fontName,
|
||||
FSSpec* pathSpec,
|
||||
FT_Long* face_index )
|
||||
FT_DEPRECATED_ATTRIBUTE;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_GetFile_From_Mac_ATS_Name
|
||||
*
|
||||
* @description:
|
||||
* Return an FSSpec for the disk file containing the named font.
|
||||
*
|
||||
* @input:
|
||||
* fontName ::
|
||||
* Mac OS name of the font in ATS framework.
|
||||
*
|
||||
* @output:
|
||||
* pathSpec ::
|
||||
* FSSpec to the file. For passing to @FT_New_Face_From_FSSpec.
|
||||
*
|
||||
* face_index ::
|
||||
* Index of the face. For passing to @FT_New_Face_From_FSSpec.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_GetFile_From_Mac_ATS_Name( const char* fontName,
|
||||
FSSpec* pathSpec,
|
||||
FT_Long* face_index )
|
||||
FT_DEPRECATED_ATTRIBUTE;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_GetFilePath_From_Mac_ATS_Name
|
||||
*
|
||||
* @description:
|
||||
* Return a pathname of the disk file and face index for given font name
|
||||
* that is handled by ATS framework.
|
||||
*
|
||||
* @input:
|
||||
* fontName ::
|
||||
* Mac OS name of the font in ATS framework.
|
||||
*
|
||||
* @output:
|
||||
* path ::
|
||||
* Buffer to store pathname of the file. For passing to @FT_New_Face.
|
||||
* The client must allocate this buffer before calling this function.
|
||||
*
|
||||
* maxPathSize ::
|
||||
* Lengths of the buffer `path` that client allocated.
|
||||
*
|
||||
* face_index ::
|
||||
* Index of the face. For passing to @FT_New_Face.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_GetFilePath_From_Mac_ATS_Name( const char* fontName,
|
||||
UInt8* path,
|
||||
UInt32 maxPathSize,
|
||||
FT_Long* face_index )
|
||||
FT_DEPRECATED_ATTRIBUTE;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_New_Face_From_FSSpec
|
||||
*
|
||||
* @description:
|
||||
* Create a new face object from a given resource and typeface index
|
||||
* using an FSSpec to the font file.
|
||||
*
|
||||
* @inout:
|
||||
* library ::
|
||||
* A handle to the library resource.
|
||||
*
|
||||
* @input:
|
||||
* spec ::
|
||||
* FSSpec to the font file.
|
||||
*
|
||||
* face_index ::
|
||||
* The index of the face within the resource. The first face has
|
||||
* index~0.
|
||||
* @output:
|
||||
* aface ::
|
||||
* A handle to a new face object.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* @FT_New_Face_From_FSSpec is identical to @FT_New_Face except it
|
||||
* accepts an FSSpec instead of a path.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_New_Face_From_FSSpec( FT_Library library,
|
||||
const FSSpec *spec,
|
||||
FT_Long face_index,
|
||||
FT_Face *aface )
|
||||
FT_DEPRECATED_ATTRIBUTE;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_New_Face_From_FSRef
|
||||
*
|
||||
* @description:
|
||||
* Create a new face object from a given resource and typeface index
|
||||
* using an FSRef to the font file.
|
||||
*
|
||||
* @inout:
|
||||
* library ::
|
||||
* A handle to the library resource.
|
||||
*
|
||||
* @input:
|
||||
* spec ::
|
||||
* FSRef to the font file.
|
||||
*
|
||||
* face_index ::
|
||||
* The index of the face within the resource. The first face has
|
||||
* index~0.
|
||||
* @output:
|
||||
* aface ::
|
||||
* A handle to a new face object.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* @FT_New_Face_From_FSRef is identical to @FT_New_Face except it accepts
|
||||
* an FSRef instead of a path.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_New_Face_From_FSRef( FT_Library library,
|
||||
const FSRef *ref,
|
||||
FT_Long face_index,
|
||||
FT_Face *aface )
|
||||
FT_DEPRECATED_ATTRIBUTE;
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
|
||||
#endif /* FTMAC_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
834
vendor/freetype/include/freetype/ftmm.h
vendored
Normal file
834
vendor/freetype/include/freetype/ftmm.h
vendored
Normal file
@@ -0,0 +1,834 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftmm.h
|
||||
*
|
||||
* FreeType Multiple Master font interface (specification).
|
||||
*
|
||||
* Copyright (C) 1996-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FTMM_H_
|
||||
#define FTMM_H_
|
||||
|
||||
#include <freetype/freetype.h>
|
||||
|
||||
#ifdef FREETYPE_H
|
||||
#error "freetype.h of FreeType 1 has been loaded!"
|
||||
#error "Please fix the directory search order for header files"
|
||||
#error "so that freetype.h of FreeType 2 is found first."
|
||||
#endif
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* multiple_masters
|
||||
*
|
||||
* @title:
|
||||
* Multiple Masters
|
||||
*
|
||||
* @abstract:
|
||||
* How to manage Multiple Masters fonts.
|
||||
*
|
||||
* @description:
|
||||
* The following types and functions are used to manage Multiple Master
|
||||
* fonts, i.e., the selection of specific design instances by setting
|
||||
* design axis coordinates.
|
||||
*
|
||||
* Besides Adobe MM fonts, the interface supports Apple's TrueType GX and
|
||||
* OpenType variation fonts. Some of the routines only work with Adobe
|
||||
* MM fonts, others will work with all three types. They are similar
|
||||
* enough that a consistent interface makes sense.
|
||||
*
|
||||
* For Adobe MM fonts, macro @FT_IS_SFNT returns false. For GX and
|
||||
* OpenType variation fonts, it returns true.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @enum:
|
||||
* T1_MAX_MM_XXX
|
||||
*
|
||||
* @description:
|
||||
* Multiple Masters limits as defined in their specifications.
|
||||
*
|
||||
* @values:
|
||||
* T1_MAX_MM_AXIS ::
|
||||
* The maximum number of Multiple Masters axes.
|
||||
*
|
||||
* T1_MAX_MM_DESIGNS ::
|
||||
* The maximum number of Multiple Masters designs.
|
||||
*
|
||||
* T1_MAX_MM_MAP_POINTS ::
|
||||
* The maximum number of elements in a design map.
|
||||
*
|
||||
*/
|
||||
#define T1_MAX_MM_AXIS 4
|
||||
#define T1_MAX_MM_DESIGNS 16
|
||||
#define T1_MAX_MM_MAP_POINTS 20
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @struct:
|
||||
* FT_MM_Axis
|
||||
*
|
||||
* @description:
|
||||
* A structure to model a given axis in design space for Multiple Masters
|
||||
* fonts.
|
||||
*
|
||||
* This structure can't be used for TrueType GX or OpenType variation
|
||||
* fonts.
|
||||
*
|
||||
* @fields:
|
||||
* name ::
|
||||
* The axis's name.
|
||||
*
|
||||
* minimum ::
|
||||
* The axis's minimum design coordinate.
|
||||
*
|
||||
* maximum ::
|
||||
* The axis's maximum design coordinate.
|
||||
*/
|
||||
typedef struct FT_MM_Axis_
|
||||
{
|
||||
FT_String* name;
|
||||
FT_Long minimum;
|
||||
FT_Long maximum;
|
||||
|
||||
} FT_MM_Axis;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @struct:
|
||||
* FT_Multi_Master
|
||||
*
|
||||
* @description:
|
||||
* A structure to model the axes and space of a Multiple Masters font.
|
||||
*
|
||||
* This structure can't be used for TrueType GX or OpenType variation
|
||||
* fonts.
|
||||
*
|
||||
* @fields:
|
||||
* num_axis ::
|
||||
* Number of axes. Cannot exceed~4.
|
||||
*
|
||||
* num_designs ::
|
||||
* Number of designs; should be normally 2^num_axis even though the
|
||||
* Type~1 specification strangely allows for intermediate designs to be
|
||||
* present. This number cannot exceed~16.
|
||||
*
|
||||
* axis ::
|
||||
* A table of axis descriptors.
|
||||
*/
|
||||
typedef struct FT_Multi_Master_
|
||||
{
|
||||
FT_UInt num_axis;
|
||||
FT_UInt num_designs;
|
||||
FT_MM_Axis axis[T1_MAX_MM_AXIS];
|
||||
|
||||
} FT_Multi_Master;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @struct:
|
||||
* FT_Var_Axis
|
||||
*
|
||||
* @description:
|
||||
* A structure to model a given axis in design space for Multiple
|
||||
* Masters, TrueType GX, and OpenType variation fonts.
|
||||
*
|
||||
* @fields:
|
||||
* name ::
|
||||
* The axis's name. Not always meaningful for TrueType GX or OpenType
|
||||
* variation fonts.
|
||||
*
|
||||
* minimum ::
|
||||
* The axis's minimum design coordinate.
|
||||
*
|
||||
* def ::
|
||||
* The axis's default design coordinate. FreeType computes meaningful
|
||||
* default values for Adobe MM fonts.
|
||||
*
|
||||
* maximum ::
|
||||
* The axis's maximum design coordinate.
|
||||
*
|
||||
* tag ::
|
||||
* The axis's tag (the equivalent to 'name' for TrueType GX and
|
||||
* OpenType variation fonts). FreeType provides default values for
|
||||
* Adobe MM fonts if possible.
|
||||
*
|
||||
* strid ::
|
||||
* The axis name entry in the font's 'name' table. This is another
|
||||
* (and often better) version of the 'name' field for TrueType GX or
|
||||
* OpenType variation fonts. Not meaningful for Adobe MM fonts.
|
||||
*
|
||||
* @note:
|
||||
* The fields `minimum`, `def`, and `maximum` are 16.16 fractional values
|
||||
* for TrueType GX and OpenType variation fonts. For Adobe MM fonts, the
|
||||
* values are whole numbers (i.e., the fractional part is zero).
|
||||
*/
|
||||
typedef struct FT_Var_Axis_
|
||||
{
|
||||
FT_String* name;
|
||||
|
||||
FT_Fixed minimum;
|
||||
FT_Fixed def;
|
||||
FT_Fixed maximum;
|
||||
|
||||
FT_ULong tag;
|
||||
FT_UInt strid;
|
||||
|
||||
} FT_Var_Axis;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @struct:
|
||||
* FT_Var_Named_Style
|
||||
*
|
||||
* @description:
|
||||
* A structure to model a named instance in a TrueType GX or OpenType
|
||||
* variation font.
|
||||
*
|
||||
* This structure can't be used for Adobe MM fonts.
|
||||
*
|
||||
* @fields:
|
||||
* coords ::
|
||||
* The design coordinates for this instance. This is an array with one
|
||||
* entry for each axis.
|
||||
*
|
||||
* strid ::
|
||||
* The entry in 'name' table identifying this instance.
|
||||
*
|
||||
* psid ::
|
||||
* The entry in 'name' table identifying a PostScript name for this
|
||||
* instance. Value 0xFFFF indicates a missing entry.
|
||||
*/
|
||||
typedef struct FT_Var_Named_Style_
|
||||
{
|
||||
FT_Fixed* coords;
|
||||
FT_UInt strid;
|
||||
FT_UInt psid; /* since 2.7.1 */
|
||||
|
||||
} FT_Var_Named_Style;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @struct:
|
||||
* FT_MM_Var
|
||||
*
|
||||
* @description:
|
||||
* A structure to model the axes and space of an Adobe MM, TrueType GX,
|
||||
* or OpenType variation font.
|
||||
*
|
||||
* Some fields are specific to one format and not to the others.
|
||||
*
|
||||
* @fields:
|
||||
* num_axis ::
|
||||
* The number of axes. The maximum value is~4 for Adobe MM fonts; no
|
||||
* limit in TrueType GX or OpenType variation fonts.
|
||||
*
|
||||
* num_designs ::
|
||||
* The number of designs; should be normally 2^num_axis for Adobe MM
|
||||
* fonts. Not meaningful for TrueType GX or OpenType variation fonts
|
||||
* (where every glyph could have a different number of designs).
|
||||
*
|
||||
* num_namedstyles ::
|
||||
* The number of named styles; a 'named style' is a tuple of design
|
||||
* coordinates that has a string ID (in the 'name' table) associated
|
||||
* with it. The font can tell the user that, for example,
|
||||
* [Weight=1.5,Width=1.1] is 'Bold'. Another name for 'named style' is
|
||||
* 'named instance'.
|
||||
*
|
||||
* For Adobe Multiple Masters fonts, this value is always zero because
|
||||
* the format does not support named styles.
|
||||
*
|
||||
* axis ::
|
||||
* An axis descriptor table. TrueType GX and OpenType variation fonts
|
||||
* contain slightly more data than Adobe MM fonts. Memory management
|
||||
* of this pointer is done internally by FreeType.
|
||||
*
|
||||
* namedstyle ::
|
||||
* A named style (instance) table. Only meaningful for TrueType GX and
|
||||
* OpenType variation fonts. Memory management of this pointer is done
|
||||
* internally by FreeType.
|
||||
*/
|
||||
typedef struct FT_MM_Var_
|
||||
{
|
||||
FT_UInt num_axis;
|
||||
FT_UInt num_designs;
|
||||
FT_UInt num_namedstyles;
|
||||
FT_Var_Axis* axis;
|
||||
FT_Var_Named_Style* namedstyle;
|
||||
|
||||
} FT_MM_Var;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Get_Multi_Master
|
||||
*
|
||||
* @description:
|
||||
* Retrieve a variation descriptor of a given Adobe MM font.
|
||||
*
|
||||
* This function can't be used with TrueType GX or OpenType variation
|
||||
* fonts.
|
||||
*
|
||||
* @input:
|
||||
* face ::
|
||||
* A handle to the source face.
|
||||
*
|
||||
* @output:
|
||||
* amaster ::
|
||||
* The Multiple Masters descriptor.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Get_Multi_Master( FT_Face face,
|
||||
FT_Multi_Master *amaster );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Get_MM_Var
|
||||
*
|
||||
* @description:
|
||||
* Retrieve a variation descriptor for a given font.
|
||||
*
|
||||
* This function works with all supported variation formats.
|
||||
*
|
||||
* @input:
|
||||
* face ::
|
||||
* A handle to the source face.
|
||||
*
|
||||
* @output:
|
||||
* amaster ::
|
||||
* The variation descriptor. Allocates a data structure, which the
|
||||
* user must deallocate with a call to @FT_Done_MM_Var after use.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Get_MM_Var( FT_Face face,
|
||||
FT_MM_Var* *amaster );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Done_MM_Var
|
||||
*
|
||||
* @description:
|
||||
* Free the memory allocated by @FT_Get_MM_Var.
|
||||
*
|
||||
* @input:
|
||||
* library ::
|
||||
* A handle of the face's parent library object that was used in the
|
||||
* call to @FT_Get_MM_Var to create `amaster`.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Done_MM_Var( FT_Library library,
|
||||
FT_MM_Var *amaster );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Set_MM_Design_Coordinates
|
||||
*
|
||||
* @description:
|
||||
* For Adobe MM fonts, choose an interpolated font design through design
|
||||
* coordinates.
|
||||
*
|
||||
* This function can't be used with TrueType GX or OpenType variation
|
||||
* fonts.
|
||||
*
|
||||
* @inout:
|
||||
* face ::
|
||||
* A handle to the source face.
|
||||
*
|
||||
* @input:
|
||||
* num_coords ::
|
||||
* The number of available design coordinates. If it is larger than
|
||||
* the number of axes, ignore the excess values. If it is smaller than
|
||||
* the number of axes, use default values for the remaining axes.
|
||||
*
|
||||
* coords ::
|
||||
* An array of design coordinates.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* [Since 2.8.1] To reset all axes to the default values, call the
|
||||
* function with `num_coords` set to zero and `coords` set to `NULL`.
|
||||
*
|
||||
* [Since 2.9] If `num_coords` is larger than zero, this function sets
|
||||
* the @FT_FACE_FLAG_VARIATION bit in @FT_Face's `face_flags` field
|
||||
* (i.e., @FT_IS_VARIATION will return true). If `num_coords` is zero,
|
||||
* this bit flag gets unset.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Set_MM_Design_Coordinates( FT_Face face,
|
||||
FT_UInt num_coords,
|
||||
FT_Long* coords );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Set_Var_Design_Coordinates
|
||||
*
|
||||
* @description:
|
||||
* Choose an interpolated font design through design coordinates.
|
||||
*
|
||||
* This function works with all supported variation formats.
|
||||
*
|
||||
* @inout:
|
||||
* face ::
|
||||
* A handle to the source face.
|
||||
*
|
||||
* @input:
|
||||
* num_coords ::
|
||||
* The number of available design coordinates. If it is larger than
|
||||
* the number of axes, ignore the excess values. If it is smaller than
|
||||
* the number of axes, use default values for the remaining axes.
|
||||
*
|
||||
* coords ::
|
||||
* An array of design coordinates.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* The design coordinates are 16.16 fractional values for TrueType GX and
|
||||
* OpenType variation fonts. For Adobe MM fonts, the values are supposed
|
||||
* to be whole numbers (i.e., the fractional part is zero).
|
||||
*
|
||||
* [Since 2.8.1] To reset all axes to the default values, call the
|
||||
* function with `num_coords` set to zero and `coords` set to `NULL`.
|
||||
* [Since 2.9] 'Default values' means the currently selected named
|
||||
* instance (or the base font if no named instance is selected).
|
||||
*
|
||||
* [Since 2.9] If `num_coords` is larger than zero, this function sets
|
||||
* the @FT_FACE_FLAG_VARIATION bit in @FT_Face's `face_flags` field
|
||||
* (i.e., @FT_IS_VARIATION will return true). If `num_coords` is zero,
|
||||
* this bit flag gets unset.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Set_Var_Design_Coordinates( FT_Face face,
|
||||
FT_UInt num_coords,
|
||||
FT_Fixed* coords );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Get_Var_Design_Coordinates
|
||||
*
|
||||
* @description:
|
||||
* Get the design coordinates of the currently selected interpolated
|
||||
* font.
|
||||
*
|
||||
* This function works with all supported variation formats.
|
||||
*
|
||||
* @input:
|
||||
* face ::
|
||||
* A handle to the source face.
|
||||
*
|
||||
* num_coords ::
|
||||
* The number of design coordinates to retrieve. If it is larger than
|
||||
* the number of axes, set the excess values to~0.
|
||||
*
|
||||
* @output:
|
||||
* coords ::
|
||||
* The design coordinates array.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* The design coordinates are 16.16 fractional values for TrueType GX and
|
||||
* OpenType variation fonts. For Adobe MM fonts, the values are whole
|
||||
* numbers (i.e., the fractional part is zero).
|
||||
*
|
||||
* @since:
|
||||
* 2.7.1
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Get_Var_Design_Coordinates( FT_Face face,
|
||||
FT_UInt num_coords,
|
||||
FT_Fixed* coords );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Set_MM_Blend_Coordinates
|
||||
*
|
||||
* @description:
|
||||
* Choose an interpolated font design through normalized blend
|
||||
* coordinates.
|
||||
*
|
||||
* This function works with all supported variation formats.
|
||||
*
|
||||
* @inout:
|
||||
* face ::
|
||||
* A handle to the source face.
|
||||
*
|
||||
* @input:
|
||||
* num_coords ::
|
||||
* The number of available design coordinates. If it is larger than
|
||||
* the number of axes, ignore the excess values. If it is smaller than
|
||||
* the number of axes, use default values for the remaining axes.
|
||||
*
|
||||
* coords ::
|
||||
* The design coordinates array. Each element is a 16.16 fractional
|
||||
* value and must be between 0 and 1.0 for Adobe MM fonts, and between
|
||||
* -1.0 and 1.0 for TrueType GX and OpenType variation fonts.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* [Since 2.8.1] To reset all axes to the default values, call the
|
||||
* function with `num_coords` set to zero and `coords` set to `NULL`.
|
||||
* [Since 2.9] 'Default values' means the currently selected named
|
||||
* instance (or the base font if no named instance is selected).
|
||||
*
|
||||
* [Since 2.9] If `num_coords` is larger than zero, this function sets
|
||||
* the @FT_FACE_FLAG_VARIATION bit in @FT_Face's `face_flags` field
|
||||
* (i.e., @FT_IS_VARIATION will return true). If `num_coords` is zero,
|
||||
* this bit flag gets unset.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Set_MM_Blend_Coordinates( FT_Face face,
|
||||
FT_UInt num_coords,
|
||||
FT_Fixed* coords );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Get_MM_Blend_Coordinates
|
||||
*
|
||||
* @description:
|
||||
* Get the normalized blend coordinates of the currently selected
|
||||
* interpolated font.
|
||||
*
|
||||
* This function works with all supported variation formats.
|
||||
*
|
||||
* @input:
|
||||
* face ::
|
||||
* A handle to the source face.
|
||||
*
|
||||
* num_coords ::
|
||||
* The number of normalized blend coordinates to retrieve. If it is
|
||||
* larger than the number of axes, set the excess values to~0.5 for
|
||||
* Adobe MM fonts, and to~0 for TrueType GX and OpenType variation
|
||||
* fonts.
|
||||
*
|
||||
* @output:
|
||||
* coords ::
|
||||
* The normalized blend coordinates array (as 16.16 fractional values).
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @since:
|
||||
* 2.7.1
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Get_MM_Blend_Coordinates( FT_Face face,
|
||||
FT_UInt num_coords,
|
||||
FT_Fixed* coords );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Set_Var_Blend_Coordinates
|
||||
*
|
||||
* @description:
|
||||
* This is another name of @FT_Set_MM_Blend_Coordinates.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Set_Var_Blend_Coordinates( FT_Face face,
|
||||
FT_UInt num_coords,
|
||||
FT_Fixed* coords );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Get_Var_Blend_Coordinates
|
||||
*
|
||||
* @description:
|
||||
* This is another name of @FT_Get_MM_Blend_Coordinates.
|
||||
*
|
||||
* @since:
|
||||
* 2.7.1
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Get_Var_Blend_Coordinates( FT_Face face,
|
||||
FT_UInt num_coords,
|
||||
FT_Fixed* coords );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Set_MM_WeightVector
|
||||
*
|
||||
* @description:
|
||||
* For Adobe MM fonts, choose an interpolated font design by directly
|
||||
* setting the weight vector.
|
||||
*
|
||||
* This function can't be used with TrueType GX or OpenType variation
|
||||
* fonts.
|
||||
*
|
||||
* @inout:
|
||||
* face ::
|
||||
* A handle to the source face.
|
||||
*
|
||||
* @input:
|
||||
* len ::
|
||||
* The length of the weight vector array. If it is larger than the
|
||||
* number of designs, the extra values are ignored. If it is less than
|
||||
* the number of designs, the remaining values are set to zero.
|
||||
*
|
||||
* weightvector ::
|
||||
* An array representing the weight vector.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* Adobe Multiple Master fonts limit the number of designs, and thus the
|
||||
* length of the weight vector to 16~elements.
|
||||
*
|
||||
* If `len` is larger than zero, this function sets the
|
||||
* @FT_FACE_FLAG_VARIATION bit in @FT_Face's `face_flags` field (i.e.,
|
||||
* @FT_IS_VARIATION will return true). If `len` is zero, this bit flag
|
||||
* is unset and the weight vector array is reset to the default values.
|
||||
*
|
||||
* The Adobe documentation also states that the values in the
|
||||
* WeightVector array must total 1.0 +/-~0.001. In practice this does
|
||||
* not seem to be enforced, so is not enforced here, either.
|
||||
*
|
||||
* @since:
|
||||
* 2.10
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Set_MM_WeightVector( FT_Face face,
|
||||
FT_UInt len,
|
||||
FT_Fixed* weightvector );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Get_MM_WeightVector
|
||||
*
|
||||
* @description:
|
||||
* For Adobe MM fonts, retrieve the current weight vector of the font.
|
||||
*
|
||||
* This function can't be used with TrueType GX or OpenType variation
|
||||
* fonts.
|
||||
*
|
||||
* @inout:
|
||||
* face ::
|
||||
* A handle to the source face.
|
||||
*
|
||||
* len ::
|
||||
* A pointer to the size of the array to be filled. If the size of the
|
||||
* array is less than the number of designs, `FT_Err_Invalid_Argument`
|
||||
* is returned, and `len` is set to the required size (the number of
|
||||
* designs). If the size of the array is greater than the number of
|
||||
* designs, the remaining entries are set to~0. On successful
|
||||
* completion, `len` is set to the number of designs (i.e., the number
|
||||
* of values written to the array).
|
||||
*
|
||||
* @output:
|
||||
* weightvector ::
|
||||
* An array to be filled.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* Adobe Multiple Master fonts limit the number of designs, and thus the
|
||||
* length of the WeightVector to~16.
|
||||
*
|
||||
* @since:
|
||||
* 2.10
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Get_MM_WeightVector( FT_Face face,
|
||||
FT_UInt* len,
|
||||
FT_Fixed* weightvector );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @enum:
|
||||
* FT_VAR_AXIS_FLAG_XXX
|
||||
*
|
||||
* @description:
|
||||
* A list of bit flags used in the return value of
|
||||
* @FT_Get_Var_Axis_Flags.
|
||||
*
|
||||
* @values:
|
||||
* FT_VAR_AXIS_FLAG_HIDDEN ::
|
||||
* The variation axis should not be exposed to user interfaces.
|
||||
*
|
||||
* @since:
|
||||
* 2.8.1
|
||||
*/
|
||||
#define FT_VAR_AXIS_FLAG_HIDDEN 1
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Get_Var_Axis_Flags
|
||||
*
|
||||
* @description:
|
||||
* Get the 'flags' field of an OpenType Variation Axis Record.
|
||||
*
|
||||
* Not meaningful for Adobe MM fonts (`*flags` is always zero).
|
||||
*
|
||||
* @input:
|
||||
* master ::
|
||||
* The variation descriptor.
|
||||
*
|
||||
* axis_index ::
|
||||
* The index of the requested variation axis.
|
||||
*
|
||||
* @output:
|
||||
* flags ::
|
||||
* The 'flags' field. See @FT_VAR_AXIS_FLAG_XXX for possible values.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @since:
|
||||
* 2.8.1
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Get_Var_Axis_Flags( FT_MM_Var* master,
|
||||
FT_UInt axis_index,
|
||||
FT_UInt* flags );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Set_Named_Instance
|
||||
*
|
||||
* @description:
|
||||
* Set or change the current named instance.
|
||||
*
|
||||
* @input:
|
||||
* face ::
|
||||
* A handle to the source face.
|
||||
*
|
||||
* instance_index ::
|
||||
* The index of the requested instance, starting with value 1. If set
|
||||
* to value 0, FreeType switches to font access without a named
|
||||
* instance.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* The function uses the value of `instance_index` to set bits 16-30 of
|
||||
* the face's `face_index` field. It also resets any variation applied
|
||||
* to the font, and the @FT_FACE_FLAG_VARIATION bit of the face's
|
||||
* `face_flags` field gets reset to zero (i.e., @FT_IS_VARIATION will
|
||||
* return false).
|
||||
*
|
||||
* For Adobe MM fonts (which don't have named instances) this function
|
||||
* simply resets the current face to the default instance.
|
||||
*
|
||||
* @since:
|
||||
* 2.9
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Set_Named_Instance( FT_Face face,
|
||||
FT_UInt instance_index );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Get_Default_Named_Instance
|
||||
*
|
||||
* @description:
|
||||
* Retrieve the index of the default named instance, to be used with
|
||||
* @FT_Set_Named_Instance.
|
||||
*
|
||||
* The default instance of a variation font is that instance for which
|
||||
* the nth axis coordinate is equal to `axis[n].def` (as specified in the
|
||||
* @FT_MM_Var structure), with~n covering all axes.
|
||||
*
|
||||
* FreeType synthesizes a named instance for the default instance if the
|
||||
* font does not contain such an entry.
|
||||
*
|
||||
* @input:
|
||||
* face ::
|
||||
* A handle to the source face.
|
||||
*
|
||||
* @output:
|
||||
* instance_index ::
|
||||
* The index of the default named instance.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* For Adobe MM fonts (which don't have named instances) this function
|
||||
* always returns zero for `instance_index`.
|
||||
*
|
||||
* @since:
|
||||
* 2.13.1
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Get_Default_Named_Instance( FT_Face face,
|
||||
FT_UInt *instance_index );
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* FTMM_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
807
vendor/freetype/include/freetype/ftmodapi.h
vendored
Normal file
807
vendor/freetype/include/freetype/ftmodapi.h
vendored
Normal file
@@ -0,0 +1,807 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftmodapi.h
|
||||
*
|
||||
* FreeType modules public interface (specification).
|
||||
*
|
||||
* Copyright (C) 1996-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FTMODAPI_H_
|
||||
#define FTMODAPI_H_
|
||||
|
||||
|
||||
#include <freetype/freetype.h>
|
||||
|
||||
#ifdef FREETYPE_H
|
||||
#error "freetype.h of FreeType 1 has been loaded!"
|
||||
#error "Please fix the directory search order for header files"
|
||||
#error "so that freetype.h of FreeType 2 is found first."
|
||||
#endif
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* module_management
|
||||
*
|
||||
* @title:
|
||||
* Module Management
|
||||
*
|
||||
* @abstract:
|
||||
* How to add, upgrade, remove, and control modules from FreeType.
|
||||
*
|
||||
* @description:
|
||||
* The definitions below are used to manage modules within FreeType.
|
||||
* Internal and external modules can be added, upgraded, and removed at
|
||||
* runtime. For example, an alternative renderer or proprietary font
|
||||
* driver can be registered and prioritized. Additionally, some module
|
||||
* properties can also be controlled.
|
||||
*
|
||||
* Here is a list of existing values of the `module_name` field in the
|
||||
* @FT_Module_Class structure.
|
||||
*
|
||||
* ```
|
||||
* autofitter
|
||||
* bdf
|
||||
* cff
|
||||
* gxvalid
|
||||
* otvalid
|
||||
* pcf
|
||||
* pfr
|
||||
* psaux
|
||||
* pshinter
|
||||
* psnames
|
||||
* raster1
|
||||
* sfnt
|
||||
* smooth
|
||||
* truetype
|
||||
* type1
|
||||
* type42
|
||||
* t1cid
|
||||
* winfonts
|
||||
* ```
|
||||
*
|
||||
* Note that the FreeType Cache sub-system is not a FreeType module.
|
||||
*
|
||||
* @order:
|
||||
* FT_Module
|
||||
* FT_Module_Constructor
|
||||
* FT_Module_Destructor
|
||||
* FT_Module_Requester
|
||||
* FT_Module_Class
|
||||
*
|
||||
* FT_Add_Module
|
||||
* FT_Get_Module
|
||||
* FT_Remove_Module
|
||||
* FT_Add_Default_Modules
|
||||
*
|
||||
* FT_FACE_DRIVER_NAME
|
||||
* FT_Property_Set
|
||||
* FT_Property_Get
|
||||
* FT_Set_Default_Properties
|
||||
*
|
||||
* FT_New_Library
|
||||
* FT_Done_Library
|
||||
* FT_Reference_Library
|
||||
*
|
||||
* FT_Renderer
|
||||
* FT_Renderer_Class
|
||||
*
|
||||
* FT_Get_Renderer
|
||||
* FT_Set_Renderer
|
||||
*
|
||||
* FT_Set_Debug_Hook
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* module bit flags */
|
||||
#define FT_MODULE_FONT_DRIVER 1 /* this module is a font driver */
|
||||
#define FT_MODULE_RENDERER 2 /* this module is a renderer */
|
||||
#define FT_MODULE_HINTER 4 /* this module is a glyph hinter */
|
||||
#define FT_MODULE_STYLER 8 /* this module is a styler */
|
||||
|
||||
#define FT_MODULE_DRIVER_SCALABLE 0x100 /* the driver supports */
|
||||
/* scalable fonts */
|
||||
#define FT_MODULE_DRIVER_NO_OUTLINES 0x200 /* the driver does not */
|
||||
/* support vector outlines */
|
||||
#define FT_MODULE_DRIVER_HAS_HINTER 0x400 /* the driver provides its */
|
||||
/* own hinter */
|
||||
#define FT_MODULE_DRIVER_HINTS_LIGHTLY 0x800 /* the driver's hinter */
|
||||
/* produces LIGHT hints */
|
||||
|
||||
|
||||
/* deprecated values */
|
||||
#define ft_module_font_driver FT_MODULE_FONT_DRIVER
|
||||
#define ft_module_renderer FT_MODULE_RENDERER
|
||||
#define ft_module_hinter FT_MODULE_HINTER
|
||||
#define ft_module_styler FT_MODULE_STYLER
|
||||
|
||||
#define ft_module_driver_scalable FT_MODULE_DRIVER_SCALABLE
|
||||
#define ft_module_driver_no_outlines FT_MODULE_DRIVER_NO_OUTLINES
|
||||
#define ft_module_driver_has_hinter FT_MODULE_DRIVER_HAS_HINTER
|
||||
#define ft_module_driver_hints_lightly FT_MODULE_DRIVER_HINTS_LIGHTLY
|
||||
|
||||
|
||||
typedef FT_Pointer FT_Module_Interface;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @functype:
|
||||
* FT_Module_Constructor
|
||||
*
|
||||
* @description:
|
||||
* A function used to initialize (not create) a new module object.
|
||||
*
|
||||
* @input:
|
||||
* module ::
|
||||
* The module to initialize.
|
||||
*/
|
||||
typedef FT_Error
|
||||
(*FT_Module_Constructor)( FT_Module module );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @functype:
|
||||
* FT_Module_Destructor
|
||||
*
|
||||
* @description:
|
||||
* A function used to finalize (not destroy) a given module object.
|
||||
*
|
||||
* @input:
|
||||
* module ::
|
||||
* The module to finalize.
|
||||
*/
|
||||
typedef void
|
||||
(*FT_Module_Destructor)( FT_Module module );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @functype:
|
||||
* FT_Module_Requester
|
||||
*
|
||||
* @description:
|
||||
* A function used to query a given module for a specific interface.
|
||||
*
|
||||
* @input:
|
||||
* module ::
|
||||
* The module to be searched.
|
||||
*
|
||||
* name ::
|
||||
* The name of the interface in the module.
|
||||
*/
|
||||
typedef FT_Module_Interface
|
||||
(*FT_Module_Requester)( FT_Module module,
|
||||
const char* name );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @struct:
|
||||
* FT_Module_Class
|
||||
*
|
||||
* @description:
|
||||
* The module class descriptor. While being a public structure necessary
|
||||
* for FreeType's module bookkeeping, most of the fields are essentially
|
||||
* internal, not to be used directly by an application.
|
||||
*
|
||||
* @fields:
|
||||
* module_flags ::
|
||||
* Bit flags describing the module.
|
||||
*
|
||||
* module_size ::
|
||||
* The size of one module object/instance in bytes.
|
||||
*
|
||||
* module_name ::
|
||||
* The name of the module.
|
||||
*
|
||||
* module_version ::
|
||||
* The version, as a 16.16 fixed number (major.minor).
|
||||
*
|
||||
* module_requires ::
|
||||
* The version of FreeType this module requires, as a 16.16 fixed
|
||||
* number (major.minor). Starts at version 2.0, i.e., 0x20000.
|
||||
*
|
||||
* module_interface ::
|
||||
* A typeless pointer to a structure (which varies between different
|
||||
* modules) that holds the module's interface functions. This is
|
||||
* essentially what `get_interface` returns.
|
||||
*
|
||||
* module_init ::
|
||||
* The initializing function.
|
||||
*
|
||||
* module_done ::
|
||||
* The finalizing function.
|
||||
*
|
||||
* get_interface ::
|
||||
* The interface requesting function.
|
||||
*/
|
||||
typedef struct FT_Module_Class_
|
||||
{
|
||||
FT_ULong module_flags;
|
||||
FT_Long module_size;
|
||||
const FT_String* module_name;
|
||||
FT_Fixed module_version;
|
||||
FT_Fixed module_requires;
|
||||
|
||||
const void* module_interface;
|
||||
|
||||
FT_Module_Constructor module_init;
|
||||
FT_Module_Destructor module_done;
|
||||
FT_Module_Requester get_interface;
|
||||
|
||||
} FT_Module_Class;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Add_Module
|
||||
*
|
||||
* @description:
|
||||
* Add a new module to a given library instance.
|
||||
*
|
||||
* @inout:
|
||||
* library ::
|
||||
* A handle to the library object.
|
||||
*
|
||||
* @input:
|
||||
* clazz ::
|
||||
* A pointer to class descriptor for the module.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* An error will be returned if a module already exists by that name, or
|
||||
* if the module requires a version of FreeType that is too great.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Add_Module( FT_Library library,
|
||||
const FT_Module_Class* clazz );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Get_Module
|
||||
*
|
||||
* @description:
|
||||
* Find a module by its name.
|
||||
*
|
||||
* @input:
|
||||
* library ::
|
||||
* A handle to the library object.
|
||||
*
|
||||
* module_name ::
|
||||
* The module's name (as an ASCII string).
|
||||
*
|
||||
* @return:
|
||||
* A module handle. 0~if none was found.
|
||||
*
|
||||
* @note:
|
||||
* FreeType's internal modules aren't documented very well, and you
|
||||
* should look up the source code for details.
|
||||
*/
|
||||
FT_EXPORT( FT_Module )
|
||||
FT_Get_Module( FT_Library library,
|
||||
const char* module_name );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Remove_Module
|
||||
*
|
||||
* @description:
|
||||
* Remove a given module from a library instance.
|
||||
*
|
||||
* @inout:
|
||||
* library ::
|
||||
* A handle to a library object.
|
||||
*
|
||||
* @input:
|
||||
* module ::
|
||||
* A handle to a module object.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* The module object is destroyed by the function in case of success.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Remove_Module( FT_Library library,
|
||||
FT_Module module );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @macro:
|
||||
* FT_FACE_DRIVER_NAME
|
||||
*
|
||||
* @description:
|
||||
* A macro that retrieves the name of a font driver from a face object.
|
||||
*
|
||||
* @note:
|
||||
* The font driver name is a valid `module_name` for @FT_Property_Set
|
||||
* and @FT_Property_Get. This is not the same as @FT_Get_Font_Format.
|
||||
*
|
||||
* @since:
|
||||
* 2.11
|
||||
*
|
||||
*/
|
||||
#define FT_FACE_DRIVER_NAME( face ) \
|
||||
( ( *FT_REINTERPRET_CAST( FT_Module_Class**, \
|
||||
( face )->driver ) )->module_name )
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Property_Set
|
||||
*
|
||||
* @description:
|
||||
* Set a property for a given module.
|
||||
*
|
||||
* @input:
|
||||
* library ::
|
||||
* A handle to the library the module is part of.
|
||||
*
|
||||
* module_name ::
|
||||
* The module name.
|
||||
*
|
||||
* property_name ::
|
||||
* The property name. Properties are described in section
|
||||
* @properties.
|
||||
*
|
||||
* Note that only a few modules have properties.
|
||||
*
|
||||
* value ::
|
||||
* A generic pointer to a variable or structure that gives the new
|
||||
* value of the property. The exact definition of `value` is
|
||||
* dependent on the property; see section @properties.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* If `module_name` isn't a valid module name, or `property_name`
|
||||
* doesn't specify a valid property, or if `value` doesn't represent a
|
||||
* valid value for the given property, an error is returned.
|
||||
*
|
||||
* The following example sets property 'bar' (a simple integer) in
|
||||
* module 'foo' to value~1.
|
||||
*
|
||||
* ```
|
||||
* FT_UInt bar;
|
||||
*
|
||||
*
|
||||
* bar = 1;
|
||||
* FT_Property_Set( library, "foo", "bar", &bar );
|
||||
* ```
|
||||
*
|
||||
* Note that the FreeType Cache sub-system doesn't recognize module
|
||||
* property changes. To avoid glyph lookup confusion within the cache
|
||||
* you should call @FTC_Manager_Reset to completely flush the cache if a
|
||||
* module property gets changed after @FTC_Manager_New has been called.
|
||||
*
|
||||
* It is not possible to set properties of the FreeType Cache sub-system
|
||||
* itself with FT_Property_Set; use @FTC_Property_Set instead.
|
||||
*
|
||||
* @since:
|
||||
* 2.4.11
|
||||
*
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Property_Set( FT_Library library,
|
||||
const FT_String* module_name,
|
||||
const FT_String* property_name,
|
||||
const void* value );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Property_Get
|
||||
*
|
||||
* @description:
|
||||
* Get a module's property value.
|
||||
*
|
||||
* @input:
|
||||
* library ::
|
||||
* A handle to the library the module is part of.
|
||||
*
|
||||
* module_name ::
|
||||
* The module name.
|
||||
*
|
||||
* property_name ::
|
||||
* The property name. Properties are described in section
|
||||
* @properties.
|
||||
*
|
||||
* @inout:
|
||||
* value ::
|
||||
* A generic pointer to a variable or structure that gives the value
|
||||
* of the property. The exact definition of `value` is dependent on
|
||||
* the property; see section @properties.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* If `module_name` isn't a valid module name, or `property_name`
|
||||
* doesn't specify a valid property, or if `value` doesn't represent a
|
||||
* valid value for the given property, an error is returned.
|
||||
*
|
||||
* The following example gets property 'baz' (a range) in module 'foo'.
|
||||
*
|
||||
* ```
|
||||
* typedef range_
|
||||
* {
|
||||
* FT_Int32 min;
|
||||
* FT_Int32 max;
|
||||
*
|
||||
* } range;
|
||||
*
|
||||
* range baz;
|
||||
*
|
||||
*
|
||||
* FT_Property_Get( library, "foo", "baz", &baz );
|
||||
* ```
|
||||
*
|
||||
* It is not possible to retrieve properties of the FreeType Cache
|
||||
* sub-system with FT_Property_Get; use @FTC_Property_Get instead.
|
||||
*
|
||||
* @since:
|
||||
* 2.4.11
|
||||
*
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Property_Get( FT_Library library,
|
||||
const FT_String* module_name,
|
||||
const FT_String* property_name,
|
||||
void* value );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Set_Default_Properties
|
||||
*
|
||||
* @description:
|
||||
* If compilation option `FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES` is
|
||||
* set, this function reads the `FREETYPE_PROPERTIES` environment
|
||||
* variable to control driver properties. See section @properties for
|
||||
* more.
|
||||
*
|
||||
* If the compilation option is not set, this function does nothing.
|
||||
*
|
||||
* `FREETYPE_PROPERTIES` has the following syntax form (broken here into
|
||||
* multiple lines for better readability).
|
||||
*
|
||||
* ```
|
||||
* <optional whitespace>
|
||||
* <module-name1> ':'
|
||||
* <property-name1> '=' <property-value1>
|
||||
* <whitespace>
|
||||
* <module-name2> ':'
|
||||
* <property-name2> '=' <property-value2>
|
||||
* ...
|
||||
* ```
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ```
|
||||
* FREETYPE_PROPERTIES=truetype:interpreter-version=35 \
|
||||
* cff:no-stem-darkening=0
|
||||
* ```
|
||||
*
|
||||
* @inout:
|
||||
* library ::
|
||||
* A handle to a new library object.
|
||||
*
|
||||
* @since:
|
||||
* 2.8
|
||||
*/
|
||||
FT_EXPORT( void )
|
||||
FT_Set_Default_Properties( FT_Library library );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Reference_Library
|
||||
*
|
||||
* @description:
|
||||
* A counter gets initialized to~1 at the time an @FT_Library structure
|
||||
* is created. This function increments the counter. @FT_Done_Library
|
||||
* then only destroys a library if the counter is~1, otherwise it simply
|
||||
* decrements the counter.
|
||||
*
|
||||
* This function helps in managing life-cycles of structures that
|
||||
* reference @FT_Library objects.
|
||||
*
|
||||
* @input:
|
||||
* library ::
|
||||
* A handle to a target library object.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @since:
|
||||
* 2.4.2
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Reference_Library( FT_Library library );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_New_Library
|
||||
*
|
||||
* @description:
|
||||
* This function is used to create a new FreeType library instance from a
|
||||
* given memory object. It is thus possible to use libraries with
|
||||
* distinct memory allocators within the same program. Note, however,
|
||||
* that the used @FT_Memory structure is expected to remain valid for the
|
||||
* life of the @FT_Library object.
|
||||
*
|
||||
* Normally, you would call this function (followed by a call to
|
||||
* @FT_Add_Default_Modules or a series of calls to @FT_Add_Module, and a
|
||||
* call to @FT_Set_Default_Properties) instead of @FT_Init_FreeType to
|
||||
* initialize the FreeType library.
|
||||
*
|
||||
* Don't use @FT_Done_FreeType but @FT_Done_Library to destroy a library
|
||||
* instance.
|
||||
*
|
||||
* @input:
|
||||
* memory ::
|
||||
* A handle to the original memory object.
|
||||
*
|
||||
* @output:
|
||||
* alibrary ::
|
||||
* A pointer to handle of a new library object.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* See the discussion of reference counters in the description of
|
||||
* @FT_Reference_Library.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_New_Library( FT_Memory memory,
|
||||
FT_Library *alibrary );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Done_Library
|
||||
*
|
||||
* @description:
|
||||
* Discard a given library object. This closes all drivers and discards
|
||||
* all resource objects.
|
||||
*
|
||||
* @input:
|
||||
* library ::
|
||||
* A handle to the target library.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* See the discussion of reference counters in the description of
|
||||
* @FT_Reference_Library.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Done_Library( FT_Library library );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @functype:
|
||||
* FT_DebugHook_Func
|
||||
*
|
||||
* @description:
|
||||
* A drop-in replacement (or rather a wrapper) for the bytecode or
|
||||
* charstring interpreter's main loop function.
|
||||
*
|
||||
* Its job is essentially
|
||||
*
|
||||
* - to activate debug mode to enforce single-stepping,
|
||||
*
|
||||
* - to call the main loop function to interpret the next opcode, and
|
||||
*
|
||||
* - to show the changed context to the user.
|
||||
*
|
||||
* An example for such a main loop function is `TT_RunIns` (declared in
|
||||
* FreeType's internal header file `src/truetype/ttinterp.h`).
|
||||
*
|
||||
* Have a look at the source code of the `ttdebug` FreeType demo program
|
||||
* for an example of a drop-in replacement.
|
||||
*
|
||||
* @inout:
|
||||
* arg ::
|
||||
* A typeless pointer, to be cast to the main loop function's data
|
||||
* structure (which depends on the font module). For TrueType fonts
|
||||
* it is bytecode interpreter's execution context, `TT_ExecContext`,
|
||||
* which is declared in FreeType's internal header file `tttypes.h`.
|
||||
*/
|
||||
typedef FT_Error
|
||||
(*FT_DebugHook_Func)( void* arg );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @enum:
|
||||
* FT_DEBUG_HOOK_XXX
|
||||
*
|
||||
* @description:
|
||||
* A list of named debug hook indices.
|
||||
*
|
||||
* @values:
|
||||
* FT_DEBUG_HOOK_TRUETYPE::
|
||||
* This hook index identifies the TrueType bytecode debugger.
|
||||
*/
|
||||
#define FT_DEBUG_HOOK_TRUETYPE 0
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Set_Debug_Hook
|
||||
*
|
||||
* @description:
|
||||
* Set a debug hook function for debugging the interpreter of a font
|
||||
* format.
|
||||
*
|
||||
* While this is a public API function, an application needs access to
|
||||
* FreeType's internal header files to do something useful.
|
||||
*
|
||||
* Have a look at the source code of the `ttdebug` FreeType demo program
|
||||
* for an example of its usage.
|
||||
*
|
||||
* @inout:
|
||||
* library ::
|
||||
* A handle to the library object.
|
||||
*
|
||||
* @input:
|
||||
* hook_index ::
|
||||
* The index of the debug hook. You should use defined enumeration
|
||||
* macros like @FT_DEBUG_HOOK_TRUETYPE.
|
||||
*
|
||||
* debug_hook ::
|
||||
* The function used to debug the interpreter.
|
||||
*
|
||||
* @note:
|
||||
* Currently, four debug hook slots are available, but only one (for the
|
||||
* TrueType interpreter) is defined.
|
||||
*/
|
||||
FT_EXPORT( void )
|
||||
FT_Set_Debug_Hook( FT_Library library,
|
||||
FT_UInt hook_index,
|
||||
FT_DebugHook_Func debug_hook );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Add_Default_Modules
|
||||
*
|
||||
* @description:
|
||||
* Add the set of default drivers to a given library object. This is
|
||||
* only useful when you create a library object with @FT_New_Library
|
||||
* (usually to plug a custom memory manager).
|
||||
*
|
||||
* @inout:
|
||||
* library ::
|
||||
* A handle to a new library object.
|
||||
*/
|
||||
FT_EXPORT( void )
|
||||
FT_Add_Default_Modules( FT_Library library );
|
||||
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* truetype_engine
|
||||
*
|
||||
* @title:
|
||||
* The TrueType Engine
|
||||
*
|
||||
* @abstract:
|
||||
* TrueType bytecode support.
|
||||
*
|
||||
* @description:
|
||||
* This section contains a function used to query the level of TrueType
|
||||
* bytecode support compiled in this version of the library.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @enum:
|
||||
* FT_TrueTypeEngineType
|
||||
*
|
||||
* @description:
|
||||
* A list of values describing which kind of TrueType bytecode engine is
|
||||
* implemented in a given FT_Library instance. It is used by the
|
||||
* @FT_Get_TrueType_Engine_Type function.
|
||||
*
|
||||
* @values:
|
||||
* FT_TRUETYPE_ENGINE_TYPE_NONE ::
|
||||
* The library doesn't implement any kind of bytecode interpreter.
|
||||
*
|
||||
* FT_TRUETYPE_ENGINE_TYPE_UNPATENTED ::
|
||||
* Deprecated and removed.
|
||||
*
|
||||
* FT_TRUETYPE_ENGINE_TYPE_PATENTED ::
|
||||
* The library implements a bytecode interpreter that covers the full
|
||||
* instruction set of the TrueType virtual machine (this was governed
|
||||
* by patents until May 2010, hence the name).
|
||||
*
|
||||
* @since:
|
||||
* 2.2
|
||||
*
|
||||
*/
|
||||
typedef enum FT_TrueTypeEngineType_
|
||||
{
|
||||
FT_TRUETYPE_ENGINE_TYPE_NONE = 0,
|
||||
FT_TRUETYPE_ENGINE_TYPE_UNPATENTED,
|
||||
FT_TRUETYPE_ENGINE_TYPE_PATENTED
|
||||
|
||||
} FT_TrueTypeEngineType;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Get_TrueType_Engine_Type
|
||||
*
|
||||
* @description:
|
||||
* Return an @FT_TrueTypeEngineType value to indicate which level of the
|
||||
* TrueType virtual machine a given library instance supports.
|
||||
*
|
||||
* @input:
|
||||
* library ::
|
||||
* A library instance.
|
||||
*
|
||||
* @return:
|
||||
* A value indicating which level is supported.
|
||||
*
|
||||
* @since:
|
||||
* 2.2
|
||||
*
|
||||
*/
|
||||
FT_EXPORT( FT_TrueTypeEngineType )
|
||||
FT_Get_TrueType_Engine_Type( FT_Library library );
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* FTMODAPI_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
204
vendor/freetype/include/freetype/ftmoderr.h
vendored
Normal file
204
vendor/freetype/include/freetype/ftmoderr.h
vendored
Normal file
@@ -0,0 +1,204 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftmoderr.h
|
||||
*
|
||||
* FreeType module error offsets (specification).
|
||||
*
|
||||
* Copyright (C) 2001-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* This file is used to define the FreeType module error codes.
|
||||
*
|
||||
* If the macro `FT_CONFIG_OPTION_USE_MODULE_ERRORS` in `ftoption.h` is
|
||||
* set, the lower byte of an error value identifies the error code as
|
||||
* usual. In addition, the higher byte identifies the module. For
|
||||
* example, the error `FT_Err_Invalid_File_Format` has value 0x0003, the
|
||||
* error `TT_Err_Invalid_File_Format` has value 0x1303, the error
|
||||
* `T1_Err_Invalid_File_Format` has value 0x1403, etc.
|
||||
*
|
||||
* Note that `FT_Err_Ok`, `TT_Err_Ok`, etc. are always equal to zero,
|
||||
* including the high byte.
|
||||
*
|
||||
* If `FT_CONFIG_OPTION_USE_MODULE_ERRORS` isn't set, the higher byte of an
|
||||
* error value is set to zero.
|
||||
*
|
||||
* To hide the various `XXX_Err_` prefixes in the source code, FreeType
|
||||
* provides some macros in `fttypes.h`.
|
||||
*
|
||||
* FT_ERR( err )
|
||||
*
|
||||
* Add current error module prefix (as defined with the `FT_ERR_PREFIX`
|
||||
* macro) to `err`. For example, in the BDF module the line
|
||||
*
|
||||
* ```
|
||||
* error = FT_ERR( Invalid_Outline );
|
||||
* ```
|
||||
*
|
||||
* expands to
|
||||
*
|
||||
* ```
|
||||
* error = BDF_Err_Invalid_Outline;
|
||||
* ```
|
||||
*
|
||||
* For simplicity, you can always use `FT_Err_Ok` directly instead of
|
||||
* `FT_ERR( Ok )`.
|
||||
*
|
||||
* FT_ERR_EQ( errcode, err )
|
||||
* FT_ERR_NEQ( errcode, err )
|
||||
*
|
||||
* Compare error code `errcode` with the error `err` for equality and
|
||||
* inequality, respectively. Example:
|
||||
*
|
||||
* ```
|
||||
* if ( FT_ERR_EQ( error, Invalid_Outline ) )
|
||||
* ...
|
||||
* ```
|
||||
*
|
||||
* Using this macro you don't have to think about error prefixes. Of
|
||||
* course, if module errors are not active, the above example is the
|
||||
* same as
|
||||
*
|
||||
* ```
|
||||
* if ( error == FT_Err_Invalid_Outline )
|
||||
* ...
|
||||
* ```
|
||||
*
|
||||
* FT_ERROR_BASE( errcode )
|
||||
* FT_ERROR_MODULE( errcode )
|
||||
*
|
||||
* Get base error and module error code, respectively.
|
||||
*
|
||||
* It can also be used to create a module error message table easily with
|
||||
* something like
|
||||
*
|
||||
* ```
|
||||
* #undef FTMODERR_H_
|
||||
* #define FT_MODERRDEF( e, v, s ) { FT_Mod_Err_ ## e, s },
|
||||
* #define FT_MODERR_START_LIST {
|
||||
* #define FT_MODERR_END_LIST { 0, 0 } };
|
||||
*
|
||||
* const struct
|
||||
* {
|
||||
* int mod_err_offset;
|
||||
* const char* mod_err_msg
|
||||
* } ft_mod_errors[] =
|
||||
*
|
||||
* #include <freetype/ftmoderr.h>
|
||||
* ```
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FTMODERR_H_
|
||||
#define FTMODERR_H_
|
||||
|
||||
|
||||
/*******************************************************************/
|
||||
/*******************************************************************/
|
||||
/***** *****/
|
||||
/***** SETUP MACROS *****/
|
||||
/***** *****/
|
||||
/*******************************************************************/
|
||||
/*******************************************************************/
|
||||
|
||||
|
||||
#undef FT_NEED_EXTERN_C
|
||||
|
||||
#ifndef FT_MODERRDEF
|
||||
|
||||
#ifdef FT_CONFIG_OPTION_USE_MODULE_ERRORS
|
||||
#define FT_MODERRDEF( e, v, s ) FT_Mod_Err_ ## e = v,
|
||||
#else
|
||||
#define FT_MODERRDEF( e, v, s ) FT_Mod_Err_ ## e = 0,
|
||||
#endif
|
||||
|
||||
#define FT_MODERR_START_LIST enum {
|
||||
#define FT_MODERR_END_LIST FT_Mod_Err_Max };
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define FT_NEED_EXTERN_C
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#endif /* !FT_MODERRDEF */
|
||||
|
||||
|
||||
/*******************************************************************/
|
||||
/*******************************************************************/
|
||||
/***** *****/
|
||||
/***** LIST MODULE ERROR BASES *****/
|
||||
/***** *****/
|
||||
/*******************************************************************/
|
||||
/*******************************************************************/
|
||||
|
||||
|
||||
#ifdef FT_MODERR_START_LIST
|
||||
FT_MODERR_START_LIST
|
||||
#endif
|
||||
|
||||
|
||||
FT_MODERRDEF( Base, 0x000, "base module" )
|
||||
FT_MODERRDEF( Autofit, 0x100, "autofitter module" )
|
||||
FT_MODERRDEF( BDF, 0x200, "BDF module" )
|
||||
FT_MODERRDEF( Bzip2, 0x300, "Bzip2 module" )
|
||||
FT_MODERRDEF( Cache, 0x400, "cache module" )
|
||||
FT_MODERRDEF( CFF, 0x500, "CFF module" )
|
||||
FT_MODERRDEF( CID, 0x600, "CID module" )
|
||||
FT_MODERRDEF( Gzip, 0x700, "Gzip module" )
|
||||
FT_MODERRDEF( LZW, 0x800, "LZW module" )
|
||||
FT_MODERRDEF( OTvalid, 0x900, "OpenType validation module" )
|
||||
FT_MODERRDEF( PCF, 0xA00, "PCF module" )
|
||||
FT_MODERRDEF( PFR, 0xB00, "PFR module" )
|
||||
FT_MODERRDEF( PSaux, 0xC00, "PS auxiliary module" )
|
||||
FT_MODERRDEF( PShinter, 0xD00, "PS hinter module" )
|
||||
FT_MODERRDEF( PSnames, 0xE00, "PS names module" )
|
||||
FT_MODERRDEF( Raster, 0xF00, "raster module" )
|
||||
FT_MODERRDEF( SFNT, 0x1000, "SFNT module" )
|
||||
FT_MODERRDEF( Smooth, 0x1100, "smooth raster module" )
|
||||
FT_MODERRDEF( TrueType, 0x1200, "TrueType module" )
|
||||
FT_MODERRDEF( Type1, 0x1300, "Type 1 module" )
|
||||
FT_MODERRDEF( Type42, 0x1400, "Type 42 module" )
|
||||
FT_MODERRDEF( Winfonts, 0x1500, "Windows FON/FNT module" )
|
||||
FT_MODERRDEF( GXvalid, 0x1600, "GX validation module" )
|
||||
FT_MODERRDEF( Sdf, 0x1700, "Signed distance field raster module" )
|
||||
|
||||
|
||||
#ifdef FT_MODERR_END_LIST
|
||||
FT_MODERR_END_LIST
|
||||
#endif
|
||||
|
||||
|
||||
/*******************************************************************/
|
||||
/*******************************************************************/
|
||||
/***** *****/
|
||||
/***** CLEANUP *****/
|
||||
/***** *****/
|
||||
/*******************************************************************/
|
||||
/*******************************************************************/
|
||||
|
||||
|
||||
#ifdef FT_NEED_EXTERN_C
|
||||
}
|
||||
#endif
|
||||
|
||||
#undef FT_MODERR_START_LIST
|
||||
#undef FT_MODERR_END_LIST
|
||||
#undef FT_MODERRDEF
|
||||
#undef FT_NEED_EXTERN_C
|
||||
|
||||
|
||||
#endif /* FTMODERR_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
206
vendor/freetype/include/freetype/ftotval.h
vendored
Normal file
206
vendor/freetype/include/freetype/ftotval.h
vendored
Normal file
@@ -0,0 +1,206 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftotval.h
|
||||
*
|
||||
* FreeType API for validating OpenType tables (specification).
|
||||
*
|
||||
* Copyright (C) 2004-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
*
|
||||
* Warning: This module might be moved to a different library in the
|
||||
* future to avoid a tight dependency between FreeType and the
|
||||
* OpenType specification.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FTOTVAL_H_
|
||||
#define FTOTVAL_H_
|
||||
|
||||
#include <freetype/freetype.h>
|
||||
|
||||
#ifdef FREETYPE_H
|
||||
#error "freetype.h of FreeType 1 has been loaded!"
|
||||
#error "Please fix the directory search order for header files"
|
||||
#error "so that freetype.h of FreeType 2 is found first."
|
||||
#endif
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* ot_validation
|
||||
*
|
||||
* @title:
|
||||
* OpenType Validation
|
||||
*
|
||||
* @abstract:
|
||||
* An API to validate OpenType tables.
|
||||
*
|
||||
* @description:
|
||||
* This section contains the declaration of functions to validate some
|
||||
* OpenType tables (BASE, GDEF, GPOS, GSUB, JSTF, MATH).
|
||||
*
|
||||
* @order:
|
||||
* FT_OpenType_Validate
|
||||
* FT_OpenType_Free
|
||||
*
|
||||
* FT_VALIDATE_OTXXX
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @enum:
|
||||
* FT_VALIDATE_OTXXX
|
||||
*
|
||||
* @description:
|
||||
* A list of bit-field constants used with @FT_OpenType_Validate to
|
||||
* indicate which OpenType tables should be validated.
|
||||
*
|
||||
* @values:
|
||||
* FT_VALIDATE_BASE ::
|
||||
* Validate BASE table.
|
||||
*
|
||||
* FT_VALIDATE_GDEF ::
|
||||
* Validate GDEF table.
|
||||
*
|
||||
* FT_VALIDATE_GPOS ::
|
||||
* Validate GPOS table.
|
||||
*
|
||||
* FT_VALIDATE_GSUB ::
|
||||
* Validate GSUB table.
|
||||
*
|
||||
* FT_VALIDATE_JSTF ::
|
||||
* Validate JSTF table.
|
||||
*
|
||||
* FT_VALIDATE_MATH ::
|
||||
* Validate MATH table.
|
||||
*
|
||||
* FT_VALIDATE_OT ::
|
||||
* Validate all OpenType tables (BASE, GDEF, GPOS, GSUB, JSTF, MATH).
|
||||
*
|
||||
*/
|
||||
#define FT_VALIDATE_BASE 0x0100
|
||||
#define FT_VALIDATE_GDEF 0x0200
|
||||
#define FT_VALIDATE_GPOS 0x0400
|
||||
#define FT_VALIDATE_GSUB 0x0800
|
||||
#define FT_VALIDATE_JSTF 0x1000
|
||||
#define FT_VALIDATE_MATH 0x2000
|
||||
|
||||
#define FT_VALIDATE_OT ( FT_VALIDATE_BASE | \
|
||||
FT_VALIDATE_GDEF | \
|
||||
FT_VALIDATE_GPOS | \
|
||||
FT_VALIDATE_GSUB | \
|
||||
FT_VALIDATE_JSTF | \
|
||||
FT_VALIDATE_MATH )
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_OpenType_Validate
|
||||
*
|
||||
* @description:
|
||||
* Validate various OpenType tables to assure that all offsets and
|
||||
* indices are valid. The idea is that a higher-level library that
|
||||
* actually does the text layout can access those tables without error
|
||||
* checking (which can be quite time consuming).
|
||||
*
|
||||
* @input:
|
||||
* face ::
|
||||
* A handle to the input face.
|
||||
*
|
||||
* validation_flags ::
|
||||
* A bit field that specifies the tables to be validated. See
|
||||
* @FT_VALIDATE_OTXXX for possible values.
|
||||
*
|
||||
* @output:
|
||||
* BASE_table ::
|
||||
* A pointer to the BASE table.
|
||||
*
|
||||
* GDEF_table ::
|
||||
* A pointer to the GDEF table.
|
||||
*
|
||||
* GPOS_table ::
|
||||
* A pointer to the GPOS table.
|
||||
*
|
||||
* GSUB_table ::
|
||||
* A pointer to the GSUB table.
|
||||
*
|
||||
* JSTF_table ::
|
||||
* A pointer to the JSTF table.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* This function only works with OpenType fonts, returning an error
|
||||
* otherwise.
|
||||
*
|
||||
* After use, the application should deallocate the five tables with
|
||||
* @FT_OpenType_Free. A `NULL` value indicates that the table either
|
||||
* doesn't exist in the font, or the application hasn't asked for
|
||||
* validation.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_OpenType_Validate( FT_Face face,
|
||||
FT_UInt validation_flags,
|
||||
FT_Bytes *BASE_table,
|
||||
FT_Bytes *GDEF_table,
|
||||
FT_Bytes *GPOS_table,
|
||||
FT_Bytes *GSUB_table,
|
||||
FT_Bytes *JSTF_table );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_OpenType_Free
|
||||
*
|
||||
* @description:
|
||||
* Free the buffer allocated by OpenType validator.
|
||||
*
|
||||
* @input:
|
||||
* face ::
|
||||
* A handle to the input face.
|
||||
*
|
||||
* table ::
|
||||
* The pointer to the buffer that is allocated by
|
||||
* @FT_OpenType_Validate.
|
||||
*
|
||||
* @note:
|
||||
* This function must be used to free the buffer allocated by
|
||||
* @FT_OpenType_Validate only.
|
||||
*/
|
||||
FT_EXPORT( void )
|
||||
FT_OpenType_Free( FT_Face face,
|
||||
FT_Bytes table );
|
||||
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* FTOTVAL_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
588
vendor/freetype/include/freetype/ftoutln.h
vendored
Normal file
588
vendor/freetype/include/freetype/ftoutln.h
vendored
Normal file
@@ -0,0 +1,588 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftoutln.h
|
||||
*
|
||||
* Support for the FT_Outline type used to store glyph shapes of
|
||||
* most scalable font formats (specification).
|
||||
*
|
||||
* Copyright (C) 1996-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FTOUTLN_H_
|
||||
#define FTOUTLN_H_
|
||||
|
||||
|
||||
#include <freetype/freetype.h>
|
||||
|
||||
#ifdef FREETYPE_H
|
||||
#error "freetype.h of FreeType 1 has been loaded!"
|
||||
#error "Please fix the directory search order for header files"
|
||||
#error "so that freetype.h of FreeType 2 is found first."
|
||||
#endif
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* outline_processing
|
||||
*
|
||||
* @title:
|
||||
* Outline Processing
|
||||
*
|
||||
* @abstract:
|
||||
* Functions to create, transform, and render vectorial glyph images.
|
||||
*
|
||||
* @description:
|
||||
* This section contains routines used to create and destroy scalable
|
||||
* glyph images known as 'outlines'. These can also be measured,
|
||||
* transformed, and converted into bitmaps and pixmaps.
|
||||
*
|
||||
* @order:
|
||||
* FT_Outline
|
||||
* FT_Outline_New
|
||||
* FT_Outline_Done
|
||||
* FT_Outline_Copy
|
||||
* FT_Outline_Translate
|
||||
* FT_Outline_Transform
|
||||
* FT_Outline_Embolden
|
||||
* FT_Outline_EmboldenXY
|
||||
* FT_Outline_Reverse
|
||||
* FT_Outline_Check
|
||||
*
|
||||
* FT_Outline_Get_CBox
|
||||
* FT_Outline_Get_BBox
|
||||
*
|
||||
* FT_Outline_Get_Bitmap
|
||||
* FT_Outline_Render
|
||||
* FT_Outline_Decompose
|
||||
* FT_Outline_Funcs
|
||||
* FT_Outline_MoveToFunc
|
||||
* FT_Outline_LineToFunc
|
||||
* FT_Outline_ConicToFunc
|
||||
* FT_Outline_CubicToFunc
|
||||
*
|
||||
* FT_Orientation
|
||||
* FT_Outline_Get_Orientation
|
||||
*
|
||||
* FT_OUTLINE_XXX
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Outline_Decompose
|
||||
*
|
||||
* @description:
|
||||
* Walk over an outline's structure to decompose it into individual
|
||||
* segments and Bezier arcs. This function also emits 'move to'
|
||||
* operations to indicate the start of new contours in the outline.
|
||||
*
|
||||
* @input:
|
||||
* outline ::
|
||||
* A pointer to the source target.
|
||||
*
|
||||
* func_interface ::
|
||||
* A table of 'emitters', i.e., function pointers called during
|
||||
* decomposition to indicate path operations.
|
||||
*
|
||||
* @inout:
|
||||
* user ::
|
||||
* A typeless pointer that is passed to each emitter during the
|
||||
* decomposition. It can be used to store the state during the
|
||||
* decomposition.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* Degenerate contours, segments, and Bezier arcs may be reported. In
|
||||
* most cases, it is best to filter these out before using the outline
|
||||
* for stroking or other path modification purposes (which may cause
|
||||
* degenerate segments to become non-degenerate and visible, like when
|
||||
* stroke caps are used or the path is otherwise outset). Some glyph
|
||||
* outlines may contain deliberate degenerate single points for mark
|
||||
* attachement.
|
||||
*
|
||||
* Similarly, the function returns success for an empty outline also
|
||||
* (doing nothing, that is, not calling any emitter); if necessary, you
|
||||
* should filter this out, too.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Outline_Decompose( FT_Outline* outline,
|
||||
const FT_Outline_Funcs* func_interface,
|
||||
void* user );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Outline_New
|
||||
*
|
||||
* @description:
|
||||
* Create a new outline of a given size.
|
||||
*
|
||||
* @input:
|
||||
* library ::
|
||||
* A handle to the library object from where the outline is allocated.
|
||||
* Note however that the new outline will **not** necessarily be
|
||||
* **freed**, when destroying the library, by @FT_Done_FreeType.
|
||||
*
|
||||
* numPoints ::
|
||||
* The maximum number of points within the outline. Must be smaller
|
||||
* than or equal to 0xFFFF (65535).
|
||||
*
|
||||
* numContours ::
|
||||
* The maximum number of contours within the outline. This value must
|
||||
* be in the range 0 to `numPoints`.
|
||||
*
|
||||
* @output:
|
||||
* anoutline ::
|
||||
* A handle to the new outline.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* The reason why this function takes a `library` parameter is simply to
|
||||
* use the library's memory allocator.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Outline_New( FT_Library library,
|
||||
FT_UInt numPoints,
|
||||
FT_Int numContours,
|
||||
FT_Outline *anoutline );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Outline_Done
|
||||
*
|
||||
* @description:
|
||||
* Destroy an outline created with @FT_Outline_New.
|
||||
*
|
||||
* @input:
|
||||
* library ::
|
||||
* A handle of the library object used to allocate the outline.
|
||||
*
|
||||
* outline ::
|
||||
* A pointer to the outline object to be discarded.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* If the outline's 'owner' field is not set, only the outline descriptor
|
||||
* will be released.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Outline_Done( FT_Library library,
|
||||
FT_Outline* outline );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Outline_Check
|
||||
*
|
||||
* @description:
|
||||
* Check the contents of an outline descriptor.
|
||||
*
|
||||
* @input:
|
||||
* outline ::
|
||||
* A handle to a source outline.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* An empty outline, or an outline with a single point only is also
|
||||
* valid.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Outline_Check( FT_Outline* outline );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Outline_Get_CBox
|
||||
*
|
||||
* @description:
|
||||
* Return an outline's 'control box'. The control box encloses all the
|
||||
* outline's points, including Bezier control points. Though it
|
||||
* coincides with the exact bounding box for most glyphs, it can be
|
||||
* slightly larger in some situations (like when rotating an outline that
|
||||
* contains Bezier outside arcs).
|
||||
*
|
||||
* Computing the control box is very fast, while getting the bounding box
|
||||
* can take much more time as it needs to walk over all segments and arcs
|
||||
* in the outline. To get the latter, you can use the 'ftbbox'
|
||||
* component, which is dedicated to this single task.
|
||||
*
|
||||
* @input:
|
||||
* outline ::
|
||||
* A pointer to the source outline descriptor.
|
||||
*
|
||||
* @output:
|
||||
* acbox ::
|
||||
* The outline's control box.
|
||||
*
|
||||
* @note:
|
||||
* See @FT_Glyph_Get_CBox for a discussion of tricky fonts.
|
||||
*/
|
||||
FT_EXPORT( void )
|
||||
FT_Outline_Get_CBox( const FT_Outline* outline,
|
||||
FT_BBox *acbox );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Outline_Translate
|
||||
*
|
||||
* @description:
|
||||
* Apply a simple translation to the points of an outline.
|
||||
*
|
||||
* @inout:
|
||||
* outline ::
|
||||
* A pointer to the target outline descriptor.
|
||||
*
|
||||
* @input:
|
||||
* xOffset ::
|
||||
* The horizontal offset.
|
||||
*
|
||||
* yOffset ::
|
||||
* The vertical offset.
|
||||
*/
|
||||
FT_EXPORT( void )
|
||||
FT_Outline_Translate( const FT_Outline* outline,
|
||||
FT_Pos xOffset,
|
||||
FT_Pos yOffset );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Outline_Copy
|
||||
*
|
||||
* @description:
|
||||
* Copy an outline into another one. Both objects must have the same
|
||||
* sizes (number of points & number of contours) when this function is
|
||||
* called.
|
||||
*
|
||||
* @input:
|
||||
* source ::
|
||||
* A handle to the source outline.
|
||||
*
|
||||
* @output:
|
||||
* target ::
|
||||
* A handle to the target outline.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Outline_Copy( const FT_Outline* source,
|
||||
FT_Outline *target );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Outline_Transform
|
||||
*
|
||||
* @description:
|
||||
* Apply a simple 2x2 matrix to all of an outline's points. Useful for
|
||||
* applying rotations, slanting, flipping, etc.
|
||||
*
|
||||
* @inout:
|
||||
* outline ::
|
||||
* A pointer to the target outline descriptor.
|
||||
*
|
||||
* @input:
|
||||
* matrix ::
|
||||
* A pointer to the transformation matrix.
|
||||
*
|
||||
* @note:
|
||||
* You can use @FT_Outline_Translate if you need to translate the
|
||||
* outline's points.
|
||||
*/
|
||||
FT_EXPORT( void )
|
||||
FT_Outline_Transform( const FT_Outline* outline,
|
||||
const FT_Matrix* matrix );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Outline_Embolden
|
||||
*
|
||||
* @description:
|
||||
* Embolden an outline. The new outline will be at most 4~times
|
||||
* `strength` pixels wider and higher. You may think of the left and
|
||||
* bottom borders as unchanged.
|
||||
*
|
||||
* Negative `strength` values to reduce the outline thickness are
|
||||
* possible also.
|
||||
*
|
||||
* @inout:
|
||||
* outline ::
|
||||
* A handle to the target outline.
|
||||
*
|
||||
* @input:
|
||||
* strength ::
|
||||
* How strong the glyph is emboldened. Expressed in 26.6 pixel format.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* The used algorithm to increase or decrease the thickness of the glyph
|
||||
* doesn't change the number of points; this means that certain
|
||||
* situations like acute angles or intersections are sometimes handled
|
||||
* incorrectly.
|
||||
*
|
||||
* If you need 'better' metrics values you should call
|
||||
* @FT_Outline_Get_CBox or @FT_Outline_Get_BBox.
|
||||
*
|
||||
* To get meaningful results, font scaling values must be set with
|
||||
* functions like @FT_Set_Char_Size before calling FT_Render_Glyph.
|
||||
*
|
||||
* @example:
|
||||
* ```
|
||||
* FT_Load_Glyph( face, index, FT_LOAD_DEFAULT );
|
||||
*
|
||||
* if ( face->glyph->format == FT_GLYPH_FORMAT_OUTLINE )
|
||||
* FT_Outline_Embolden( &face->glyph->outline, strength );
|
||||
* ```
|
||||
*
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Outline_Embolden( FT_Outline* outline,
|
||||
FT_Pos strength );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Outline_EmboldenXY
|
||||
*
|
||||
* @description:
|
||||
* Embolden an outline. The new outline will be `xstrength` pixels wider
|
||||
* and `ystrength` pixels higher. Otherwise, it is similar to
|
||||
* @FT_Outline_Embolden, which uses the same strength in both directions.
|
||||
*
|
||||
* @since:
|
||||
* 2.4.10
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Outline_EmboldenXY( FT_Outline* outline,
|
||||
FT_Pos xstrength,
|
||||
FT_Pos ystrength );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Outline_Reverse
|
||||
*
|
||||
* @description:
|
||||
* Reverse the drawing direction of an outline. This is used to ensure
|
||||
* consistent fill conventions for mirrored glyphs.
|
||||
*
|
||||
* @inout:
|
||||
* outline ::
|
||||
* A pointer to the target outline descriptor.
|
||||
*
|
||||
* @note:
|
||||
* This function toggles the bit flag @FT_OUTLINE_REVERSE_FILL in the
|
||||
* outline's `flags` field.
|
||||
*
|
||||
* It shouldn't be used by a normal client application, unless it knows
|
||||
* what it is doing.
|
||||
*/
|
||||
FT_EXPORT( void )
|
||||
FT_Outline_Reverse( FT_Outline* outline );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Outline_Get_Bitmap
|
||||
*
|
||||
* @description:
|
||||
* Render an outline within a bitmap. The outline's image is simply
|
||||
* OR-ed to the target bitmap.
|
||||
*
|
||||
* @input:
|
||||
* library ::
|
||||
* A handle to a FreeType library object.
|
||||
*
|
||||
* outline ::
|
||||
* A pointer to the source outline descriptor.
|
||||
*
|
||||
* @inout:
|
||||
* abitmap ::
|
||||
* A pointer to the target bitmap descriptor.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* This function does **not create** the bitmap, it only renders an
|
||||
* outline image within the one you pass to it! Consequently, the
|
||||
* various fields in `abitmap` should be set accordingly.
|
||||
*
|
||||
* It will use the raster corresponding to the default glyph format.
|
||||
*
|
||||
* The value of the `num_grays` field in `abitmap` is ignored. If you
|
||||
* select the gray-level rasterizer, and you want less than 256 gray
|
||||
* levels, you have to use @FT_Outline_Render directly.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Outline_Get_Bitmap( FT_Library library,
|
||||
FT_Outline* outline,
|
||||
const FT_Bitmap *abitmap );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Outline_Render
|
||||
*
|
||||
* @description:
|
||||
* Render an outline within a bitmap using the current scan-convert.
|
||||
*
|
||||
* @input:
|
||||
* library ::
|
||||
* A handle to a FreeType library object.
|
||||
*
|
||||
* outline ::
|
||||
* A pointer to the source outline descriptor.
|
||||
*
|
||||
* @inout:
|
||||
* params ::
|
||||
* A pointer to an @FT_Raster_Params structure used to describe the
|
||||
* rendering operation.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0~means success.
|
||||
*
|
||||
* @note:
|
||||
* This advanced function uses @FT_Raster_Params as an argument.
|
||||
* The field `params.source` will be set to `outline` before the scan
|
||||
* converter is called, which means that the value you give to it is
|
||||
* actually ignored. Either `params.target` must point to preallocated
|
||||
* bitmap, or @FT_RASTER_FLAG_DIRECT must be set in `params.flags`
|
||||
* allowing FreeType rasterizer to be used for direct composition,
|
||||
* translucency, etc. See @FT_Raster_Params for more details.
|
||||
*/
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_Outline_Render( FT_Library library,
|
||||
FT_Outline* outline,
|
||||
FT_Raster_Params* params );
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @enum:
|
||||
* FT_Orientation
|
||||
*
|
||||
* @description:
|
||||
* A list of values used to describe an outline's contour orientation.
|
||||
*
|
||||
* The TrueType and PostScript specifications use different conventions
|
||||
* to determine whether outline contours should be filled or unfilled.
|
||||
*
|
||||
* @values:
|
||||
* FT_ORIENTATION_TRUETYPE ::
|
||||
* According to the TrueType specification, clockwise contours must be
|
||||
* filled, and counter-clockwise ones must be unfilled.
|
||||
*
|
||||
* FT_ORIENTATION_POSTSCRIPT ::
|
||||
* According to the PostScript specification, counter-clockwise
|
||||
* contours must be filled, and clockwise ones must be unfilled.
|
||||
*
|
||||
* FT_ORIENTATION_FILL_RIGHT ::
|
||||
* This is identical to @FT_ORIENTATION_TRUETYPE, but is used to
|
||||
* remember that in TrueType, everything that is to the right of the
|
||||
* drawing direction of a contour must be filled.
|
||||
*
|
||||
* FT_ORIENTATION_FILL_LEFT ::
|
||||
* This is identical to @FT_ORIENTATION_POSTSCRIPT, but is used to
|
||||
* remember that in PostScript, everything that is to the left of the
|
||||
* drawing direction of a contour must be filled.
|
||||
*
|
||||
* FT_ORIENTATION_NONE ::
|
||||
* The orientation cannot be determined. That is, different parts of
|
||||
* the glyph have different orientation.
|
||||
*
|
||||
*/
|
||||
typedef enum FT_Orientation_
|
||||
{
|
||||
FT_ORIENTATION_TRUETYPE = 0,
|
||||
FT_ORIENTATION_POSTSCRIPT = 1,
|
||||
FT_ORIENTATION_FILL_RIGHT = FT_ORIENTATION_TRUETYPE,
|
||||
FT_ORIENTATION_FILL_LEFT = FT_ORIENTATION_POSTSCRIPT,
|
||||
FT_ORIENTATION_NONE
|
||||
|
||||
} FT_Orientation;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @function:
|
||||
* FT_Outline_Get_Orientation
|
||||
*
|
||||
* @description:
|
||||
* This function analyzes a glyph outline and tries to compute its fill
|
||||
* orientation (see @FT_Orientation). This is done by integrating the
|
||||
* total area covered by the outline. The positive integral corresponds
|
||||
* to the clockwise orientation and @FT_ORIENTATION_POSTSCRIPT is
|
||||
* returned. The negative integral corresponds to the counter-clockwise
|
||||
* orientation and @FT_ORIENTATION_TRUETYPE is returned.
|
||||
*
|
||||
* Note that this will return @FT_ORIENTATION_TRUETYPE for empty
|
||||
* outlines.
|
||||
*
|
||||
* @input:
|
||||
* outline ::
|
||||
* A handle to the source outline.
|
||||
*
|
||||
* @return:
|
||||
* The orientation.
|
||||
*
|
||||
*/
|
||||
FT_EXPORT( FT_Orientation )
|
||||
FT_Outline_Get_Orientation( FT_Outline* outline );
|
||||
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* FTOUTLN_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
|
||||
|
||||
/* Local Variables: */
|
||||
/* coding: utf-8 */
|
||||
/* End: */
|
||||
218
vendor/freetype/include/freetype/ftparams.h
vendored
Normal file
218
vendor/freetype/include/freetype/ftparams.h
vendored
Normal file
@@ -0,0 +1,218 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* ftparams.h
|
||||
*
|
||||
* FreeType API for possible FT_Parameter tags (specification only).
|
||||
*
|
||||
* Copyright (C) 2017-2024 by
|
||||
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FTPARAMS_H_
|
||||
#define FTPARAMS_H_
|
||||
|
||||
#include <freetype/freetype.h>
|
||||
|
||||
#ifdef FREETYPE_H
|
||||
#error "freetype.h of FreeType 1 has been loaded!"
|
||||
#error "Please fix the directory search order for header files"
|
||||
#error "so that freetype.h of FreeType 2 is found first."
|
||||
#endif
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @section:
|
||||
* parameter_tags
|
||||
*
|
||||
* @title:
|
||||
* Parameter Tags
|
||||
*
|
||||
* @abstract:
|
||||
* Macros for driver property and font loading parameter tags.
|
||||
*
|
||||
* @description:
|
||||
* This section contains macros for the @FT_Parameter structure that are
|
||||
* used with various functions to activate some special functionality or
|
||||
* different behaviour of various components of FreeType.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @enum:
|
||||
* FT_PARAM_TAG_IGNORE_TYPOGRAPHIC_FAMILY
|
||||
*
|
||||
* @description:
|
||||
* A tag for @FT_Parameter to make @FT_Open_Face ignore typographic
|
||||
* family names in the 'name' table (introduced in OpenType version 1.4).
|
||||
* Use this for backward compatibility with legacy systems that have a
|
||||
* four-faces-per-family restriction.
|
||||
*
|
||||
* @since:
|
||||
* 2.8
|
||||
*
|
||||
*/
|
||||
#define FT_PARAM_TAG_IGNORE_TYPOGRAPHIC_FAMILY \
|
||||
FT_MAKE_TAG( 'i', 'g', 'p', 'f' )
|
||||
|
||||
|
||||
/* this constant is deprecated */
|
||||
#define FT_PARAM_TAG_IGNORE_PREFERRED_FAMILY \
|
||||
FT_PARAM_TAG_IGNORE_TYPOGRAPHIC_FAMILY
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @enum:
|
||||
* FT_PARAM_TAG_IGNORE_TYPOGRAPHIC_SUBFAMILY
|
||||
*
|
||||
* @description:
|
||||
* A tag for @FT_Parameter to make @FT_Open_Face ignore typographic
|
||||
* subfamily names in the 'name' table (introduced in OpenType version
|
||||
* 1.4). Use this for backward compatibility with legacy systems that
|
||||
* have a four-faces-per-family restriction.
|
||||
*
|
||||
* @since:
|
||||
* 2.8
|
||||
*
|
||||
*/
|
||||
#define FT_PARAM_TAG_IGNORE_TYPOGRAPHIC_SUBFAMILY \
|
||||
FT_MAKE_TAG( 'i', 'g', 'p', 's' )
|
||||
|
||||
|
||||
/* this constant is deprecated */
|
||||
#define FT_PARAM_TAG_IGNORE_PREFERRED_SUBFAMILY \
|
||||
FT_PARAM_TAG_IGNORE_TYPOGRAPHIC_SUBFAMILY
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @enum:
|
||||
* FT_PARAM_TAG_INCREMENTAL
|
||||
*
|
||||
* @description:
|
||||
* An @FT_Parameter tag to be used with @FT_Open_Face to indicate
|
||||
* incremental glyph loading.
|
||||
*
|
||||
*/
|
||||
#define FT_PARAM_TAG_INCREMENTAL \
|
||||
FT_MAKE_TAG( 'i', 'n', 'c', 'r' )
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @enum:
|
||||
* FT_PARAM_TAG_IGNORE_SBIX
|
||||
*
|
||||
* @description:
|
||||
* A tag for @FT_Parameter to make @FT_Open_Face ignore an 'sbix' table
|
||||
* while loading a font. Use this if @FT_FACE_FLAG_SBIX is set and you
|
||||
* want to access the outline glyphs in the font.
|
||||
*
|
||||
*/
|
||||
#define FT_PARAM_TAG_IGNORE_SBIX \
|
||||
FT_MAKE_TAG( 'i', 's', 'b', 'x' )
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @enum:
|
||||
* FT_PARAM_TAG_LCD_FILTER_WEIGHTS
|
||||
*
|
||||
* @description:
|
||||
* An @FT_Parameter tag to be used with @FT_Face_Properties. The
|
||||
* corresponding argument specifies the five LCD filter weights for a
|
||||
* given face (if using @FT_LOAD_TARGET_LCD, for example), overriding the
|
||||
* global default values or the values set up with
|
||||
* @FT_Library_SetLcdFilterWeights.
|
||||
*
|
||||
* @since:
|
||||
* 2.8
|
||||
*
|
||||
*/
|
||||
#define FT_PARAM_TAG_LCD_FILTER_WEIGHTS \
|
||||
FT_MAKE_TAG( 'l', 'c', 'd', 'f' )
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @enum:
|
||||
* FT_PARAM_TAG_RANDOM_SEED
|
||||
*
|
||||
* @description:
|
||||
* An @FT_Parameter tag to be used with @FT_Face_Properties. The
|
||||
* corresponding 32bit signed integer argument overrides the font
|
||||
* driver's random seed value with a face-specific one; see @random-seed.
|
||||
*
|
||||
* @since:
|
||||
* 2.8
|
||||
*
|
||||
*/
|
||||
#define FT_PARAM_TAG_RANDOM_SEED \
|
||||
FT_MAKE_TAG( 's', 'e', 'e', 'd' )
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @enum:
|
||||
* FT_PARAM_TAG_STEM_DARKENING
|
||||
*
|
||||
* @description:
|
||||
* An @FT_Parameter tag to be used with @FT_Face_Properties. The
|
||||
* corresponding Boolean argument specifies whether to apply stem
|
||||
* darkening, overriding the global default values or the values set up
|
||||
* with @FT_Property_Set (see @no-stem-darkening).
|
||||
*
|
||||
* This is a passive setting that only takes effect if the font driver or
|
||||
* autohinter honors it, which the CFF, Type~1, and CID drivers always
|
||||
* do, but the autohinter only in 'light' hinting mode (as of version
|
||||
* 2.9).
|
||||
*
|
||||
* @since:
|
||||
* 2.8
|
||||
*
|
||||
*/
|
||||
#define FT_PARAM_TAG_STEM_DARKENING \
|
||||
FT_MAKE_TAG( 'd', 'a', 'r', 'k' )
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @enum:
|
||||
* FT_PARAM_TAG_UNPATENTED_HINTING
|
||||
*
|
||||
* @description:
|
||||
* Deprecated, no effect.
|
||||
*
|
||||
* Previously: A constant used as the tag of an @FT_Parameter structure
|
||||
* to indicate that unpatented methods only should be used by the
|
||||
* TrueType bytecode interpreter for a typeface opened by @FT_Open_Face.
|
||||
*
|
||||
*/
|
||||
#define FT_PARAM_TAG_UNPATENTED_HINTING \
|
||||
FT_MAKE_TAG( 'u', 'n', 'p', 'a' )
|
||||
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
|
||||
#endif /* FTPARAMS_H_ */
|
||||
|
||||
|
||||
/* END */
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user