Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Correct Buffer size for #2530 #2636

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Jklawreszuk
Copy link
Collaborator

PR Details

Fixes an exception for some sizes

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have built and run the editor to try this change out.

@Eideren Eideren marked this pull request as draft February 15, 2025 19:53
Copy link
Contributor

@Ethereal77 Ethereal77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments about the changes.

I think currently we are losing some features in the change to SharpFont, isn't it?
Specifically I see much more logic in the previous GetFontFace() methods that took the font styles into account.

Sorry if I'm misunderstanding the change.

using FreeImageAPI;
using SharpDX.Mathematics.Interop;
using SharpFont;
using Stride.Core;
using Factory = SharpDX.DirectWrite.Factory;

// This code was originally taken from DirectXTk but rewritten with DirectWrite
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is no longer correct, is it? It does not use DirectWrite.

@@ -128,7 +121,7 @@ private unsafe Glyph ImportGlyph(Face face, char character, float fontSize, Font
face.LoadGlyph(index, LoadFlags.Render, LoadTarget.Normal);

var glyphBitmap = face.Glyph.Bitmap;
var bufferData = new Span<byte>((byte*)glyphBitmap.Buffer, glyphBitmap.Rows * glyphBitmap.Pitch);
var bufferData = new Span<byte>((byte*)glyphBitmap.Buffer, glyphBitmap.Rows * glyphBitmap.Width);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes more sense that the size is Rows times Pitch. Why that results in an incorrect buffer size? Worst case should be that Width == Pitch if byte-sized and no paddings, no?

As GetFont() is a new method, if Pitch is not correctly returning the pitch, then maybe we should fix it there.

Also related: Why create a new GetFont() method returning a Face instead of modifying the already existing GetFontFace() that returns a FontFace?
I ask because maybe we should encapsulate Face inside FontFace (as it already has a correct Pitch property), and not change this line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants