Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Source/UnicodeBrowser/UnicodeBrowserOptions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// all rights reserved


#include "UnicodeBrowserOptions.h"

TSharedRef<IDetailsView> UUnicodeBrowserOptions::MakePropertyEditor(UUnicodeBrowserOptions* Options)
{
FPropertyEditorModule& PropertyEditor = FModuleManager::Get().LoadModuleChecked<FPropertyEditorModule>(TEXT("PropertyEditor"));
FDetailsViewArgs DetailsViewArgs;
DetailsViewArgs.bAllowSearch = false;
DetailsViewArgs.bHideSelectionTip = true;
DetailsViewArgs.bShowModifiedPropertiesOption = false;
DetailsViewArgs.bShowScrollBar = false;
DetailsViewArgs.bShowOptions = false;
DetailsViewArgs.bShowObjectLabel = false;
DetailsViewArgs.bLockable = false;
auto FontDetailsView = PropertyEditor.CreateDetailView(DetailsViewArgs);
FontDetailsView->SetObject(Options);
return FontDetailsView;
}

void UUnicodeBrowserOptions::PostInitProperties()
{
Super::PostInitProperties();
if (!Font.HasValidFont())
{
Font = FCoreStyle::GetDefaultFontStyle("Regular", 18);
}
}

void UUnicodeBrowserOptions::PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent)
{
Super::PostEditChangeProperty(PropertyChangedEvent);

if (!Font.HasValidFont())
{
Font = FCoreStyle::GetDefaultFontStyle("Regular", 18);
}

OnChanged.Broadcast(&PropertyChangedEvent);
}
43 changes: 43 additions & 0 deletions Source/UnicodeBrowser/UnicodeBrowserOptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// all rights reserved

#pragma once

#include "CoreMinimal.h"
#include "UObject/Object.h"
#include "UnicodeBrowserOptions.generated.h"

/**
*
*/
UCLASS(Hidden, BlueprintType, EditInlineNew, DefaultToInstanced, DisplayName = "Font Options")
class UNICODEBROWSER_API UUnicodeBrowserOptions : public UObject
{
GENERATED_BODY()

public:
static TSharedRef<class IDetailsView> MakePropertyEditor(UUnicodeBrowserOptions* Options);
UPROPERTY(EditAnywhere, meta=(ShowOnlyInnerProperties), Transient)
FSlateFontInfo Font = FCoreStyle::GetDefaultFontStyle("Regular", 18);

UPROPERTY(EditAnywhere)
int32 NumCols = 24;

// Show Characters which can't be displayed by the font (primary for debug purposes)
UPROPERTY(EditAnywhere)
bool bShowMissing = false;

// Show Characters which have a measurement of 0x0 (primary for debug purposes)
UPROPERTY(EditAnywhere)
bool bShowZeroSize = false;

// Cache the Character meta information while loading the font, this is slower while changing fonts, but may reduce delay for displaying character previews
UPROPERTY(EditAnywhere)
bool bCacheCharacterMetaOnLoad = false;

virtual void PostInitProperties() override;

virtual void PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) override;

DECLARE_MULTICAST_DELEGATE_OneParam(FOnNumColsChangedDelegate, struct FPropertyChangedEvent*);
FOnNumColsChangedDelegate OnChanged;
};
80 changes: 80 additions & 0 deletions Source/UnicodeBrowser/UnicodeBrowserRow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#pragma once
#include "Fonts/UnicodeBlockRange.h"
#include "Fonts/FontMeasure.h"

class FUnicodeBrowserRow : public TSharedFromThis<FUnicodeBrowserRow>
{
public:
FUnicodeBrowserRow(int32 CodePointIn, TOptional<EUnicodeBlockRange> BlockRangeIn, FSlateFontInfo const *FontInfoIn = nullptr) : Codepoint(CodePointIn), BlockRange(BlockRangeIn), FontInfo(FontInfoIn)
{
FUnicodeChar::CodepointToString(Codepoint, Character);
}

FString Character;
int32 Codepoint = 0;
TOptional<EUnicodeBlockRange> BlockRange;

private:
FSlateFontInfo const *FontInfo = nullptr;
const FFontData *FontData = nullptr;
TOptional<float> ScalingFactor;
TOptional<FVector2D> Measurements;
TOptional<bool> bCanLoadCodepoint;


public:
const FFontData* GetFontData()
{
if(!FontData && FontInfo)
{
float ScalingFactorResult;
FontData = &FSlateApplication::Get().GetRenderer()->GetFontCache()->GetFontDataForCodepoint(*FontInfo, Codepoint, ScalingFactorResult);
ScalingFactor = ScalingFactorResult;
}

return FontData;
}

bool CanLoadCodepoint()
{
if(!bCanLoadCodepoint.IsSet() && GetFontData()){
bCanLoadCodepoint = FSlateApplication::Get().GetRenderer()->GetFontCache()->CanLoadCodepoint(*FontData, Codepoint);
}

return bCanLoadCodepoint.Get(false);
}

FVector2D GetMeasurements()
{
if(!Measurements.IsSet() && FontInfo){
Measurements = FSlateApplication::Get().GetRenderer()->GetFontMeasureService()->Measure(*Character, *FontInfo);
}

return Measurements.Get(FVector2D::ZeroVector);
}

float GetScaling()
{
if(!ScalingFactor.IsSet())
{
// this will try to populate the ScalingFactor
GetFontData();
}

return ScalingFactor.Get(0.0f);
}


friend bool operator==(FUnicodeBrowserRow const& Lhs, FUnicodeBrowserRow const& RHS)
{
return Lhs.Codepoint == RHS.Codepoint
&& Lhs.Character == RHS.Character
&& Lhs.BlockRange == RHS.BlockRange
&& Lhs.FontData == RHS.FontData
&& Lhs.ScalingFactor == RHS.ScalingFactor
&& Lhs.Measurements == RHS.Measurements
&& Lhs.bCanLoadCodepoint == RHS.bCanLoadCodepoint;
}

friend bool operator!=(FUnicodeBrowserRow const& Lhs, FUnicodeBrowserRow const& RHS) { return !(Lhs == RHS); }
};
Loading