Skip to content

Commit

Permalink
Feat: 폰트변경, 색상선택(static)
Browse files Browse the repository at this point in the history
  • Loading branch information
support-kang committed Mar 8, 2024
1 parent 2569c4a commit 58f8845
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 16 deletions.
7 changes: 7 additions & 0 deletions src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,10 @@ body {
box-shadow: none;
background-color: transparent;
}

@font-face {
font-family: 'Pretendard-Medium';
font-style: normal;
font-weight: 400;
src: url('../fonts/Pretendard-Medium.otf') format('opentype');
}
31 changes: 31 additions & 0 deletions src/components/canvas/fabricCanvas.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export default function FabricCanvas() {

canvas.selection = false;

// 캔버스에 로고 추가
addlogoToCanvas();

canvas.renderAll();
}, [canvas, isCanvasInit]);

Expand Down Expand Up @@ -125,6 +128,34 @@ export default function FabricCanvas() {
setSaveOpen(false);
};

const generateLogoText = () => {
const text = new fabric.Text('fit-a-pat', {
fontSize: 50,
fontFamily: 'Pretendard-Medium',
fill: 'rgba(78, 78, 78, 1)' /* 투명도 조절 */,
fontWeight: 'bold',
originX: 'center',
originY: 'center',
evented: false,
selectable: false,
});
return text;
};

const addlogoToCanvas = () => {
const logoText = generateLogoText();
logoText.set({
originX: 'center',
originY: 'center',
left: canvas.getWidth() / 2,
top: canvas.getHeight() / 2,
zIndex: 50,
});
canvas.discardActiveObject();
canvas.add(logoText);
canvas.renderAll();
};

return (
<Box
sx={{
Expand Down
36 changes: 20 additions & 16 deletions src/components/canvas/stylePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ function simpleObjectToString(workouts) {
if (workouts[i].aerobic) {
string +=
workouts[i].sets[j].intensity +
'km/h x ' +
'km/h | ' +
workouts[i].sets[j].time +
'min\n';
} else {
string +=
workouts[i].sets[j].intensity +
'kg x ' +
'kg | ' +
workouts[i].sets[j].time +
'reps\n';
}
Expand All @@ -33,14 +33,12 @@ function simpleObjectToString(workouts) {
return string;
}

function simpleText(workoutsString) {
function simpleText(workoutsString, color) {
const text = new fabric.Text(workoutsString, {
textAlign: 'left',
fontSize: 20,
fontFamily: 'Helvetica',
fill: 'white',
stroke: 'black',
strokeWidth: 1,
fontFamily: 'Pretendard-Medium',
fill: color,
fontWeight: 'bold',
originX: 'center',
originY: 'center',
Expand Down Expand Up @@ -80,9 +78,15 @@ export default function StylePicker(props) {
React.useEffect(() => {
if (value === null || value === undefined) return;

if (value === 'simple') {
if (value === 'white') {
const workoutsString = simpleObjectToString(selectedWorkout);
const text = simpleText(workoutsString);
const text = simpleText(workoutsString, 'white');
setWorkoutResult(text);
}

if (value === 'black') {
const workoutsString = simpleObjectToString(selectedWorkout);
const text = simpleText(workoutsString, 'black');
setWorkoutResult(text);
}
}, [value]);
Expand All @@ -106,17 +110,17 @@ export default function StylePicker(props) {
}}
>
<TabList onChange={handleChange} aria-label="lab API tabs example">
<Tab label="Simple" value="simple" />
{
// WIP: Work In Progress
}
<Tab label="Work In Progress.." value="WIP" disabled={true} />{' '}
<Tab label="White" value="white" />
<Tab label="Black" value="black" />
</TabList>
</Box>
<TabPanel value="simple"></TabPanel>
<TabPanel value="2">Item Two</TabPanel>
{/* <TabPanel value="white"></TabPanel>
<TabPanel value="black"></TabPanel> */}
</TabContext>
<Button
sx={{
mt: 2,
}}
variant="contained"
onClick={() => {
addItemToCanvasCenter(canvas, workoutResult);
Expand Down
2 changes: 2 additions & 0 deletions src/components/canvas/workoutModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import Box from '@mui/material/Box';
import SelectWorkoutButtons from './selectWorkoutButtons';
import StylePicker from './stylePicker';

import { useSession } from 'next-auth/react';

// 운동 예시 오브젝트
const EXAMPLE_WORKOUT1 = {
_id: '1',
Expand Down
Binary file added src/fonts/Pretendard-Medium.otf
Binary file not shown.

0 comments on commit 58f8845

Please sign in to comment.