feat: ground work for custom font support
This commit is contained in:
parent
3108a06e89
commit
e9f416f682
@ -34,7 +34,8 @@ __all__ = [
|
||||
'bl_metaball',
|
||||
'bl_lattice',
|
||||
'bl_lightprobe',
|
||||
'bl_speaker'
|
||||
'bl_speaker',
|
||||
'bl_font'
|
||||
] # Order here defines execution order
|
||||
|
||||
from . import *
|
||||
|
@ -62,6 +62,11 @@ class BlCurve(BlDatablock):
|
||||
loader = Loader()
|
||||
loader.load(target, data)
|
||||
|
||||
# if isinstance(curve, T.TextCurve):
|
||||
# curve.font = data['font']
|
||||
# curve.font_bold = data['font']
|
||||
# curve.font_bold_italic = data['font']
|
||||
# curve.font_italic = data['font']
|
||||
target.splines.clear()
|
||||
# load splines
|
||||
for spline in data['splines'].values():
|
||||
@ -84,6 +89,7 @@ class BlCurve(BlDatablock):
|
||||
# new_spline.points[point_index], data['splines'][spline]["points"][point_index])
|
||||
|
||||
loader.load(new_spline, spline)
|
||||
|
||||
def _dump_implementation(self, data, instance=None):
|
||||
assert(instance)
|
||||
dumper = Dumper()
|
||||
@ -119,3 +125,17 @@ class BlCurve(BlDatablock):
|
||||
elif isinstance(instance, T.Curve):
|
||||
data['type'] = 'CURVE'
|
||||
return data
|
||||
|
||||
def _resolve_deps_implementation(self):
|
||||
# TODO: resolve material
|
||||
deps = []
|
||||
curve = self.instance
|
||||
|
||||
if isinstance(curve, T.TextCurve):
|
||||
deps.extend([
|
||||
curve.font,
|
||||
curve.font_bold,
|
||||
curve.font_bold_italic,
|
||||
curve.font_italic])
|
||||
|
||||
return deps
|
73
multi_user/bl_types/bl_font.py
Normal file
73
multi_user/bl_types/bl_font.py
Normal file
@ -0,0 +1,73 @@
|
||||
# ##### BEGIN GPL LICENSE BLOCK #####
|
||||
#
|
||||
# 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 3 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, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
|
||||
import bpy
|
||||
import mathutils
|
||||
import os
|
||||
import logging
|
||||
from .. import utils
|
||||
from .dump_anything import Loader, Dumper
|
||||
from .bl_datablock import BlDatablock
|
||||
|
||||
class BlFont(BlDatablock):
|
||||
bl_id = "fonts"
|
||||
bl_class = bpy.types.VectorFont
|
||||
bl_delay_refresh = 1
|
||||
bl_delay_apply = 1
|
||||
bl_automatic_push = True
|
||||
bl_check_common = False
|
||||
bl_icon = 'FILE_FONT'
|
||||
|
||||
def _construct(self, data):
|
||||
if data['filepath'] == '<builtin>':
|
||||
return bpy.data.fonts[data['name']]
|
||||
elif 'font_file' in data.keys():
|
||||
prefs = utils.get_preferences()
|
||||
font_name = f"{self.uuid}.ttf"
|
||||
font_path = os.path.join(prefs.cache_directory, font_name)
|
||||
|
||||
os.makedirs(prefs.cache_directory, exist_ok=True)
|
||||
file = open(font_path, 'wb')
|
||||
file.write(data["font_file"])
|
||||
file.close()
|
||||
|
||||
logging.info(f'loading {font_path}')
|
||||
return bpy.data.fonts.load(font_path)
|
||||
|
||||
return bpy.data.images.new(
|
||||
name=data['name'],
|
||||
width=data['size'][0],
|
||||
height=data['size'][1]
|
||||
)
|
||||
|
||||
def _load(self, data, target):
|
||||
pass
|
||||
|
||||
def _dump(self, instance=None):
|
||||
data = {
|
||||
'filepath':instance.filepath,
|
||||
'name':instance.name
|
||||
}
|
||||
if instance.filepath != '<builtin>' and not instance.is_embedded_data:
|
||||
file = open(instance.filepath, "rb")
|
||||
data['font_file'] = file.read()
|
||||
file.close()
|
||||
return data
|
||||
|
||||
def diff(self):
|
||||
return False
|
@ -593,6 +593,8 @@ class Loader:
|
||||
instance.write(bpy.data.materials.get(dump))
|
||||
elif isinstance(rna_property_type, T.Collection):
|
||||
instance.write(bpy.data.collections.get(dump))
|
||||
elif isinstance(rna_property_type, T.VectorFont):
|
||||
instance.write(bpy.data.fonts.get(dump))
|
||||
|
||||
def _load_matrix(self, matrix, dump):
|
||||
matrix.write(mathutils.Matrix(dump))
|
||||
|
@ -57,11 +57,13 @@ def get_datablock_users(datablock):
|
||||
|
||||
|
||||
def clean_scene():
|
||||
builtin = ['Bfont']
|
||||
for type_name in dir(bpy.data):
|
||||
try:
|
||||
type_collection = getattr(bpy.data, type_name)
|
||||
for item in type_collection:
|
||||
type_collection.remove(item)
|
||||
if item.name not in builtin:
|
||||
type_collection.remove(item)
|
||||
except:
|
||||
continue
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user